Makefile: Fix build on Windows and Android
[pcsx_rearmed.git] / Makefile
... / ...
CommitLineData
1# Makefile for PCSX ReARMed
2
3# default stuff goes here, so that config can override
4TARGET ?= pcsx
5CFLAGS += -Wall -Iinclude -ffast-math
6ifeq ($(DEBUG), 1)
7CFLAGS += -O0 -ggdb
8else
9ifeq ($(platform), $(filter $(platform), vita ctr))
10CFLAGS += -O3 -DNDEBUG
11else
12CFLAGS += -O2 -DNDEBUG
13endif
14endif
15CXXFLAGS += $(CFLAGS)
16#DRC_DBG = 1
17#PCNT = 1
18
19# Suppress minor warnings for dependencies
20deps/%: CFLAGS += -Wno-unused -Wno-unused-function
21
22all: config.mak target_ plugins_
23
24ifndef NO_CONFIG_MAK
25ifneq ($(wildcard config.mak),)
26config.mak: ./configure
27 @echo $@ is out-of-date, running configure
28 @sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
29include config.mak
30else
31config.mak:
32 @echo "Please run ./configure before running make!"
33 @exit 1
34endif
35else # NO_CONFIG_MAK
36config.mak:
37endif
38
39-include Makefile.local
40
41CC_LINK ?= $(CC)
42CC_AS ?= $(CC)
43LDFLAGS += $(MAIN_LDFLAGS)
44EXTRA_LDFLAGS ?= -Wl,-Map=$@.map
45LDLIBS += $(MAIN_LDLIBS)
46ifdef PCNT
47CFLAGS += -DPCNT
48endif
49
50LIGHTREC_CUSTOM_MAP ?= 0
51CFLAGS += -DLIGHTREC_CUSTOM_MAP=$(LIGHTREC_CUSTOM_MAP)
52
53# core
54OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore/database.o \
55 libpcsxcore/decode_xa.o libpcsxcore/mdec.o \
56 libpcsxcore/misc.o libpcsxcore/plugins.o libpcsxcore/ppf.o libpcsxcore/psxbios.o \
57 libpcsxcore/psxcommon.o libpcsxcore/psxcounters.o libpcsxcore/psxdma.o libpcsxcore/psxhle.o \
58 libpcsxcore/psxhw.o libpcsxcore/psxinterpreter.o libpcsxcore/psxmem.o libpcsxcore/r3000a.o \
59 libpcsxcore/sio.o libpcsxcore/spu.o
60OBJS += libpcsxcore/gte.o libpcsxcore/gte_nf.o libpcsxcore/gte_divider.o
61
62ifeq ($(DEBUG), 1)
63OBJS += libpcsxcore/debug.o libpcsxcore/socket.o libpcsxcore/disr3000a.o
64endif
65
66ifeq ($(WANT_ZLIB),1)
67CFLAGS += -Ideps/libchdr/deps/zlib-1.2.11
68OBJS += deps/libchdr/deps/zlib-1.2.11/adler32.o \
69 deps/libchdr/deps/zlib-1.2.11/compress.o \
70 deps/libchdr/deps/zlib-1.2.11/crc32.o \
71 deps/libchdr/deps/zlib-1.2.11/deflate.o \
72 deps/libchdr/deps/zlib-1.2.11/gzclose.o \
73 deps/libchdr/deps/zlib-1.2.11/gzlib.o \
74 deps/libchdr/deps/zlib-1.2.11/gzread.o \
75 deps/libchdr/deps/zlib-1.2.11/gzwrite.o \
76 deps/libchdr/deps/zlib-1.2.11/infback.o \
77 deps/libchdr/deps/zlib-1.2.11/inffast.o \
78 deps/libchdr/deps/zlib-1.2.11/inflate.o \
79 deps/libchdr/deps/zlib-1.2.11/inftrees.o \
80 deps/libchdr/deps/zlib-1.2.11/trees.o \
81 deps/libchdr/deps/zlib-1.2.11/uncompr.o \
82 deps/libchdr/deps/zlib-1.2.11/zutil.o
83endif
84ifeq "$(ARCH)" "arm"
85OBJS += libpcsxcore/gte_arm.o
86endif
87ifeq "$(HAVE_NEON)" "1"
88OBJS += libpcsxcore/gte_neon.o
89endif
90libpcsxcore/psxbios.o: CFLAGS += -Wno-nonnull
91
92# dynarec
93ifeq "$(DYNAREC)" "lightrec"
94CFLAGS += -Ideps/lightning/include -Ideps/lightrec -Iinclude/lightning -Iinclude/lightrec \
95 -DLIGHTREC -DLIGHTREC_STATIC
96ifeq ($(LIGHTREC_CUSTOM_MAP),1)
97LDLIBS += -lrt
98OBJS += libpcsxcore/lightrec/mem.o
99endif
100OBJS += libpcsxcore/lightrec/plugin.o
101OBJS += deps/lightning/lib/jit_disasm.o \
102 deps/lightning/lib/jit_memory.o \
103 deps/lightning/lib/jit_names.o \
104 deps/lightning/lib/jit_note.o \
105 deps/lightning/lib/jit_print.o \
106 deps/lightning/lib/jit_size.o \
107 deps/lightning/lib/lightning.o \
108 deps/lightrec/blockcache.o \
109 deps/lightrec/disassembler.o \
110 deps/lightrec/emitter.o \
111 deps/lightrec/interpreter.o \
112 deps/lightrec/lightrec.o \
113 deps/lightrec/memmanager.o \
114 deps/lightrec/optimizer.o \
115 deps/lightrec/regcache.o \
116 deps/lightrec/recompiler.o \
117 deps/lightrec/reaper.o
118libpcsxcore/lightrec/mem.o: CFLAGS += -D_GNU_SOURCE
119ifeq ($(MMAP_WIN32),1)
120CFLAGS += -Iinclude/mman
121OBJS += deps/mman/mman.o
122endif
123else ifeq "$(DYNAREC)" "ari64"
124OBJS += libpcsxcore/new_dynarec/new_dynarec.o
125OBJS += libpcsxcore/new_dynarec/pcsxmem.o
126 ifeq "$(ARCH)" "arm"
127 OBJS += libpcsxcore/new_dynarec/linkage_arm.o
128 libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/assem_arm.c
129 else ifneq (,$(findstring $(ARCH),aarch64 arm64))
130 OBJS += libpcsxcore/new_dynarec/linkage_arm64.o
131 libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/assem_arm64.c
132 else
133 $(error no dynarec support for architecture $(ARCH))
134 endif
135else
136CFLAGS += -DDRC_DISABLE
137endif
138OBJS += libpcsxcore/new_dynarec/emu_if.o
139libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/pcsxmem_inline.c
140ifdef DRC_DBG
141libpcsxcore/new_dynarec/emu_if.o: CFLAGS += -D_FILE_OFFSET_BITS=64
142CFLAGS += -DDRC_DBG
143endif
144ifeq "$(BASE_ADDR_DYNAMIC)" "1"
145libpcsxcore/new_dynarec/%.o: CFLAGS += -DBASE_ADDR_DYNAMIC=1
146endif
147
148# spu
149OBJS += plugins/dfsound/dma.o plugins/dfsound/freeze.o \
150 plugins/dfsound/registers.o plugins/dfsound/spu.o \
151 plugins/dfsound/out.o plugins/dfsound/nullsnd.o
152plugins/dfsound/spu.o: plugins/dfsound/adsr.c plugins/dfsound/reverb.c \
153 plugins/dfsound/xa.c
154ifeq "$(ARCH)" "arm"
155OBJS += plugins/dfsound/arm_utils.o
156endif
157ifeq "$(HAVE_C64_TOOLS)" "1"
158plugins/dfsound/spu.o: CFLAGS += -DC64X_DSP
159plugins/dfsound/spu.o: plugins/dfsound/spu_c64x.c
160frontend/menu.o: CFLAGS += -DC64X_DSP
161endif
162ifneq ($(findstring oss,$(SOUND_DRIVERS)),)
163plugins/dfsound/out.o: CFLAGS += -DHAVE_OSS
164OBJS += plugins/dfsound/oss.o
165endif
166ifneq ($(findstring alsa,$(SOUND_DRIVERS)),)
167plugins/dfsound/out.o: CFLAGS += -DHAVE_ALSA
168OBJS += plugins/dfsound/alsa.o
169LDLIBS += -lasound
170endif
171ifneq ($(findstring sdl,$(SOUND_DRIVERS)),)
172plugins/dfsound/out.o: CFLAGS += -DHAVE_SDL
173OBJS += plugins/dfsound/sdl.o
174endif
175ifneq ($(findstring pulseaudio,$(SOUND_DRIVERS)),)
176plugins/dfsound/out.o: CFLAGS += -DHAVE_PULSE
177OBJS += plugins/dfsound/pulseaudio.o
178endif
179ifneq ($(findstring libretro,$(SOUND_DRIVERS)),)
180plugins/dfsound/out.o: CFLAGS += -DHAVE_LIBRETRO
181endif
182
183# builtin gpu
184OBJS += plugins/gpulib/gpu.o plugins/gpulib/vout_pl.o
185ifeq "$(BUILTIN_GPU)" "neon"
186CFLAGS += -DGPU_NEON
187OBJS += plugins/gpu_neon/psx_gpu_if.o
188ifeq "$(HAVE_NEON)" "1"
189OBJS += plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o
190plugins/gpu_neon/psx_gpu_if.o: CFLAGS += -DNEON_BUILD -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP
191else
192plugins/gpu_neon/psx_gpu_if.o: CFLAGS += -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP
193endif
194plugins/gpu_neon/psx_gpu_if.o: plugins/gpu_neon/psx_gpu/*.c
195endif
196ifeq "$(BUILTIN_GPU)" "peops"
197CFLAGS += -DGPU_PEOPS
198# note: code is not safe for strict-aliasing? (Castlevania problems)
199plugins/dfxvideo/gpulib_if.o: CFLAGS += -fno-strict-aliasing
200plugins/dfxvideo/gpulib_if.o: plugins/dfxvideo/prim.c plugins/dfxvideo/soft.c
201OBJS += plugins/dfxvideo/gpulib_if.o
202ifeq "$(THREAD_RENDERING)" "1"
203CFLAGS += -DTHREAD_RENDERING
204OBJS += plugins/gpulib/gpulib_thread_if.o
205endif
206endif
207ifeq "$(BUILTIN_GPU)" "unai"
208CFLAGS += -DGPU_UNAI
209CFLAGS += -DUSE_GPULIB=1
210#CFLAGS += -DINLINE="static __inline__"
211#CFLAGS += -Dasm="__asm__ __volatile__"
212OBJS += plugins/gpu_unai/gpulib_if.o
213ifeq "$(ARCH)" "arm"
214OBJS += plugins/gpu_unai/gpu_arm.o
215endif
216ifeq "$(THREAD_RENDERING)" "1"
217CFLAGS += -DTHREAD_RENDERING
218OBJS += plugins/gpulib/gpulib_thread_if.o
219endif
220plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -O3
221CC_LINK = $(CXX)
222endif
223
224# cdrcimg
225OBJS += plugins/cdrcimg/cdrcimg.o
226
227# libchdr
228ifeq "$(HAVE_CHD)" "1"
229CFLAGS += -Ideps/libchdr/include
230CFLAGS += -Ideps/libchdr/include/libchdr
231OBJS += deps/libchdr/deps/lzma-19.00/src/Alloc.o
232OBJS += deps/libchdr/deps/lzma-19.00/src/Bra86.o
233OBJS += deps/libchdr/deps/lzma-19.00/src/BraIA64.o
234OBJS += deps/libchdr/deps/lzma-19.00/src/CpuArch.o
235OBJS += deps/libchdr/deps/lzma-19.00/src/Delta.o
236OBJS += deps/libchdr/deps/lzma-19.00/src/LzFind.o
237OBJS += deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.o
238OBJS += deps/libchdr/deps/lzma-19.00/src/LzmaDec.o
239OBJS += deps/libchdr/deps/lzma-19.00/src/LzmaEnc.o
240OBJS += deps/libchdr/deps/lzma-19.00/src/Sort.o
241OBJS += deps/libchdr/src/libchdr_bitstream.o
242OBJS += deps/libchdr/src/libchdr_cdrom.o
243OBJS += deps/libchdr/src/libchdr_chd.o
244OBJS += deps/libchdr/src/libchdr_flac.o
245OBJS += deps/libchdr/src/libchdr_huffman.o
246CFLAGS += -Ideps/libchdr/deps/lzma-19.00/include
247CFLAGS += -DHAVE_CHD -D_7ZIP_ST
248LDFLAGS += -lm
249endif
250
251# dfinput
252ifneq "$(PLATFORM)" "libretro"
253OBJS += plugins/dfinput/main.o plugins/dfinput/pad.o plugins/dfinput/guncon.o
254endif
255
256# frontend/gui
257OBJS += frontend/cspace.o
258ifeq "$(HAVE_NEON)" "1"
259OBJS += frontend/cspace_neon.o
260else
261ifeq "$(ARCH)" "arm"
262OBJS += frontend/cspace_arm.o
263endif
264endif
265
266ifeq "$(PLATFORM)" "generic"
267OBJS += frontend/libpicofe/in_sdl.o
268OBJS += frontend/libpicofe/plat_sdl.o
269OBJS += frontend/libpicofe/plat_dummy.o
270OBJS += frontend/libpicofe/linux/in_evdev.o
271OBJS += frontend/plat_sdl.o
272ifeq "$(HAVE_GLES)" "1"
273OBJS += frontend/libpicofe/gl.o frontend/libpicofe/gl_platform.o
274LDLIBS += $(LDLIBS_GLES)
275frontend/libpicofe/plat_sdl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
276frontend/libpicofe/gl_platform.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
277frontend/libpicofe/gl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
278frontend/plat_sdl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
279endif
280USE_PLUGIN_LIB = 1
281USE_FRONTEND = 1
282endif
283ifeq "$(PLATFORM)" "pandora"
284OBJS += frontend/libpicofe/pandora/plat.o
285OBJS += frontend/libpicofe/linux/fbdev.o frontend/libpicofe/linux/xenv.o
286OBJS += frontend/libpicofe/linux/in_evdev.o
287OBJS += frontend/plat_pandora.o frontend/plat_omap.o
288frontend/main.o frontend/menu.o: CFLAGS += -include frontend/pandora/ui_feat.h
289frontend/libpicofe/linux/plat.o: CFLAGS += -DPANDORA
290USE_PLUGIN_LIB = 1
291USE_FRONTEND = 1
292endif
293ifeq "$(PLATFORM)" "caanoo"
294OBJS += frontend/libpicofe/gp2x/in_gp2x.o frontend/warm/warm.o
295OBJS += frontend/libpicofe/gp2x/soc_pollux.o
296OBJS += frontend/libpicofe/linux/in_evdev.o
297OBJS += frontend/plat_pollux.o frontend/in_tsbutton.o frontend/blit320.o
298frontend/main.o frontend/menu.o: CFLAGS += -include frontend/320240/ui_gp2x.h
299USE_PLUGIN_LIB = 1
300USE_FRONTEND = 1
301endif
302ifeq "$(PLATFORM)" "maemo"
303OBJS += maemo/hildon.o maemo/main.o maemo/maemo_xkb.o frontend/pl_gun_ts.o
304maemo/%.o: maemo/%.c
305USE_PLUGIN_LIB = 1
306LDFLAGS += $(shell pkg-config --libs hildon-1 libpulse)
307CFLAGS += $(shell pkg-config --cflags hildon-1) -DHAVE_TSLIB
308CFLAGS += `pkg-config --cflags glib-2.0 libosso dbus-1 hildon-fm-2`
309LDFLAGS += `pkg-config --libs glib-2.0 libosso dbus-1 hildon-fm-2`
310endif
311ifeq "$(PLATFORM)" "libretro"
312ifeq "$(USE_LIBRETRO_VFS)" "1"
313OBJS += libretro-common/compat/compat_posix_string.o
314OBJS += libretro-common/compat/fopen_utf8.o
315OBJS += libretro-common/encodings/compat_strl.o
316OBJS += libretro-common/encodings/encoding_utf.o
317OBJS += libretro-common/file/file_path.o
318OBJS += libretro-common/streams/file_stream.o
319OBJS += libretro-common/streams/file_stream_transforms.o
320OBJS += libretro-common/string/stdstring.o
321OBJS += libretro-common/time/rtime.o
322OBJS += libretro-common/vfs/vfs_implementation.o
323CFLAGS += -DUSE_LIBRETRO_VFS
324endif
325OBJS += frontend/libretro.o
326CFLAGS += -Ilibretro-common/include
327CFLAGS += -DFRONTEND_SUPPORTS_RGB565
328CFLAGS += -DHAVE_LIBRETRO
329
330ifneq ($(DYNAREC),lightrec)
331ifeq ($(MMAP_WIN32),1)
332OBJS += libpcsxcore/memmap_win32.o
333endif
334endif
335endif
336
337ifeq "$(USE_PLUGIN_LIB)" "1"
338OBJS += frontend/plugin_lib.o
339OBJS += frontend/libpicofe/linux/plat.o
340OBJS += frontend/libpicofe/readpng.o frontend/libpicofe/fonts.o
341frontend/libpicofe/linux/plat.o: CFLAGS += -DNO_HOME_DIR
342ifeq "$(HAVE_NEON)" "1"
343OBJS += frontend/libpicofe/arm/neon_scale2x.o
344OBJS += frontend/libpicofe/arm/neon_eagle2x.o
345frontend/libpicofe/arm/neon_scale2x.o: CFLAGS += -DDO_BGR_TO_RGB
346frontend/libpicofe/arm/neon_eagle2x.o: CFLAGS += -DDO_BGR_TO_RGB
347endif
348endif
349ifeq "$(USE_FRONTEND)" "1"
350OBJS += frontend/menu.o
351OBJS += frontend/libpicofe/input.o
352frontend/menu.o: frontend/libpicofe/menu.c
353ifeq "$(HAVE_TSLIB)" "1"
354frontend/%.o: CFLAGS += -DHAVE_TSLIB
355OBJS += frontend/pl_gun_ts.o
356endif
357else
358CFLAGS += -DNO_FRONTEND
359endif
360
361# misc
362OBJS += frontend/main.o frontend/plugin.o
363
364
365frontend/menu.o frontend/main.o: frontend/revision.h
366frontend/plat_sdl.o frontend/libretro.o: frontend/revision.h
367
368frontend/libpicofe/%.c:
369 @echo "libpicofe module is missing, please run:"
370 @echo "git submodule init && git submodule update"
371 @exit 1
372
373libpcsxcore/gte_nf.o: libpcsxcore/gte.c
374 $(CC) -c -o $@ $^ $(CFLAGS) -DFLAGLESS
375
376frontend/revision.h: FORCE
377 @(git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > $@_
378 @diff -q $@_ $@ > /dev/null 2>&1 || cp $@_ $@
379 @rm $@_
380
381%.o: %.S
382 $(CC_AS) $(CFLAGS) -c $^ -o $@
383
384%.o: %.cpp
385 $(CXX) $(CXXFLAGS) -c -o $@ $<
386
387%.o: %.c
388 $(CC) $(CFLAGS) -c -o $@ $<
389
390target_: $(TARGET)
391
392$(TARGET): $(OBJS)
393ifeq ($(STATIC_LINKING), 1)
394 $(AR) rcs $@ $(OBJS)
395else
396 $(CC_LINK) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(EXTRA_LDFLAGS)
397endif
398
399clean: $(PLAT_CLEAN) clean_plugins
400 $(RM) $(TARGET) $(OBJS) $(TARGET).map frontend/revision.h
401
402ifneq ($(PLUGINS),)
403plugins_: $(PLUGINS)
404
405$(PLUGINS):
406 make -C $(dir $@)
407
408clean_plugins:
409 make -C plugins/gpulib/ clean
410 for dir in $(PLUGINS) ; do \
411 $(MAKE) -C $$(dirname $$dir) clean; done
412else
413plugins_:
414clean_plugins:
415endif
416
417.PHONY: all clean target_ plugins_ clean_plugins FORCE
418
419# ----------- release -----------
420
421VER ?= $(shell git describe --always HEAD)
422
423ifeq "$(PLATFORM)" "generic"
424OUT = pcsx_rearmed_$(VER)
425
426rel: pcsx $(PLUGINS) \
427 frontend/pandora/skin readme.txt COPYING
428 rm -rf $(OUT)
429 mkdir -p $(OUT)/plugins
430 mkdir -p $(OUT)/bios
431 cp -r $^ $(OUT)/
432 mv $(OUT)/*.so* $(OUT)/plugins/
433 zip -9 -r $(OUT).zip $(OUT)
434endif
435
436ifeq "$(PLATFORM)" "pandora"
437PND_MAKE ?= $(HOME)/dev/pnd/src/pandora-libraries/testdata/scripts/pnd_make.sh
438
439rel: pcsx plugins/dfsound/pcsxr_spu_area3.out $(PLUGINS) \
440 frontend/pandora/pcsx.sh frontend/pandora/pcsx.pxml.templ frontend/pandora/pcsx.png \
441 frontend/pandora/picorestore frontend/pandora/skin readme.txt COPYING
442 rm -rf out
443 mkdir -p out/plugins
444 cp -r $^ out/
445 sed -e 's/%PR%/$(VER)/g' out/pcsx.pxml.templ > out/pcsx.pxml
446 rm out/pcsx.pxml.templ
447 mv out/*.so out/plugins/
448 $(PND_MAKE) -p pcsx_rearmed_$(VER).pnd -d out -x out/pcsx.pxml -i frontend/pandora/pcsx.png -c
449endif
450
451ifeq "$(PLATFORM)" "caanoo"
452PLAT_CLEAN = caanoo_clean
453
454caanoo_clean:
455 $(RM) frontend/320240/pollux_set
456
457rel: pcsx $(PLUGINS) \
458 frontend/320240/caanoo.gpe frontend/320240/pcsx26.png \
459 frontend/320240/pcsxb.png frontend/320240/skin \
460 frontend/warm/bin/warm_2.6.24.ko frontend/320240/pollux_set \
461 frontend/320240/pcsx_rearmed.ini frontend/320240/haptic_w.cfg \
462 frontend/320240/haptic_s.cfg \
463 readme.txt COPYING
464 rm -rf out
465 mkdir -p out/pcsx_rearmed/plugins
466 cp -r $^ out/pcsx_rearmed/
467 mv out/pcsx_rearmed/*.so out/pcsx_rearmed/plugins/
468 mv out/pcsx_rearmed/caanoo.gpe out/pcsx_rearmed/pcsx.gpe
469 mv out/pcsx_rearmed/pcsx_rearmed.ini out/
470 mkdir out/pcsx_rearmed/lib/
471 cp ./lib/libbz2.so.1 out/pcsx_rearmed/lib/
472 mkdir out/pcsx_rearmed/bios/
473 cd out && zip -9 -r ../pcsx_rearmed_$(VER)_caanoo.zip *
474endif