Makefile: Enable address sanitizer with DEBUG_ASAN=1
[pcsx_rearmed.git] / Makefile
1 # Makefile for PCSX ReARMed
2
3 # default stuff goes here, so that config can override
4 TARGET ?= pcsx
5 CFLAGS += -Wall -ggdb -Iinclude -ffast-math
6 ifndef DEBUG
7 CFLAGS += -O2 -DNDEBUG
8 endif
9 ifeq ($(DEBUG_ASAN), 1)
10 CFLAGS += -fsanitize=address
11 endif
12 CFLAGS += -DP_HAVE_MMAP=$(if $(NO_MMAP),0,1) \
13           -DP_HAVE_PTHREAD=$(if $(NO_PTHREAD),0,1) \
14           -DP_HAVE_POSIX_MEMALIGN=$(if $(NO_POSIX_MEMALIGN),0,1) \
15           -DDISABLE_MEM_LUTS=0
16 CXXFLAGS += $(CFLAGS)
17 #DRC_DBG = 1
18 #PCNT = 1
19
20 all: config.mak target_ plugins_
21
22 ifndef NO_CONFIG_MAK
23 ifneq ($(wildcard config.mak),)
24 config.mak: ./configure
25         @echo $@ is out-of-date, running configure
26         @sed -n "/.*Configured with/s/[^:]*: //p" $@ | sh
27 include config.mak
28 else
29 config.mak:
30         @echo "Please run ./configure before running make!"
31         @exit 1
32 endif
33 else # NO_CONFIG_MAK
34 config.mak:
35 endif
36
37 -include Makefile.local
38
39 CC_LINK ?= $(CC)
40 CC_AS ?= $(CC)
41 LDFLAGS += $(MAIN_LDFLAGS)
42 ifeq ($(DEBUG_ASAN), 1)
43 LDFLAGS += -static-libasan
44 endif
45 EXTRA_LDFLAGS ?= -Wl,-Map=$@.map
46 LDLIBS += $(MAIN_LDLIBS)
47 ifdef PCNT
48 CFLAGS += -DPCNT
49 endif
50
51 # core
52 OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore/database.o \
53         libpcsxcore/decode_xa.o libpcsxcore/mdec.o \
54         libpcsxcore/misc.o libpcsxcore/plugins.o libpcsxcore/ppf.o libpcsxcore/psxbios.o \
55         libpcsxcore/psxcommon.o libpcsxcore/psxcounters.o libpcsxcore/psxdma.o \
56         libpcsxcore/psxhw.o libpcsxcore/psxinterpreter.o libpcsxcore/psxmem.o \
57         libpcsxcore/psxevents.o libpcsxcore/r3000a.o \
58         libpcsxcore/sio.o libpcsxcore/spu.o libpcsxcore/gpu.o
59 OBJS += libpcsxcore/gte.o libpcsxcore/gte_nf.o libpcsxcore/gte_divider.o
60 #OBJS += libpcsxcore/debug.o libpcsxcore/socket.o libpcsxcore/disr3000a.o
61 ifeq "$(ARCH)" "arm"
62 OBJS += libpcsxcore/gte_arm.o
63 endif
64 ifeq "$(HAVE_NEON_ASM)" "1"
65 OBJS += libpcsxcore/gte_neon.o
66 endif
67 libpcsxcore/psxbios.o: CFLAGS += -Wno-nonnull
68
69 # dynarec
70 ifeq "$(USE_DYNAREC)" "1"
71 OBJS += libpcsxcore/new_dynarec/new_dynarec.o
72 OBJS += libpcsxcore/new_dynarec/pcsxmem.o
73  ifeq "$(ARCH)" "arm"
74  OBJS += libpcsxcore/new_dynarec/linkage_arm.o
75  libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/assem_arm.c
76  else ifneq (,$(findstring $(ARCH),aarch64 arm64))
77  OBJS += libpcsxcore/new_dynarec/linkage_arm64.o
78  libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/assem_arm64.c
79  else
80  $(error no dynarec support for architecture $(ARCH))
81  endif
82 else
83 CFLAGS += -DDRC_DISABLE
84 endif
85 OBJS += libpcsxcore/new_dynarec/emu_if.o
86 libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/pcsxmem_inline.c
87 ifdef DRC_DBG
88 libpcsxcore/new_dynarec/emu_if.o: CFLAGS += -D_FILE_OFFSET_BITS=64
89 CFLAGS += -DDRC_DBG
90 endif
91 ifeq "$(BASE_ADDR_DYNAMIC)" "1"
92 libpcsxcore/new_dynarec/%.o: CFLAGS += -DBASE_ADDR_DYNAMIC=1
93 endif
94
95 # spu
96 OBJS += plugins/dfsound/dma.o plugins/dfsound/freeze.o \
97         plugins/dfsound/registers.o plugins/dfsound/spu.o \
98         plugins/dfsound/out.o plugins/dfsound/nullsnd.o
99 plugins/dfsound/spu.o: plugins/dfsound/adsr.c plugins/dfsound/reverb.c \
100         plugins/dfsound/xa.c
101 ifeq "$(ARCH)" "arm"
102 OBJS += plugins/dfsound/arm_utils.o
103 endif
104 ifeq "$(HAVE_C64_TOOLS)" "1"
105 plugins/dfsound/spu.o: CFLAGS += -DC64X_DSP
106 plugins/dfsound/spu.o: plugins/dfsound/spu_c64x.c
107 frontend/menu.o: CFLAGS += -DC64X_DSP
108 endif
109 ifneq ($(findstring oss,$(SOUND_DRIVERS)),)
110 plugins/dfsound/out.o: CFLAGS += -DHAVE_OSS
111 OBJS += plugins/dfsound/oss.o
112 endif
113 ifneq ($(findstring alsa,$(SOUND_DRIVERS)),)
114 plugins/dfsound/out.o: CFLAGS += -DHAVE_ALSA
115 OBJS += plugins/dfsound/alsa.o
116 LDLIBS += -lasound
117 endif
118 ifneq ($(findstring sdl,$(SOUND_DRIVERS)),)
119 plugins/dfsound/out.o: CFLAGS += -DHAVE_SDL
120 OBJS += plugins/dfsound/sdl.o
121 endif
122 ifneq ($(findstring pulseaudio,$(SOUND_DRIVERS)),)
123 plugins/dfsound/out.o: CFLAGS += -DHAVE_PULSE
124 OBJS += plugins/dfsound/pulseaudio.o
125 endif
126 ifneq ($(findstring libretro,$(SOUND_DRIVERS)),)
127 plugins/dfsound/out.o: CFLAGS += -DHAVE_LIBRETRO
128 endif
129
130 # builtin gpu
131 OBJS += plugins/gpulib/gpu.o plugins/gpulib/vout_pl.o
132 ifeq "$(BUILTIN_GPU)" "neon"
133 OBJS += plugins/gpu_neon/psx_gpu_if.o
134 plugins/gpu_neon/psx_gpu_if.o: CFLAGS += -DNEON_BUILD -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP
135 plugins/gpu_neon/psx_gpu_if.o: plugins/gpu_neon/psx_gpu/*.c
136 frontend/menu.o frontend/plugin_lib.o: CFLAGS += -DBUILTIN_GPU_NEON
137  ifeq "$(HAVE_NEON_ASM)" "1"
138  OBJS += plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o
139  else
140  OBJS += plugins/gpu_neon/psx_gpu/psx_gpu_simd.o
141  plugins/gpu_neon/psx_gpu_if.o: CFLAGS += -DSIMD_BUILD
142  plugins/gpu_neon/psx_gpu/psx_gpu_simd.o: CFLAGS += -DSIMD_BUILD
143  endif
144 endif
145 ifeq "$(BUILTIN_GPU)" "peops"
146 # note: code is not safe for strict-aliasing? (Castlevania problems)
147 plugins/dfxvideo/gpulib_if.o: CFLAGS += -fno-strict-aliasing
148 plugins/dfxvideo/gpulib_if.o: plugins/dfxvideo/prim.c plugins/dfxvideo/soft.c
149 OBJS += plugins/dfxvideo/gpulib_if.o
150 endif
151 ifeq "$(BUILTIN_GPU)" "unai_old"
152 OBJS += plugins/gpu_unai_old/gpulib_if.o
153 ifeq "$(ARCH)" "arm"
154 OBJS += plugins/gpu_unai_old/gpu_arm.o
155 endif
156 plugins/gpu_unai_old/gpulib_if.o: CFLAGS += -DREARMED -O3
157 CC_LINK = $(CXX)
158 endif
159
160 ifeq "$(BUILTIN_GPU)" "unai"
161 OBJS += plugins/gpu_unai/gpulib_if.o
162 ifeq "$(ARCH)" "arm"
163 OBJS += plugins/gpu_unai/gpu_arm.o
164 endif
165 plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -DUSE_GPULIB=1 -O3
166 CC_LINK = $(CXX)
167 endif
168
169 # cdrcimg
170 OBJS += plugins/cdrcimg/cdrcimg.o
171 #ifeq "$(CHD_SUPPORT)" "1"
172 OBJS += libchdr/src/libchdr_bitstream.o
173 OBJS += libchdr/src/libchdr_cdrom.o
174 OBJS += libchdr/src/libchdr_chd.o
175 OBJS += libchdr/src/libchdr_flac.o
176 OBJS += libchdr/src/libchdr_huffman.o
177 OBJS += libchdr/deps/lzma-19.00/src/Alloc.o libchdr/deps/lzma-19.00/src/Bra86.o libchdr/deps/lzma-19.00/src/BraIA64.o libchdr/deps/lzma-19.00/src/CpuArch.o libchdr/deps/lzma-19.00/src/Delta.o
178 OBJS += libchdr/deps/lzma-19.00/src/LzFind.o libchdr/deps/lzma-19.00/src/Lzma86Dec.o libchdr/deps/lzma-19.00/src/LzmaDec.o libchdr/deps/lzma-19.00/src/LzmaEnc.o libchdr/deps/lzma-19.00/src/Sort.o
179 CFLAGS += -DHAVE_CHD -Ilibchdr/include
180 libpcsxcore/cdriso.o: CFLAGS += -Wno-unused-function
181 libchdr/src/%.o: CFLAGS += -Wno-unused -Ilibchdr/deps/lzma-19.00/include -std=gnu11
182 libchdr/deps/lzma-19.00/src/%.o: CFLAGS += -Wno-unused -D_7ZIP_ST -Ilibchdr/deps/lzma-19.00/include
183 #endif
184
185 # frontend/gui
186 OBJS += frontend/cspace.o
187 ifeq "$(HAVE_NEON_ASM)" "1"
188 OBJS += frontend/cspace_neon.o
189 frontend/cspace.o: CFLAGS += -DHAVE_bgr555_to_rgb565 -DHAVE_bgr888_to_x
190 else
191 ifeq "$(ARCH)" "arm"
192 OBJS += frontend/cspace_arm.o
193 frontend/cspace.o: CFLAGS += -DHAVE_bgr555_to_rgb565
194 endif
195 endif
196
197 ifeq "$(PLATFORM)" "generic"
198 OBJS += frontend/libpicofe/in_sdl.o
199 OBJS += frontend/libpicofe/plat_sdl.o
200 OBJS += frontend/libpicofe/plat_dummy.o
201 OBJS += frontend/libpicofe/linux/in_evdev.o
202 OBJS += frontend/plat_sdl.o
203 ifeq "$(HAVE_GLES)" "1"
204 OBJS += frontend/libpicofe/gl.o frontend/libpicofe/gl_platform.o
205 LDLIBS += $(LDLIBS_GLES)
206 frontend/libpicofe/plat_sdl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
207 frontend/libpicofe/gl_platform.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
208 frontend/libpicofe/gl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
209 frontend/plat_sdl.o: CFLAGS += -DHAVE_GLES $(CFLAGS_GLES)
210 endif
211 USE_PLUGIN_LIB = 1
212 USE_FRONTEND = 1
213 endif
214 ifeq "$(PLATFORM)" "pandora"
215 OBJS += frontend/libpicofe/pandora/plat.o
216 OBJS += frontend/libpicofe/linux/fbdev.o frontend/libpicofe/linux/xenv.o
217 OBJS += frontend/libpicofe/linux/in_evdev.o
218 OBJS += frontend/plat_pandora.o frontend/plat_omap.o
219 frontend/main.o frontend/menu.o: CFLAGS += -include frontend/pandora/ui_feat.h
220 frontend/libpicofe/linux/plat.o: CFLAGS += -DPANDORA
221 USE_PLUGIN_LIB = 1
222 USE_FRONTEND = 1
223 endif
224 ifeq "$(PLATFORM)" "caanoo"
225 OBJS += frontend/libpicofe/gp2x/in_gp2x.o frontend/warm/warm.o
226 OBJS += frontend/libpicofe/gp2x/soc_pollux.o
227 OBJS += frontend/libpicofe/linux/in_evdev.o
228 OBJS += frontend/plat_pollux.o frontend/in_tsbutton.o frontend/blit320.o
229 frontend/main.o frontend/menu.o: CFLAGS += -include frontend/320240/ui_gp2x.h
230 USE_PLUGIN_LIB = 1
231 USE_FRONTEND = 1
232 endif
233 ifeq "$(PLATFORM)" "maemo"
234 OBJS += maemo/hildon.o maemo/main.o maemo/maemo_xkb.o frontend/pl_gun_ts.o
235 maemo/%.o: maemo/%.c
236 USE_PLUGIN_LIB = 1
237 LDFLAGS += $(shell pkg-config --libs hildon-1 libpulse)
238 CFLAGS += $(shell pkg-config --cflags hildon-1) -DHAVE_TSLIB
239 CFLAGS += `pkg-config --cflags glib-2.0 libosso dbus-1 hildon-fm-2`
240 LDFLAGS += `pkg-config --libs glib-2.0 libosso dbus-1 hildon-fm-2`
241 endif
242 ifeq "$(PLATFORM)" "libretro"
243 OBJS += frontend/libretro.o
244 CFLAGS += -DFRONTEND_SUPPORTS_RGB565
245
246 ifeq ($(MMAP_WIN32),1)
247 OBJS += libpcsxcore/memmap_win32.o
248 endif
249 endif
250
251 ifeq "$(USE_PLUGIN_LIB)" "1"
252 OBJS += frontend/plugin_lib.o
253 OBJS += frontend/libpicofe/linux/plat.o
254 OBJS += frontend/libpicofe/readpng.o frontend/libpicofe/fonts.o
255 frontend/libpicofe/linux/plat.o: CFLAGS += -DNO_HOME_DIR
256 ifeq "$(HAVE_NEON_ASM)" "1"
257 OBJS += frontend/libpicofe/arm/neon_scale2x.o
258 OBJS += frontend/libpicofe/arm/neon_eagle2x.o
259 frontend/libpicofe/arm/neon_scale2x.o: CFLAGS += -DDO_BGR_TO_RGB
260 frontend/libpicofe/arm/neon_eagle2x.o: CFLAGS += -DDO_BGR_TO_RGB
261 endif
262 endif
263 ifeq "$(USE_FRONTEND)" "1"
264 OBJS += frontend/menu.o
265 OBJS += frontend/libpicofe/input.o
266 frontend/menu.o: frontend/libpicofe/menu.c
267 ifeq "$(HAVE_TSLIB)" "1"
268 frontend/%.o: CFLAGS += -DHAVE_TSLIB
269 OBJS += frontend/pl_gun_ts.o
270 endif
271 else
272 CFLAGS += -DNO_FRONTEND
273 endif
274
275 # misc
276 OBJS += frontend/main.o frontend/plugin.o
277 frontend/main.o: CFLAGS += -DBUILTIN_GPU=$(BUILTIN_GPU)
278
279 frontend/menu.o frontend/main.o: frontend/revision.h
280 frontend/plat_sdl.o frontend/libretro.o: frontend/revision.h
281
282 frontend/libpicofe/%.c:
283         @echo "libpicofe module is missing, please run:"
284         @echo "git submodule init && git submodule update"
285         @exit 1
286
287 libpcsxcore/gte_nf.o: libpcsxcore/gte.c
288         $(CC) -c -o $@ $^ $(CFLAGS) -DFLAGLESS
289
290 frontend/revision.h: FORCE
291         @(git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > $@_
292         @diff -q $@_ $@ > /dev/null 2>&1 || cp $@_ $@
293         @rm $@_
294
295 %.o: %.S
296         $(CC_AS) $(CFLAGS) -c $^ -o $@
297
298
299 target_: $(TARGET)
300
301 $(TARGET): $(OBJS)
302         $(CC_LINK) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(EXTRA_LDFLAGS)
303
304 clean: $(PLAT_CLEAN) clean_plugins
305         $(RM) $(TARGET) $(OBJS) $(TARGET).map frontend/revision.h
306
307 ifneq ($(PLUGINS),)
308 plugins_: $(PLUGINS)
309
310 $(PLUGINS):
311         $(MAKE) -C $(dir $@)
312
313 clean_plugins:
314         $(MAKE) -C plugins/gpulib/ clean
315         for dir in $(PLUGINS) ; do \
316                 $(MAKE) -C $$(dirname $$dir) clean; done
317 else
318 plugins_:
319 clean_plugins:
320 endif
321
322 .PHONY: all clean target_ plugins_ clean_plugins FORCE
323
324 ifneq "$(PLATFORM)" "pandora"
325 ifdef CPATH
326 $(warning warning: CPATH is defined)
327 endif
328 endif
329
330 # ----------- release -----------
331
332 VER ?= $(shell git describe --always HEAD)
333
334 ifeq "$(PLATFORM)" "generic"
335 OUT = pcsx_rearmed_$(VER)
336
337 rel: pcsx $(PLUGINS) \
338                 frontend/pandora/skin readme.txt COPYING
339         rm -rf $(OUT)
340         mkdir -p $(OUT)/plugins
341         mkdir -p $(OUT)/bios
342         cp -r $^ $(OUT)/
343         mv $(OUT)/*.so* $(OUT)/plugins/
344         zip -9 -r $(OUT).zip $(OUT)
345 endif
346
347 ifeq "$(PLATFORM)" "pandora"
348 PND_MAKE ?= $(HOME)/dev/pnd/src/pandora-libraries/testdata/scripts/pnd_make.sh
349
350 rel: pcsx plugins/dfsound/pcsxr_spu_area3.out $(PLUGINS) \
351                 frontend/pandora/pcsx.sh frontend/pandora/pcsx.pxml.templ frontend/pandora/pcsx.png \
352                 frontend/pandora/picorestore frontend/pandora/skin readme.txt COPYING
353         rm -rf out
354         mkdir -p out/plugins
355         cp -r $^ out/
356         sed -e 's/%PR%/$(VER)/g' out/pcsx.pxml.templ > out/pcsx.pxml
357         rm out/pcsx.pxml.templ
358         mv out/*.so out/plugins/
359         $(PND_MAKE) -p pcsx_rearmed_$(VER).pnd -d out -x out/pcsx.pxml -i frontend/pandora/pcsx.png -c
360 endif
361
362 ifeq "$(PLATFORM)" "caanoo"
363 PLAT_CLEAN = caanoo_clean
364
365 caanoo_clean:
366         $(RM) frontend/320240/pollux_set
367
368 rel: pcsx $(PLUGINS) \
369                 frontend/320240/caanoo.gpe frontend/320240/pcsx26.png \
370                 frontend/320240/pcsxb.png frontend/320240/skin \
371                 frontend/warm/bin/warm_2.6.24.ko frontend/320240/pollux_set \
372                 frontend/320240/pcsx_rearmed.ini frontend/320240/haptic_w.cfg \
373                 frontend/320240/haptic_s.cfg \
374                 readme.txt COPYING
375         rm -rf out
376         mkdir -p out/pcsx_rearmed/plugins
377         cp -r $^ out/pcsx_rearmed/
378         mv out/pcsx_rearmed/*.so out/pcsx_rearmed/plugins/
379         mv out/pcsx_rearmed/caanoo.gpe out/pcsx_rearmed/pcsx.gpe
380         mv out/pcsx_rearmed/pcsx_rearmed.ini out/
381         mkdir out/pcsx_rearmed/lib/
382         cp ./lib/libbz2.so.1 out/pcsx_rearmed/lib/
383         mkdir out/pcsx_rearmed/bios/
384         cd out && zip -9 -r ../pcsx_rearmed_$(VER)_caanoo.zip *
385 endif