-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile.lua
170 lines (144 loc) · 3.79 KB
/
makefile.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
function writemakefile_psp(prj_name, ...)
local args = {...}
local files = "main.o";
for i, v in ipairs( args ) do
files = files .. " " .. v:match("(.+)%..+") .. ".o"
end
files = string.gsub(files, "^%s*(.-)%s*$", "%1")
file = io.open("source/makefile", "w")
if (file) then
str = [[
TARGET = ../data/memstick/PSP/PLUGINS/%s/%s
OBJS = %s
LIBS = -lstdc++ -lm
BUILD_PRX=1
PRX_EXPORTS=exports.exp
INCDIR =
CFLAGS = -Os -G0 -Wall -D PSP -mpreferred-stack-boundary=4 -mabi=eabi
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
]]
file:write(string.format(str, prj_name, prj_name, files))
file:close()
end
end
function writemakefile_ps2(prj_name, scripts_addr, base, libs, ...)
local args = {...}
local files = "main.o";
for i, v in ipairs( args ) do
files = files .. " " .. v:match("(.+)%..+") .. ".o"
end
files = string.gsub(files, "^%s*(.-)%s*$", "%1")
file = io.open("source/" .. prj_name .. "/makefile", "w")
if (file) then
str = [[
EE_BIN = ../../data/%s/%s.elf
EE_OBJS = %s
CFLAGS = -O0 -Os -G0 -Wall -fshort-wchar -fno-pic -mno-check-zero-division -fpack-struct=16
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BASE_ADDRESS = %s
EE_LINKFILE = linkfile
EE_LIBS += %s
EE_LDFLAGS = -Wl,--entry=init -Wl,-Map,../../data/%s/%s.map -Wl,-exclude-libs,ALL -Wl,'--defsym=BASE_ADDRESS=$(BASE_ADDRESS)'
all: clean main-build
main-build: $(EE_BIN)
clean:
rm -f $(EE_OBJS) $(EE_BIN)
PS2SDK = ../../external/ps2sdk/ps2sdk
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
]]
file:write(string.format(str, prj_name, scripts_addr .. prj_name, files, base, libs, prj_name, scripts_addr .. prj_name))
file:close()
end
end
function writelinkfile_ps2(prj_name)
file = io.open("source/" .. prj_name .. "/linkfile", "w")
if (file) then
str = [[
ENTRY(__start);
PHDRS {
text PT_LOAD;
}
SECTIONS {
.text BASE_ADDRESS : {
_ftext = . ;
*(.text)
*(.text.*)
*(.gnu.linkonce.t*)
KEEP(*(.init))
KEEP(*(.fini))
QUAD(0)
} :text
PROVIDE(_etext = .);
PROVIDE(etext = .);
.reginfo : { *(.reginfo) }
/* Global/static constructors and deconstructors. */
.ctors ALIGN(16): {
KEEP(*crtbegin*.o(.ctors))
KEEP(*(EXCLUDE_FILE(*crtend*.o) .ctors))
KEEP(*(SORT(.ctors.*)))
KEEP(*(.ctors))
}
.dtors ALIGN(16): {
KEEP(*crtbegin*.o(.dtors))
KEEP(*(EXCLUDE_FILE(*crtend*.o) .dtors))
KEEP(*(SORT(.dtors.*)))
KEEP(*(.dtors))
}
/* Static data. */
.rodata ALIGN(128): {
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r*)
}
.data ALIGN(128): {
_fdata = . ;
*(.data)
*(.data.*)
*(.gnu.linkonce.d*)
SORT(CONSTRUCTORS)
}
.rdata ALIGN(128): { *(.rdata) }
.gcc_except_table ALIGN(128): { *(.gcc_except_table) }
_gp = ALIGN(128) + 0x7ff0;
.lit4 ALIGN(128): { *(.lit4) }
.lit8 ALIGN(128): { *(.lit8) }
.sdata ALIGN(128): {
*(.sdata)
*(.sdata.*)
*(.gnu.linkonce.s*)
}
_edata = .;
PROVIDE(edata = .);
/* Uninitialized data. */
.sbss ALIGN(128) : {
_fbss = . ;
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb*)
*(.scommon)
}
.bss ALIGN(128) : {
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b*)
*(COMMON)
}
_end_bss = .;
_end = . ;
PROVIDE(end = .);
/* Symbols needed by crt0.s. */
PROVIDE(_heap_size = -1);
PROVIDE(_stack = -1);
PROVIDE(_stack_size = 128 * 1024);
}
]]
file:write(str)
file:close()
end
end