use gas-preprocessor for ios
[pcsx_rearmed.git] / Makefile.libretro
1 # Makefile for PCSX ReARMed (libretro)
2
3 # default stuff goes here, so that config can override
4 CFLAGS += -Wall -ggdb -Iinclude -ffast-math
5 ifndef DEBUG
6 CFLAGS += -O2 -DNDEBUG
7 endif
8 CXXFLAGS += $(CFLAGS)
9 #DRC_DBG = 1
10 #PCNT = 1
11
12 all: target_ plugins_
13
14 ifeq ($(platform),)
15 platform = unix
16 ifeq ($(shell uname -a),)
17    platform = win
18 else ifneq ($(findstring MINGW,$(shell uname -a)),)
19    platform = win
20 else ifneq ($(findstring Darwin,$(shell uname -a)),)
21    platform = osx
22 else ifneq ($(findstring win,$(shell uname -a)),)
23    platform = win
24 endif
25 endif
26
27 CC ?= gcc
28 CXX ?= g++
29 AS ?= as
30 CC_AS ?= $(CC)
31
32 ifeq ($(platform), unix)
33    TARGET := snes9x_next_libretro.so
34    fpic := -fPIC
35    SHARED := -shared -Wl,--version-script=libretro/link.T
36 else ifeq ($(platform), osx)
37    TARGET := snes9x_next_libretro.dylib
38    fpic := -fPIC
39    SHARED := -dynamiclib
40 else ifeq ($(platform), ios)
41 ARCH := arm
42    TARGET := snes9x_next_libretro.dylib
43    fpic := -fPIC
44    SHARED := -dynamiclib
45
46 CC = clang -arch armv7 -isysroot $(IOSSDK)
47 CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
48 CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
49 CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
50 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
51    HAVE_NEON = 1
52    CFLAGS += -DIOS
53 else ifeq ($(platform), ps3)
54    TARGET := snes9x_next_libretro_ps3.a
55    CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
56    AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
57    CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
58 else ifeq ($(platform), sncps3)
59    TARGET := snes9x_next_libretro_ps3.a
60    CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
61    AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
62    CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
63 else ifeq ($(platform), psl1ght)
64    TARGET := snes9x_next_libretro_psl1ght.a
65    CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
66    AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
67    CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
68 else ifeq ($(platform), psp1)
69         TARGET := snes9x_next_libretro_psp1.a
70         CC = psp-gcc$(EXE_EXT)
71         AR = psp-ar$(EXE_EXT)
72         CFLAGS += -DPSP -G0
73 else ifeq ($(platform), xenon)
74    TARGET := snes9x_next_libretro_xenon360.a
75    CC = xenon-gcc$(EXE_EXT)
76    AR = xenon-ar$(EXE_EXT)
77    CFLAGS += -D__LIBXENON__ -m32 -D__ppc__
78 else ifeq ($(platform), ngc)
79    TARGET := snes9x_next_libretro_ngc.a
80    CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
81    AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
82    CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
83 else ifeq ($(platform), wii)
84    TARGET := snes9x_next_libretro_wii.a
85    CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
86    AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
87    CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
88 else ifeq ($(platform), qnx)
89    TARGET := libretro_pcsx_rearmed_qnx.so
90    HAVE_NEON = 1
91    USE_DYNAREC = 1
92    DRC_CACHE_BASE = 0
93    BUILTIN_GPU = neon
94    ARCH = arm
95    CFLAGS += -DBASE_ADDR_FIXED=0 -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
96    ASFLAGS +=  -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp
97 else
98    TARGET := snes9x_next_retro.dll
99    CC = gcc
100    fpic := -fPIC
101    LD_FLAGS := -fPIC
102    SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=libretro/link.T
103    CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__
104 endif
105
106 CFLAGS +=  -fPIC
107 ASFLAGS += 
108 LDFLAGS += 
109
110 ifneq ($(platform),qnx)
111    LDLIBS += -lpthread
112    MAIN_LDLIBS += -ldl
113 endif
114 MAIN_LDFLAGS +=  -shared
115 MAIN_LDLIBS += -lm -lz
116 PLUGIN_CFLAGS +=  -fPIC
117
118 TARGET ?= libretro.so
119 PLATFORM = libretro
120 BUILTIN_GPU ?= peops
121 SOUND_DRIVERS = libretro
122 #PLUGINS = plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so
123
124 CC_LINK = $(CC)
125 LDFLAGS += $(MAIN_LDFLAGS)
126 LDLIBS += $(MAIN_LDLIBS)
127 ifdef PCNT
128 CFLAGS += -DPCNT
129 endif
130
131 # core
132 OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore/debug.o \
133         libpcsxcore/decode_xa.o libpcsxcore/disr3000a.o libpcsxcore/mdec.o \
134         libpcsxcore/misc.o libpcsxcore/plugins.o libpcsxcore/ppf.o libpcsxcore/psxbios.o \
135         libpcsxcore/psxcommon.o libpcsxcore/psxcounters.o libpcsxcore/psxdma.o libpcsxcore/psxhle.o \
136         libpcsxcore/psxhw.o libpcsxcore/psxinterpreter.o libpcsxcore/psxmem.o libpcsxcore/r3000a.o \
137         libpcsxcore/sio.o libpcsxcore/socket.o libpcsxcore/spu.o
138 OBJS += libpcsxcore/gte.o libpcsxcore/gte_nf.o libpcsxcore/gte_divider.o
139 ifeq "$(ARCH)" "arm"
140 OBJS += libpcsxcore/gte_arm.o
141 endif
142 ifeq "$(HAVE_NEON)" "1"
143 OBJS += libpcsxcore/gte_neon.o
144 endif
145 libpcsxcore/psxbios.o: CFLAGS += -Wno-nonnull
146
147 # dynarec
148 ifeq "$(USE_DYNAREC)" "1"
149 OBJS += libpcsxcore/new_dynarec/new_dynarec.o libpcsxcore/new_dynarec/linkage_arm.o
150 OBJS += libpcsxcore/new_dynarec/pcsxmem.o
151 else
152 libpcsxcore/new_dynarec/emu_if.o: CFLAGS += -DDRC_DISABLE
153 endif
154 OBJS += libpcsxcore/new_dynarec/emu_if.o
155 libpcsxcore/new_dynarec/new_dynarec.o: libpcsxcore/new_dynarec/assem_arm.c \
156         libpcsxcore/new_dynarec/pcsxmem_inline.c
157 libpcsxcore/new_dynarec/new_dynarec.o: CFLAGS += -Wno-all -Wno-pointer-sign
158 ifdef DRC_DBG
159 libpcsxcore/new_dynarec/emu_if.o: CFLAGS += -D_FILE_OFFSET_BITS=64
160 CFLAGS += -DDRC_DBG
161 endif
162 ifeq "$(DRC_CACHE_BASE)" "1"
163 libpcsxcore/new_dynarec/%.o: CFLAGS += -DBASE_ADDR_FIXED=1
164 endif
165
166 # spu
167 OBJS += plugins/dfsound/dma.o plugins/dfsound/freeze.o \
168         plugins/dfsound/registers.o plugins/dfsound/spu.o \
169         plugins/dfsound/out.o
170 plugins/dfsound/spu.o: plugins/dfsound/adsr.c plugins/dfsound/reverb.c \
171         plugins/dfsound/xa.c
172 ifeq "$(ARCH)" "arm"
173 OBJS += plugins/dfsound/arm_utils.o
174 endif
175 plugins/dfsound/out.o: CFLAGS += -DHAVE_LIBRETRO
176
177 # builtin gpu
178 OBJS += plugins/gpulib/gpu.o plugins/gpulib/vout_pl.o
179 ifeq "$(BUILTIN_GPU)" "neon"
180 OBJS += plugins/gpu_neon/psx_gpu_if.o plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o
181 plugins/gpu_neon/psx_gpu_if.o: CFLAGS += -DNEON_BUILD -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP
182 plugins/gpu_neon/psx_gpu_if.o: plugins/gpu_neon/psx_gpu/*.c
183 endif
184 ifeq "$(BUILTIN_GPU)" "peops"
185 # note: code is not safe for strict-aliasing? (Castlevania problems)
186 plugins/dfxvideo/gpulib_if.o: CFLAGS += -fno-strict-aliasing
187 plugins/dfxvideo/gpulib_if.o: plugins/dfxvideo/prim.c plugins/dfxvideo/soft.c
188 OBJS += plugins/dfxvideo/gpulib_if.o
189 endif
190 ifeq "$(BUILTIN_GPU)" "unai"
191 OBJS += plugins/gpu_unai/gpulib_if.o
192 ifeq "$(ARCH)" "arm"
193 OBJS += plugins/gpu_unai/gpu_arm.o
194 endif
195 plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -O3 
196 CC_LINK = $(CXX)
197 endif
198
199 # cdrcimg
200 OBJS += plugins/cdrcimg/cdrcimg.o
201
202 # dfinput
203 OBJS += plugins/dfinput/main.o plugins/dfinput/pad.o plugins/dfinput/guncon.o
204
205 # frontend/gui
206 OBJS += frontend/cspace.o
207 ifeq "$(HAVE_NEON)" "1"
208 OBJS += frontend/cspace_neon.o
209 else
210 ifeq "$(ARCH)" "arm"
211 OBJS += frontend/cspace_arm.o
212 endif
213 endif
214
215 CFLAGS += -DFRONTEND_SUPPORTS_RGB565 -DNO_FRONTEND
216
217 # misc
218 OBJS += frontend/libretro.o frontend/main.o frontend/plugin.o
219
220
221 frontend/menu.o frontend/main.o: frontend/revision.h
222 frontend/libretro.o: frontend/revision.h
223
224 libpcsxcore/gte_nf.o: libpcsxcore/gte.c
225         $(CC) -c -o $@ $^ $(CFLAGS) -DFLAGLESS
226
227 frontend/revision.h: FORCE
228         @(git describe || echo) | sed -e 's/.*/#define REV "\0"/' > $@_
229         @diff -q $@_ $@ > /dev/null 2>&1 || cp $@_ $@
230         @rm $@_
231
232 %.o: %.S
233         $(CC_AS) $(CFLAGS) -c $^ -o $@
234         
235 %.o: %.s
236         $(CC) $(ASFLAGS) -c $^ -o $@
237
238
239 target_: $(TARGET)
240
241 $(TARGET): $(OBJS)
242         $(CC_LINK) -o $@ $^ $(LDFLAGS) $(LDLIBS) -Wl,-Map=$@.map
243
244 clean: $(PLAT_CLEAN) clean_plugins
245         $(RM) $(TARGET) $(OBJS) $(TARGET).map frontend/revision.h
246
247 ifneq ($(PLUGINS),)
248 plugins_: $(PLUGINS)
249
250 $(PLUGINS):
251         make -C $(dir $@)
252
253 clean_plugins:
254         make -C plugins/gpulib/ clean
255         for dir in $(PLUGINS) ; do \
256                 $(MAKE) -C $$(dirname $$dir) clean; done
257 else
258 plugins_:
259 clean_plugins:
260 endif
261
262 .PHONY: all clean target_ plugins_ clean_plugins FORCE