Fix build
[pcsx_rearmed.git] / Makefile.libretro
... / ...
CommitLineData
1# Makefile for PCSX ReARMed (libretro)
2
3DEBUG ?= 0
4WANT_ZLIB ?= 1
5HAVE_CHD ?= 1
6
7# Dynarec options: lightrec, ari64
8DYNAREC ?= lightrec
9
10ifeq ($(platform),)
11 platform = unix
12 ifeq ($(shell uname -a),)
13 platform = win
14 else ifneq ($(findstring MINGW,$(shell uname -a)),)
15 platform = win
16 else ifneq ($(findstring Darwin,$(shell uname -a)),)
17 platform = osx
18 else ifneq ($(findstring win,$(shell uname -a)),)
19 platform = win
20 endif
21endif
22
23CC ?= gcc
24CXX ?= g++
25AS ?= as
26CC_AS ?= $(CC)
27CFLAGS ?=
28
29TARGET_NAME := pcsx_rearmed
30GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
31ifneq ($(GIT_VERSION)," unknown")
32 CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
33endif
34ifneq ($(WANT_ZLIB),1)
35LIBZ := -lz
36endif
37LIBPTHREAD := -lpthread
38ifneq ($(findstring Haiku,$(shell uname -s)),)
39LIBDL := -lroot -lnetwork
40else
41LIBDL := -ldl
42endif
43LIBM := -lm
44MMAP_WIN32 = 0
45EXTRA_LDFLAGS =
46
47# Unix
48ifeq ($(platform), unix)
49 TARGET := $(TARGET_NAME)_libretro.so
50 fpic := -fPIC
51ifneq ($(findstring SunOS,$(shell uname -s)),)
52 CC = gcc
53endif
54ifeq ($(ARCH), arm)
55ifneq ($(findstring __thumb__,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
56 # must disable thumb as recompiler can't handle it
57 CFLAGS += -marm
58endif
59endif
60
61else ifeq ($(platform), linux-portable)
62 TARGET := $(TARGET_NAME)_libretro.so
63 fpic := -fPIC -nostdlib
64 EXTRA_LDFLAGS += -fPIC -nostdlib
65 LIBZ :=
66 LIBPTHREAD :=
67 LIBDL :=
68 LIBM :=
69 NO_UNDEF_CHECK = 1
70
71# OS X
72else ifeq ($(platform), osx)
73 DYNAREC ?= ari64
74 TARGET := $(TARGET_NAME)_libretro.dylib
75 fpic := -fPIC
76 fpic += -mmacosx-version-min=10.1
77ifeq ($(DYNAREC),lightrec)
78 # Override
79 DYNAREC = 0
80 TARGET := $(TARGET_NAME)_interpreter_libretro.dylib
81endif
82
83# iOS
84else ifeq ($(platform),$(filter $(platform),ios-arm64))
85 ARCH := arm64
86 HAVE_NEON = 0
87 BUILTIN_GPU = peops
88 DYNAREC = 0
89 TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
90
91 CC = clang -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
92 CXX = clang++ -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
93 CFLAGS += -marm -DIOS
94
95else ifneq (,$(findstring ios,$(platform)))
96 ARCH := arm
97 DYNAREC ?= ari64
98 HAVE_NEON = 1
99 BUILTIN_GPU = neon
100 TARGET := $(TARGET_NAME)_libretro_ios.dylib
101ifeq ($(DYNAREC),lightrec)
102 # Override
103 DYNAREC = 0
104 TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
105endif
106 fpic := -fPIC
107
108 ifeq ($(IOSSDK),)
109 IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
110 endif
111
112 CC = clang -arch armv7 -isysroot $(IOSSDK)
113 CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
114 CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
115 CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
116 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
117 CFLAGS += -DIOS
118ifeq ($(platform),ios9)
119 CC += -miphoneos-version-min=8.0
120 CXX += -miphoneos-version-min=8.0
121 CC_AS += -miphoneos-version-min=8.0
122 CFLAGS += -miphoneos-version-min=8.0
123else
124 CC += -miphoneos-version-min=5.0
125 CXX += -miphoneos-version-min=5.0
126 CC_AS += -miphoneos-version-min=5.0
127 CFLAGS += -miphoneos-version-min=5.0
128endif
129
130# Nintendo Switch (libnx)
131else ifeq ($(platform), libnx)
132 export DEPSDIR := $(CURDIR)/
133 include $(DEVKITPRO)/libnx/switch_rules
134 TARGET := $(TARGET_NAME)_libretro_$(platform).a
135 ARCH := arm64
136 BUILTIN_GPU = unai
137 HAVE_VFS_FD = 0
138 CFLAGS += -O3 -fomit-frame-pointer -ffast-math -I$(DEVKITPRO)/libnx/include/ -fPIE -Wl,--allow-multiple-definition -include $(LIBNX)/include/switch.h
139 CFLAGS += -specs=$(DEVKITPRO)/libnx/switch.specs -DNO_OS -DNO_DYLIB -DNO_SOCKET -D__arm64__ -D__ARM_NEON__
140 CFLAGS += -D__SWITCH__
141 CFLAGS += -DARM -D__aarch64__=1 -march=armv8-a -mtune=cortex-a57 -mtp=soft -DHAVE_INTTYPES -DLSB_FIRST -ffast-math -mcpu=cortex-a57+crc+fp+simd -ffunction-sections
142 CFLAGS += -ftree-vectorize
143 CFLAGS += -Ifrontend/switch -ftree-vectorize
144 LIBPTHREAD :=
145 STATIC_LINKING=1
146
147# Lakka Switch (arm64)
148else ifeq ($(platform), arm64)
149 TARGET := $(TARGET_NAME)_libretro.so
150 ARCH := arm64
151 BUILTIN_GPU = unai
152 fpic := -fPIC
153 CFLAGS := $(filter-out -O2, $(CFLAGS))
154 CFLAGS += -O3 -ftree-vectorize
155
156# PS3
157else ifeq ($(platform), ps3)
158 TARGET := $(TARGET_NAME)_libretro_ps3.a
159 CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
160 AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
161 CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
162
163# sncps3
164else ifeq ($(platform), sncps3)
165 TARGET := $(TARGET_NAME)_libretro_ps3.a
166 CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
167 AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
168 CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
169
170# Lightweight PS3 Homebrew SDK
171else ifeq ($(platform), psl1ght)
172 TARGET := $(TARGET_NAME)_libretro_psl1ght.a
173 CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
174 AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
175 CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
176
177# PSP
178else ifeq ($(platform), psp1)
179 TARGET := $(TARGET_NAME)_libretro_psp1.a
180 CC = psp-gcc$(EXE_EXT)
181 AR = psp-ar$(EXE_EXT)
182 CFLAGS += -DPSP -G0
183
184# Vita
185else ifeq ($(platform), vita)
186 TARGET := $(TARGET_NAME)_libretro_vita.a
187 CC = arm-vita-eabi-gcc$(EXE_EXT)
188 AR = arm-vita-eabi-ar$(EXE_EXT)
189 CFLAGS += -DVITA
190 CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
191 CFLAGS += -fsingle-precision-constant -mword-relocations -fno-unwind-tables
192 CFLAGS += -fno-asynchronous-unwind-tables -ftree-vectorize -funroll-loops
193 CFLAGS += -fno-optimize-sibling-calls
194 CFLAGS += -I$(VITASDK)/include -Ifrontend/vita
195 CFLAGS += -DNO_SOCKET -DNO_OS -DNO_DYLIB
196 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
197
198# CFLAGS += -U__ARM_NEON__
199 HAVE_NEON = 1
200 BUILTIN_GPU = neon
201
202 DYNAREC = ari64
203 DRC_CACHE_BASE = 0
204
205 ARCH = arm
206 STATIC_LINKING = 1
207
208# CTR(3DS)
209else ifeq ($(platform), ctr)
210 TARGET := $(TARGET_NAME)_libretro_ctr.a
211 CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
212 CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
213 AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
214 CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET
215 CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
216 CFLAGS += -Wall -mword-relocations
217 CFLAGS += -fomit-frame-pointer -ffast-math
218 CFLAGS += -Ifrontend/3ds
219 CFLAGS += -Werror=implicit-function-declaration
220
221# CFLAGS += -DPCSX
222 BUILTIN_GPU = unai
223 DYNAREC = ari64
224 DRC_CACHE_BASE = 0
225 ARCH = arm
226 HAVE_NEON = 0
227 STATIC_LINKING = 1
228
229# Xbox 360
230else ifeq ($(platform), xenon)
231 TARGET := $(TARGET_NAME)_libretro_xenon360.a
232 CC = xenon-gcc$(EXE_EXT)
233 AR = xenon-ar$(EXE_EXT)
234 CFLAGS += -D__LIBXENON__ -m32 -D__ppc__
235
236# Nintendo Game Cube
237else ifeq ($(platform), ngc)
238 TARGET := $(TARGET_NAME)_libretro_ngc.a
239 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
240 AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
241 CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
242
243# Nintendo Wii
244else ifeq ($(platform), wii)
245 TARGET := libretro_$(TARGET_NAME)_wii.a
246 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
247 AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
248 CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
249
250# QNX
251else ifeq ($(platform), qnx)
252 TARGET := $(TARGET_NAME)_libretro_qnx.so
253 fpic := -fPIC
254 CC = qcc -Vgcc_ntoarmv7le
255 CC_AS = $(CC)
256 HAVE_NEON = 1
257 DYNAREC = ari64
258 DRC_CACHE_BASE = 0
259 BUILTIN_GPU = neon
260 ARCH = arm
261 CFLAGS += -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
262 ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
263 MAIN_LDLIBS += -lsocket
264 LIBPTHREAD :=
265 LIBDL :=
266 LIBM :=
267
268#Raspberry Pi 2
269else ifeq ($(platform), rpi2)
270 TARGET := $(TARGET_NAME)_libretro.so
271 fpic := -fPIC
272 CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
273 ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
274 HAVE_NEON = 1
275 ARCH = arm
276 BUILTIN_GPU = neon
277 DYNAREC = ari64
278
279#Raspberry Pi 3
280else ifeq ($(platform), rpi3)
281 TARGET := $(TARGET_NAME)_libretro.so
282 fpic := -fPIC
283 CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
284 ASFLAGS += -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
285 HAVE_NEON = 1
286 ARCH = arm
287 BUILTIN_GPU = neon
288 DYNAREC = ari64
289
290#Raspberry Pi 4
291else ifeq ($(platform), rpi4)
292 TARGET := $(TARGET_NAME)_libretro.so
293 fpic := -fPIC
294 CFLAGS += -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
295 ASFLAGS += -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
296 HAVE_NEON = 1
297 ARCH = arm
298 BUILTIN_GPU = neon
299 DYNAREC = ari64
300
301# Classic Platforms ####################
302# Platform affix = classic_<ISA>_<µARCH>
303# Help at https://modmyclassic.com/comp
304
305# (armv7 a7, hard point, neon based) ###
306# NESC, SNESC, C64 mini
307else ifeq ($(platform), classic_armv7_a7)
308 TARGET := $(TARGET_NAME)_libretro.so
309 fpic := -fPIC
310 CFLAGS += -Ofast \
311 -flto=4 -fwhole-program -fuse-linker-plugin \
312 -fdata-sections -ffunction-sections -Wl,--gc-sections \
313 -fno-stack-protector -fno-ident -fomit-frame-pointer \
314 -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
315 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
316 -fmerge-all-constants -fno-math-errno \
317 -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
318 CXXFLAGS += $(CFLAGS)
319 CPPFLAGS += $(CFLAGS)
320 ASFLAGS += $(CFLAGS)
321 HAVE_NEON = 1
322 ARCH = arm
323 BUILTIN_GPU = neon
324 DYNAREC = ari64
325 ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
326 CFLAGS += -march=armv7-a
327 else
328 CFLAGS += -march=armv7ve
329 # If gcc is 5.0 or later
330 ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
331 LDFLAGS += -static-libgcc -static-libstdc++
332 endif
333 endif
334
335# (armv8 a35, hard point, neon based) ###
336# PlayStation Classic
337else ifeq ($(platform), classic_armv8_a35)
338 TARGET := $(TARGET_NAME)_libretro.so
339 fpic := -fPIC
340 CFLAGS += -Ofast \
341 -fmerge-all-constants -fno-math-errno -march=armv8-a \
342 -marm -mcpu=cortex-a35 -mtune=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
343 HAVE_NEON = 1
344 ARCH = arm
345 BUILTIN_GPU = neon
346 DYNAREC = ari64
347 LDFLAGS += -static-libgcc -static-libstdc++ -fPIC
348
349#######################################
350
351# ARM
352else ifneq (,$(findstring armv,$(platform)))
353 TARGET := $(TARGET_NAME)_libretro.so
354 fpic := -fPIC
355 HAVE_NEON = 0
356 DRC_CACHE_BASE = 0
357 BUILTIN_GPU = peops
358 ifneq (,$(findstring cortexa8,$(platform)))
359 CFLAGS += -marm -mcpu=cortex-a8
360 ASFLAGS += -mcpu=cortex-a8
361 else ifneq (,$(findstring cortexa7,$(platform)))
362 CFLAGS += -marm -mcpu=cortex-a7
363 ASFLAGS += -mcpu=cortex-a7
364 LIBZ :=
365 else ifneq (,$(findstring cortexa9,$(platform)))
366 CFLAGS += -marm -mcpu=cortex-a9
367 ASFLAGS += -mcpu=cortex-a9
368 endif
369 CFLAGS += -marm
370 ifneq (,$(findstring neon,$(platform)))
371 CFLAGS += -mfpu=neon
372 ASFLAGS += -mfpu=neon
373 HAVE_NEON = 1
374 BUILTIN_GPU = neon
375 endif
376 ifneq (,$(findstring softfloat,$(platform)))
377 CFLAGS += -mfloat-abi=softfp
378 ASFLAGS += -mfloat-abi=softfp
379 else ifneq (,$(findstring hardfloat,$(platform)))
380 CFLAGS += -mfloat-abi=hard
381 ASFLAGS += -mfloat-abi=hard
382 endif
383 ARCH = arm
384 DYNAREC = ari64
385
386# Windows
387else
388 TARGET := $(TARGET_NAME)_libretro.dll
389 BUILTIN_GPU = peops
390 PLATFORM = libretro
391 MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
392 CFLAGS += -D__WIN32__ -DNO_DYLIB
393 MMAP_WIN32=1
394 MAIN_LDLIBS += -lws2_32
395 LIBPTHREAD :=
396 LIBDL :=
397 LIBM :=
398endif
399
400CFLAGS += $(fpic)
401MAIN_LDFLAGS += -shared
402MAIN_LDLIBS += $(LIBPTHREAD) $(LIBM) $(LIBDL) $(LIBZ)
403
404# enable large file support if available
405ifeq ($(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h | grep __SIZEOF_LONG__ | awk '{print $$3}'),4)
406CFLAGS += -D_FILE_OFFSET_BITS=64
407endif
408
409# try to autodetect stuff for the lazy
410ifndef ARCH
411ARCH = $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
412endif
413ifndef HAVE_NEON
414HAVE_NEON = $(shell $(CC) -E -dD - < /dev/null 2> /dev/null | grep -q __ARM_NEON__ && echo 1 || echo 0)
415endif
416ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
417MAIN_LDFLAGS += -Wl,--no-undefined
418endif
419
420TARGET ?= libretro.so
421PLATFORM = libretro
422BUILTIN_GPU ?= peops
423SOUND_DRIVERS = libretro
424PLUGINS =
425NO_CONFIG_MAK = yes
426
427# what does this do
428#libretro_all: all
429#ifeq ($(platform),ios)
430#ifeq ($(DYNAREC),1)
431# make -f Makefile.libretro DYNAREC=0 platform=$(platform) clean
432# make -f Makefile.libretro DYNAREC=0 platform=$(platform)
433#endif
434#endif
435
436include Makefile
437
438# no special AS needed for gpu_neon
439plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o: plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.S
440 $(CC) $(CFLAGS) -c $^ -o $@