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