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