1 # Makefile for PCSX ReARMed (libretro)
8 # Dynarec options: lightrec, ari64
13 ifeq ($(shell uname -a),)
15 else ifneq ($(findstring MINGW,$(shell uname -a)),)
17 else ifneq ($(findstring Darwin,$(shell uname -a)),)
19 else ifneq ($(findstring win,$(shell uname -a)),)
30 TARGET_NAME := pcsx_rearmed
31 ARCH_DETECTED := $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
32 GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
33 ifneq ($(GIT_VERSION)," unknown")
34 CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
36 ifneq ($(WANT_ZLIB),1)
39 LIBPTHREAD := -lpthread
40 ifneq ($(findstring Haiku,$(shell uname -s)),)
41 LIBDL := -lroot -lnetwork
49 # select some defaults
50 ifneq (,$(findstring $(ARCH_DETECTED),arm aarch64))
52 ifneq ($(findstring __thumb__,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
53 # must disable thumb as ari64 can't handle it
57 ifneq (,$(findstring $(ARCH_DETECTED),x86_64 aarch64))
61 # platform specific options
64 ifeq ($(platform), unix)
65 TARGET := $(TARGET_NAME)_libretro.so
68 ifeq ($(shell uname),Linux)
69 LIGHTREC_CUSTOM_MAP := 1
71 ifneq ($(findstring SunOS,$(shell uname -s)),)
76 else ifneq (,$(findstring CortexA73_G12B,$(platform)))
77 TARGET := $(TARGET_NAME)_libretro.so
79 SHARED := -shared -Wl,-version-script=link.T
84 CFLAGS += -fomit-frame-pointer -ffast-math -DARM
85 CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a73 -mtune=cortex-a73.cortex-a53
88 else ifneq (,$(findstring h5,$(platform)))
89 TARGET := $(TARGET_NAME)_libretro.so
91 SHARED := -shared -Wl,-version-script=link.T
96 CFLAGS += -fomit-frame-pointer -ffast-math -DARM
97 CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a53 -mtune=cortex-a53
99 else ifeq ($(platform), linux-portable)
100 TARGET := $(TARGET_NAME)_libretro.so
101 fpic := -fPIC -nostdlib
102 EXTRA_LDFLAGS += -fPIC -nostdlib
108 LIGHTREC_CUSTOM_MAP := 1
111 else ifeq ($(platform), osx)
113 TARGET := $(TARGET_NAME)_libretro.dylib
116 MACSOSVER = `sw_vers -productVersion | cut -d. -f 1`
117 OSXVER = `sw_vers -productVersion | cut -d. -f 2`
118 OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
119 ifeq ($(OSX_LT_MAVERICKS),YES)
120 fpic += -mmacosx-version-min=10.1
123 ifeq ($(CROSS_COMPILE),1)
124 TARGET_RULE = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
125 CFLAGS += $(TARGET_RULE)
126 CPPFLAGS += $(TARGET_RULE)
127 CXXFLAGS += $(TARGET_RULE)
128 LDFLAGS += $(TARGET_RULE)
131 CFLAGS += $(ARCHFLAGS)
132 CXXFLAGS += $(ARCHFLAGS)
133 LDFLAGS += $(ARCHFLAGS)
136 else ifneq (,$(findstring ios,$(platform)))
137 TARGET := $(TARGET_NAME)_libretro_ios.dylib
139 ifeq ($(DYNAREC),lightrec)
146 IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
149 CFLAGS += -DIOS -marm
150 ifeq ($(platform),ios-arm64)
151 CC = cc -arch arm64 -isysroot $(IOSSDK)
152 CXX = c++ -arch arm64 -isysroot $(IOSSDK)
158 CC = cc -arch armv7 -isysroot $(IOSSDK)
159 CXX = c++ -arch armv7 -isysroot $(IOSSDK)
164 CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
165 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
167 CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
168 ifeq ($(platform),$(filter $(platform),ios9 ios-arm64))
169 MINVERSION = -miphoneos-version-min=8.0
171 MINVERSION = -miphoneos-version-min=5.0
173 CFLAGS += $(MINVERSION)
175 else ifeq ($(platform), tvos-arm64)
176 TARGET := $(TARGET_NAME)_libretro_tvos.dylib
178 ifeq ($(DYNAREC),lightrec)
185 IOSSDK := $(shell xcodebuild -version -sdk appletvos Path)
188 CFLAGS += -DIOS -DTVOS
189 CC = cc -arch arm64 -isysroot $(IOSSDK)
190 CXX = c++ -arch arm64 -isysroot $(IOSSDK)
195 CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
197 # Nintendo Switch (libnx)
198 else ifeq ($(platform), libnx)
199 export DEPSDIR := $(CURDIR)/
200 include $(DEVKITPRO)/libnx/switch_rules
201 TARGET := $(TARGET_NAME)_libretro_$(platform).a
204 CFLAGS += -O3 -fomit-frame-pointer -ffast-math -I$(DEVKITPRO)/libnx/include/ -fPIE -Wl,--allow-multiple-definition # -include $(LIBNX)/include/switch.h
205 CFLAGS += -specs=$(DEVKITPRO)/libnx/switch.specs -DNO_OS -DNO_DYLIB -DNO_SOCKET -D__arm64__ -D__ARM_NEON__
206 CFLAGS += -D__SWITCH__ -DHAVE_LIBNX
207 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
208 CFLAGS += -ftree-vectorize
209 CFLAGS += -Ifrontend/switch -ftree-vectorize
216 # Lakka Switch (arm64)
217 else ifeq ($(platform), arm64)
218 TARGET := $(TARGET_NAME)_libretro.so
224 CFLAGS := $(filter-out -O2, $(CFLAGS))
225 CFLAGS += -O3 -ftree-vectorize
227 # Lightweight PS3 Homebrew SDK
228 else ifeq ($(platform), psl1ght)
229 TARGET := $(TARGET_NAME)_libretro_psl1ght.a
230 CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
231 AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
232 CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
235 else ifeq ($(platform), psp1)
236 TARGET := $(TARGET_NAME)_libretro_psp1.a
237 CC = psp-gcc$(EXE_EXT)
238 AR = psp-ar$(EXE_EXT)
242 else ifeq ($(platform), vita)
243 TARGET := $(TARGET_NAME)_libretro_vita.a
244 CC = arm-vita-eabi-gcc$(EXE_EXT)
245 AR = arm-vita-eabi-ar$(EXE_EXT)
247 CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
248 CFLAGS += -fsingle-precision-constant -mword-relocations -fno-unwind-tables
249 CFLAGS += -fno-asynchronous-unwind-tables -ftree-vectorize -funroll-loops
250 CFLAGS += -fno-optimize-sibling-calls
251 CFLAGS += -I$(VITASDK)/include -Ifrontend/vita
252 CFLAGS += -DNO_SOCKET -DNO_OS -DNO_DYLIB
253 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
255 # CFLAGS += -U__ARM_NEON__
265 else ifeq ($(platform), ctr)
266 TARGET := $(TARGET_NAME)_libretro_ctr.a
267 CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
268 CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
269 AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
270 CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET -DTHREAD_ENABLED -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
271 CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
272 CFLAGS += -Wall -mword-relocations
273 CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
274 CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
275 CFLAGS += -Werror=implicit-function-declaration
276 CFLAGS += -DHAVE_UNISTD_H
278 OBJS += frontend/3ds/utils.o
289 else ifeq ($(platform), xenon)
290 TARGET := $(TARGET_NAME)_libretro_xenon360.a
291 CC = xenon-gcc$(EXE_EXT)
292 AR = xenon-ar$(EXE_EXT)
293 CFLAGS += -D__LIBXENON__ -m32 -D__ppc__
296 else ifeq ($(platform), ngc)
297 TARGET := $(TARGET_NAME)_libretro_ngc.a
298 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
299 AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
300 CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
303 else ifeq ($(platform), wii)
304 TARGET := libretro_$(TARGET_NAME)_wii.a
305 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
306 AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
307 CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
310 else ifeq ($(platform), qnx)
311 TARGET := $(TARGET_NAME)_libretro_qnx.so
313 CC = qcc -Vgcc_ntoarmv7le
320 CFLAGS += -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
321 ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
322 MAIN_LDLIBS += -lsocket
328 else ifeq ($(platform), rpi1)
329 TARGET := $(TARGET_NAME)_libretro.so
331 CFLAGS += -marm -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
332 ASFLAGS += -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
339 else ifeq ($(platform), rpi2)
340 TARGET := $(TARGET_NAME)_libretro.so
342 CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
343 ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
351 else ifeq ($(platform), rpi3)
352 TARGET := $(TARGET_NAME)_libretro.so
354 CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
355 ASFLAGS += -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
362 #Raspberry Pi 3 with a 64bit GNU/Linux OS
363 else ifeq ($(platform), rpi3_64)
364 TARGET := $(TARGET_NAME)_libretro.so
370 CFLAGS += -march=armv8-a+crc+simd -mtune=cortex-a53 -ftree-vectorize
372 #Raspberry Pi 4 with a 32bit GNU/Linux OS
373 else ifeq ($(platform), rpi4)
374 TARGET := $(TARGET_NAME)_libretro.so
376 CFLAGS += -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
377 ASFLAGS += -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
384 #Raspberry Pi 4 with a 64bit GNU/Linux OS
385 else ifeq ($(platform), rpi4_64)
386 TARGET := $(TARGET_NAME)_libretro.so
392 CFLAGS += -march=armv8-a+crc+simd -mtune=cortex-a72 -ftree-vectorize
394 # Classic Platforms ####################
395 # Platform affix = classic_<ISA>_<µARCH>
396 # Help at https://modmyclassic.com/comp
398 # (armv7 a7, hard point, neon based) ###
399 # NESC, SNESC, C64 mini
400 else ifeq ($(platform), classic_armv7_a7)
401 TARGET := $(TARGET_NAME)_libretro.so
404 -flto=4 -fwhole-program -fuse-linker-plugin \
405 -fdata-sections -ffunction-sections -Wl,--gc-sections \
406 -fno-stack-protector -fno-ident -fomit-frame-pointer \
407 -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
408 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
409 -fmerge-all-constants -fno-math-errno \
410 -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
411 CXXFLAGS += $(CFLAGS)
412 CPPFLAGS += $(CFLAGS)
419 ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
420 CFLAGS += -march=armv7-a
422 CFLAGS += -march=armv7ve
423 # If gcc is 5.0 or later
424 ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
425 LDFLAGS += -static-libgcc -static-libstdc++
429 # (armv8 a35, hard point, neon based) ###
430 # PlayStation Classic
431 else ifeq ($(platform), classic_armv8_a35)
432 TARGET := $(TARGET_NAME)_libretro.so
435 -fmerge-all-constants -fno-math-errno -march=armv8-a \
436 -marm -mcpu=cortex-a35 -mtune=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
442 LDFLAGS += -static-libgcc -static-libstdc++ -fPIC
444 #######################################
447 else ifneq (,$(findstring armv,$(platform)))
448 TARGET := $(TARGET_NAME)_libretro.so
452 ifneq (,$(findstring cortexa8,$(platform)))
453 CFLAGS += -marm -mcpu=cortex-a8
454 ASFLAGS += -mcpu=cortex-a8
455 else ifneq (,$(findstring cortexa7,$(platform)))
456 CFLAGS += -marm -mcpu=cortex-a7
457 ASFLAGS += -mcpu=cortex-a7
459 else ifneq (,$(findstring cortexa9,$(platform)))
460 CFLAGS += -marm -mcpu=cortex-a9
461 ASFLAGS += -mcpu=cortex-a9
464 ifneq (,$(findstring neon,$(platform)))
466 ASFLAGS += -mfpu=neon
471 ifneq (,$(findstring softfloat,$(platform)))
472 CFLAGS += -mfloat-abi=softfp
473 ASFLAGS += -mfloat-abi=softfp
474 else ifneq (,$(findstring hardfloat,$(platform)))
475 CFLAGS += -mfloat-abi=hard
476 ASFLAGS += -mfloat-abi=hard
481 else ifeq ($(platform), miyoo)
482 TARGET := $(TARGET_NAME)_libretro.so
483 CC = /opt/miyoo/usr/bin/arm-linux-gcc
484 CXX = /opt/miyoo/usr/bin/arm-linux-g++
486 CFLAGS += -mcpu=arm926ej-s -fsingle-precision-constant
487 CFLAGS += -DGPULIB_USE_MMAP -DGPU_UNAI_USE_INT_DIV_MULTINV -D_MIYOO
494 else ifeq ($(platform), emscripten)
495 TARGET := $(TARGET_NAME)_libretro_$(platform).bc
497 SHARED := -shared -Wl,--no-undefined -Wl,--version-script=link.T
498 CFLAGS += -DNO_DYLIB -DNO_SOCKET
503 TARGET := $(TARGET_NAME)_libretro.dll
505 MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
506 CFLAGS += -D__WIN32__ -DNO_DYLIB
508 MAIN_LDLIBS += -lws2_32
516 MAIN_LDFLAGS += -shared
517 MAIN_LDLIBS += $(LIBPTHREAD) $(LIBM) $(LIBDL) $(LIBZ)
519 # enable large file support if available
520 ifeq ($(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h | grep __SIZEOF_LONG__ | awk '{print $$3}'),4)
521 CFLAGS += -D_FILE_OFFSET_BITS=64
524 # try to autodetect stuff for the lazy
526 ARCH = $(ARCH_DETECTED)
529 HAVE_NEON = $(shell $(CC) -E -dD - < /dev/null 2> /dev/null | grep -q __ARM_NEON__ && echo 1 || echo 0)
531 ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
532 MAIN_LDFLAGS += -Wl,--no-undefined
534 ifdef ALLOW_LIGHTREC_ON_ARM
535 CFLAGS += -DALLOW_LIGHTREC_ON_ARM
538 TARGET ?= libretro.so
541 SOUND_DRIVERS = libretro
547 #ifeq ($(platform),ios)
549 # make -f Makefile.libretro DYNAREC=0 platform=$(platform) clean
550 # make -f Makefile.libretro DYNAREC=0 platform=$(platform)
556 # no special AS needed for gpu_neon
557 plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o: plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.S
558 $(CC) $(CFLAGS) -c $^ -o $@