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