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