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