-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
380 lines (309 loc) · 8.29 KB
/
Makefile
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#disable built-in rules
.SUFFIXES :
ifndef OS
OS:=$(shell uname -s)
endif
FIXUP:=true
BUNDLED_LIBZ:=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o\
zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
ifeq ($(OS),Windows)
ifndef SDL2_PREFIX
SDL2_PREFIX:="sdl/i686-w64-mingw32"
endif
ifndef GLEW_PREFIX
GLEW_PREFIX:=glew
endif
ifndef GLEW32S_LIB
GLEW32S_LIB:=$(GLEW_PREFIX)/lib/Release/Win32/glew32s.lib
endif
MEM:=mem_win.o
TERMINAL:=terminal_win.o
FONT:=nuklear_ui/font_win.o
NET:=net_win.o
EXE:=.exe
SO:=dll
CPU:=i686
ifeq ($(CPU),i686)
CC:=i686-w64-mingw32-gcc-win32
else
CC:=x86_64-w64-mingw32-gcc-win32
endif
CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration
LDFLAGS:=-lm -lmingw32 -lws2_32 -mwindows
ifneq ($(MAKECMDGOALS),libblastem.dll)
CFLAGS+= -I"$(SDL2_PREFIX)/include/SDL2" -I"$(GLEW_PREFIX)/include" -DGLEW_STATIC
LDFLAGS+= $(GLEW32S_LIB) -L"$(SDL2_PREFIX)/lib" -lSDL2main -lSDL2 -lopengl32 -lglu32
endif
LIBZOBJS=$(BUNDLED_LIBZ)
else
MEM:=mem.o
TERMINAL:=terminal.o
NET:=net.o
EXE:=
HAS_PROC:=$(shell if [ -d /proc ]; then /bin/echo -e -DHAS_PROC; fi)
CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value $(HAS_PROC) -DHAVE_UNISTD_H
ifeq ($(OS),Darwin)
LIBS=sdl2 glew
FONT:=nuklear_ui/font_mac.o
SO:=dylib
else
SO:=so
ifdef USE_FBDEV
LIBS=alsa
ifndef NOGL
LIBS+=glesv2 egl
endif
CFLAGS+= -DUSE_GLES -DUSE_FBDEV -pthread
else
ifdef USE_GLES
LIBS=sdl2 glesv2
CFLAGS+= -DUSE_GLES
else
LIBS=sdl2 glew gl
endif #USE_GLES
endif #USE_FBDEV
FONT:=nuklear_ui/font.o
endif #Darwin
ifdef HOST_ZLIB
LIBS+= zlib
LIBZOBJS=
else
LIBZOBJS=$(BUNDLED_LIBZ)
endif
ifeq ($(OS),Darwin)
#This should really be based on whether or not the C compiler is clang rather than based on the OS
CFLAGS+= -Wno-logical-op-parentheses
endif
ifdef PORTABLE
ifdef USE_GLES
ifndef GLES_LIB
GLES_LIB:=$(shell pkg-config --libs glesv2)
endif
LDFLAGS:=-lm $(GLES_LIB)
else
CFLAGS+= -DGLEW_STATIC -Iglew/include
LDFLAGS:=-lm glew/lib/libGLEW.a
endif
ifeq ($(OS),Darwin)
CFLAGS+= -IFrameworks/SDL2.framework/Headers
LDFLAGS+= -FFrameworks -framework SDL2 -framework OpenGL -framework AppKit
FIXUP:=install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 @executable_path/Frameworks/SDL2.framework/Versions/A/SDL2
else
CFLAGS+= -Isdl/include
LDFLAGS+= -Wl,-rpath='$$ORIGIN/lib' -Llib -lSDL2
ifndef USE_GLES
LDFLAGS+= $(shell pkg-config --libs gl)
endif
endif #Darwin
else
ifeq ($(MAKECMDGOALS),libblastem.$(SO))
LDFLAGS:=-lm
else
CFLAGS:=$(shell pkg-config --cflags-only-I $(LIBS)) $(CFLAGS)
LDFLAGS:=-lm $(shell pkg-config --libs $(LIBS))
ifdef USE_FBDEV
LDFLAGS+= -pthread
endif
endif #libblastem.so
ifeq ($(OS),Darwin)
LDFLAGS+= -framework OpenGL -framework AppKit
endif
endif #PORTABLE
endif #Windows
ifndef OPT
ifdef DEBUG
OPT:=-g3 -O0
else
ifdef NOLTO
OPT:=-O2
else
OPT:=-O2 -flto
endif #NOLTO
endif #DEBUG
endif #OPT
CFLAGS:=$(OPT) $(CFLAGS)
LDFLAGS:=$(OPT) $(LDFLAGS)
ifdef Z80_LOG_ADDRESS
CFLAGS+= -DZ80_LOG_ADDRESS
endif
ifdef PROFILE
PROFFLAGS:= -Wl,--no-as-needed -lprofiler -Wl,--as-needed
CFLAGS+= -g3
endif
ifdef NOGL
CFLAGS+= -DDISABLE_OPENGL
NONUKLEAR:=1
endif
ifdef M68030
CFLAGS+= -DM68030
endif
ifdef M68020
CFLAGS+= -DM68020
endif
ifdef M68010
CFLAGS+= -DM68010
endif
ifndef CPU
CPU:=$(shell uname -m)
endif
#OpenBSD uses different names for these architectures
ifeq ($(CPU),amd64)
CPU:=x86_64
else
ifeq ($(CPU),i386)
CPU:=i686
endif
endif
TRANSOBJS=gen.o backend.o $(MEM) arena.o tern.o
M68KOBJS=68kinst.o m68k_core.o
ifeq ($(CPU),x86_64)
M68KOBJS+= m68k_core_x86.o
TRANSOBJS+= gen_x86.o backend_x86.o
else
ifeq ($(CPU),i686)
M68KOBJS+= m68k_core_x86.o
TRANSOBJS+= gen_x86.o backend_x86.o
endif
endif
ifdef NEW_CORE
Z80OBJS=z80.o z80inst.o
CFLAGS+= -DNEW_CORE
else
Z80OBJS=z80inst.o z80_to_x86.o
endif
AUDIOOBJS=ym2612.o psg.o wave.o
CONFIGOBJS=config.o tern.o util.o paths.o
NUKLEAROBJS=$(FONT) nuklear_ui/blastem_nuklear.o nuklear_ui/sfnt.o
RENDEROBJS=ppm.o controller_info.o
ifdef USE_FBDEV
RENDEROBJS+= render_fbdev.o
else
RENDEROBJS+= render_sdl.o
endif
ifdef NOZLIB
CFLAGS+= -DDISABLE_ZLIB
else
RENDEROBJS+= $(LIBZOBJS) png.o
endif
MAINOBJS=blastem.o system.o genesis.o debug.o gdb_remote.o vdp.o $(RENDEROBJS) io.o romdb.o hash.o menu.o xband.o \
realtec.o i2c.o nor.o sega_mapper.o multi_game.o megawifi.o $(NET) serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o \
$(M68KOBJS) $(TRANSOBJS) $(AUDIOOBJS) saves.o zip.o bindings.o jcart.o
LIBOBJS=libblastem.o system.o genesis.o debug.o gdb_remote.o vdp.o io.o romdb.o hash.o xband.o realtec.o \
i2c.o nor.o sega_mapper.o multi_game.o megawifi.o $(NET) serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o \
$(M68KOBJS) $(TRANSOBJS) $(AUDIOOBJS) saves.o jcart.o rom.db.o
ifdef NONUKLEAR
CFLAGS+= -DDISABLE_NUKLEAR
else
MAINOBJS+= $(NUKLEAROBJS)
endif
ifeq ($(CPU),x86_64)
CFLAGS+=-DX86_64 -m64
LDFLAGS+=-m64
else
ifeq ($(CPU),i686)
CFLAGS+=-DX86_32 -m32
LDFLAGS+=-m32
else
$(error $(CPU) is not a supported architecture)
endif
endif
ifdef NOZ80
CFLAGS+=-DNO_Z80
else
MAINOBJS+= sms.o $(Z80OBJS)
LIBOBJS+= sms.o $(Z80OBJS)
endif
ifeq ($(OS),Windows)
MAINOBJS+= res.o
endif
ifdef CONFIG_PATH
CFLAGS+= -DCONFIG_PATH='"'$(CONFIG_PATH)'"'
endif
ifdef DATA_PATH
CFLAGS+= -DDATA_PATH='"'$(DATA_PATH)'"'
endif
ALL=dis$(EXE) zdis$(EXE) stateview$(EXE) vgmplay$(EXE) blastem$(EXE)
ifneq ($(OS),Windows)
ALL+= termhelper
endif
ifeq ($(MAKECMDGOALS),libblastem.$(SO))
CFLAGS+= -fpic -DIS_LIB
endif
all : $(ALL)
libblastem.$(SO) : $(LIBOBJS)
$(CC) -shared -o $@ $^ $(LDFLAGS)
blastem$(EXE) : $(MAINOBJS)
$(CC) -o $@ $^ $(LDFLAGS) $(PROFFLAGS)
$(FIXUP) ./$@
blastjag$(EXE) : jaguar.o jag_video.o $(RENDEROBJS) serialize.o $(M68KOBJS) $(TRANSOBJS) $(CONFIGOBJS)
$(CC) -o $@ $^ $(LDFLAGS)
termhelper : termhelper.o
$(CC) -o $@ $^ $(LDFLAGS)
dis$(EXE) : dis.o 68kinst.o tern.o vos_program_module.o
$(CC) -o $@ $^ $(OPT)
jagdis : jagdis.o jagcpu.o tern.o
$(CC) -o $@ $^
zdis$(EXE) : zdis.o z80inst.o
$(CC) -o $@ $^
libemu68k.a : $(M68KOBJS) $(TRANSOBJS)
ar rcs libemu68k.a $(M68KOBJS) $(TRANSOBJS)
trans : trans.o serialize.o $(M68KOBJS) $(TRANSOBJS) util.o
$(CC) -o trans trans.o $(M68KOBJS) $(TRANSOBJS) util.o $(OPT)
transz80 : transz80.o $(Z80OBJS) $(TRANSOBJS)
$(CC) -o transz80 transz80.o $(Z80OBJS) $(TRANSOBJS)
ztestrun : ztestrun.o serialize.o $(Z80OBJS) $(TRANSOBJS)
$(CC) -o ztestrun $^ $(OPT)
ztestgen : ztestgen.o z80inst.o
$(CC) -ggdb -o ztestgen ztestgen.o z80inst.o
stateview$(EXE) : stateview.o vdp.o $(RENDEROBJS) serialize.o $(CONFIGOBJS) gst.o
$(CC) -o $@ $^ $(LDFLAGS)
$(FIXUP) ./$@
vgmplay$(EXE) : vgmplay.o $(RENDEROBJS) serialize.o $(CONFIGOBJS) $(AUDIOOBJS)
$(CC) -o $@ $^ $(LDFLAGS)
$(FIXUP) ./$@
blastcpm : blastcpm.o util.o serialize.o $(Z80OBJS) $(TRANSOBJS)
$(CC) -o $@ $^ $(OPT) $(PROFFLAGS)
test : test.o vdp.o
$(CC) -o test test.o vdp.o
testgst : testgst.o gst.o
$(CC) -o testgst testgst.o gst.o
test_x86 : test_x86.o gen_x86.o gen.o
$(CC) -o test_x86 test_x86.o gen_x86.o gen.o
test_arm : test_arm.o gen_arm.o mem.o gen.o
$(CC) -o test_arm test_arm.o gen_arm.o mem.o gen.o
test_int_timing : test_int_timing.o vdp.o
$(CC) -o $@ $^
gen_fib : gen_fib.o gen_x86.o mem.o
$(CC) -o gen_fib gen_fib.o gen_x86.o mem.o
offsets : offsets.c z80_to_x86.h m68k_core.h
$(CC) -o offsets offsets.c
vos_prog_info : vos_prog_info.o vos_program_module.o
$(CC) -o vos_prog_info vos_prog_info.o vos_program_module.o
%.c : %.cpu cpu_dsl.py
./cpu_dsl.py -d goto $< > $@
%.db.c : %.db
sed $< -e 's/"/\\"/g' -e 's/^\(.*\)$$/"\1\\n"/' -e'1s/^\(.*\)$$/const char $(shell echo $< | tr '.' '_')_data[] = \1/' -e '$$s/^\(.*\)$$/\1;/' > $@
%.o : %.S
$(CC) -c -o $@ $<
%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o : %.m
$(CC) $(CFLAGS) -c -o $@ $<
%.png : %.xcf
xcf2png $< > $@
%.tiles : %.spec
./img2tiles.py -s $< $@
%.bin : %.s68
vasmm68k_mot -Fbin -m68000 -no-opt -spaces -o $@ -L [email protected] $<
%.bin : %.sz8
vasmz80_mot -Fbin -spaces -o $@ $<
res.o : blastem.rc
i686-w64-mingw32-windres blastem.rc res.o
arrow.tiles : arrow.png
cursor.tiles : cursor.png
font_interlace_variable.tiles : font_interlace_variable.png
button.tiles : button.png
font.tiles : font.png
menu.bin : font_interlace_variable.tiles arrow.tiles cursor.tiles button.tiles font.tiles
clean :
rm -rf $(ALL) trans ztestrun ztestgen *.o nuklear_ui/*.o zlib/*.o