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