Merge pull request #454 from justinweiss/handle-oob-cd-reads
[pcsx_rearmed.git] / Makefile.libretro
CommitLineData
706252fc 1# Makefile for PCSX ReARMed (libretro)
2
a9422018
HH
3DEBUG ?= 0
4WANT_ZLIB ?= 1
b0ec2e6d 5HAVE_CHD ?= 1
9b400da1 6
6f1edc3c
PC
7# Dynarec options: lightrec, ari64
8DYNAREC ?= lightrec
9
1c6ab616 10ifeq ($(platform),)
fb01e82a 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
1c6ab616 21endif
22
a4874585
C
23CC ?= gcc
24CXX ?= g++
25AS ?= as
8ad07683 26CC_AS ?= $(CC)
b09a1d34 27CFLAGS ?=
1c6ab616 28
468564e2 29TARGET_NAME := pcsx_rearmed
8fc5171a
GR
30GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
31ifneq ($(GIT_VERSION)," unknown")
32 CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
33endif
7795edd6 34ifneq ($(WANT_ZLIB),1)
917a47e0 35LIBZ := -lz
7795edd6 36endif
917a47e0 37LIBPTHREAD := -lpthread
2085a865 38ifneq ($(findstring Haiku,$(shell uname -s)),)
39LIBDL := -lroot -lnetwork
40else
8356146f 41LIBDL := -ldl
2085a865 42endif
958c9818 43LIBM := -lm
a9422018 44MMAP_WIN32 = 0
917a47e0 45EXTRA_LDFLAGS =
ce0e7ac9 46
fb01e82a 47# Unix
1c6ab616 48ifeq ($(platform), unix)
fb01e82a 49 TARGET := $(TARGET_NAME)_libretro.so
50 fpic := -fPIC
2085a865 51ifneq ($(findstring SunOS,$(shell uname -s)),)
cf1d58b3 52 CC = gcc
53endif
4abd2871
HH
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
fb01e82a 60
917a47e0 61else ifeq ($(platform), linux-portable)
62 TARGET := $(TARGET_NAME)_libretro.so
63 fpic := -fPIC -nostdlib
64 EXTRA_LDFLAGS += -fPIC -nostdlib
917a47e0 65 LIBZ :=
66 LIBPTHREAD :=
67 LIBDL :=
958c9818 68 LIBM :=
95527e35 69 NO_UNDEF_CHECK = 1
70
fb01e82a 71# OS X
1c6ab616 72else ifeq ($(platform), osx)
9382523c 73 DYNAREC ?= lightrec
fb01e82a 74 TARGET := $(TARGET_NAME)_libretro.dylib
75 fpic := -fPIC
33b82111 76 fpic += -mmacosx-version-min=10.1
fb01e82a 77
78# iOS
aab1b446 79else ifeq ($(platform),$(filter $(platform),ios-arm64))
a9422018 80 ARCH := arm64
a9422018
HH
81 HAVE_NEON = 0
82 BUILTIN_GPU = peops
405f21d0 83 DYNAREC = 0
d1cce326
YS
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
8fb0f7c5 89
5c166f37 90else ifneq (,$(findstring ios,$(platform)))
fb01e82a 91 ARCH := arm
3d96277d 92 DYNAREC ?= ari64
c8c2bdfe 93 HAVE_NEON = 1
94 BUILTIN_GPU = neon
fb01e82a 95 TARGET := $(TARGET_NAME)_libretro_ios.dylib
3d96277d 96ifeq ($(DYNAREC),lightrec)
cbf0ed57 97 # Override
405f21d0 98 DYNAREC = 0
cbf0ed57
JC
99 TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
100endif
fb01e82a 101 fpic := -fPIC
1c6ab616 102
fb01e82a 103 ifeq ($(IOSSDK),)
d45e563f 104 IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
fb01e82a 105 endif
ac86f051 106
fb01e82a 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
fb01e82a 112 CFLAGS += -DIOS
5c166f37 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
fb01e82a 124
12367ad0 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 :=
12367ad0 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
12367ad0 150
fb01e82a 151# PS3
1c6ab616 152else ifeq ($(platform), ps3)
fb01e82a 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
1c6ab616 159else ifeq ($(platform), sncps3)
fb01e82a 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
1c6ab616 166else ifeq ($(platform), psl1ght)
fb01e82a 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
1c6ab616 173else ifeq ($(platform), psp1)
93305561 174 TARGET := $(TARGET_NAME)_libretro_psp1.a
1c6ab616 175 CC = psp-gcc$(EXE_EXT)
176 AR = psp-ar$(EXE_EXT)
177 CFLAGS += -DPSP -G0
fb01e82a 178
c90258c8 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
778ad9ce 186 CFLAGS += -fsingle-precision-constant -mword-relocations -fno-unwind-tables
73081f23 187 CFLAGS += -fno-asynchronous-unwind-tables -ftree-vectorize -funroll-loops
ddd39f20 188 CFLAGS += -fno-optimize-sibling-calls -fcommon
c4052f4d 189 CFLAGS += -I$(VITASDK)/include -Ifrontend/vita
190 CFLAGS += -DNO_SOCKET -DNO_OS -DNO_DYLIB
c90258c8 191 ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
c4052f4d 192
95527e35 193# CFLAGS += -U__ARM_NEON__
c90258c8 194 HAVE_NEON = 1
195 BUILTIN_GPU = neon
196
3d96277d 197 DYNAREC = ari64
1cc8c854 198 DRC_CACHE_BASE = 0
c4052f4d 199
200 ARCH = arm
95527e35 201 STATIC_LINKING = 1
c4052f4d 202
fc99395c 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)
eca6163f 209 CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
f72db18e 210 CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
31f52a9f 211 CFLAGS += -Wall -mword-relocations -fcommon
eca6163f 212 CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
31f52a9f 213 CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
fc99395c 214 CFLAGS += -Werror=implicit-function-declaration
215
b37c639e
JW
216 OBJS += frontend/3ds/utils.o
217
fc99395c 218# CFLAGS += -DPCSX
c1567e8c 219 BUILTIN_GPU = unai
3d96277d 220 DYNAREC = ari64
9508b4c7 221 DRC_CACHE_BASE = 0
fc99395c 222 ARCH = arm
86cf0ab7 223 HAVE_NEON = 0
fc99395c 224 STATIC_LINKING = 1
225
fb01e82a 226# Xbox 360
1c6ab616 227else ifeq ($(platform), xenon)
fb01e82a 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
1c6ab616 234else ifeq ($(platform), ngc)
fb01e82a 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
1c6ab616 241else ifeq ($(platform), wii)
fb01e82a 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
a4874585 248else ifeq ($(platform), qnx)
fb01e82a 249 TARGET := $(TARGET_NAME)_libretro_qnx.so
ea13a2f2 250 fpic := -fPIC
fb01e82a 251 CC = qcc -Vgcc_ntoarmv7le
252 CC_AS = $(CC)
253 HAVE_NEON = 1
3d96277d 254 DYNAREC = ari64
fb01e82a 255 DRC_CACHE_BASE = 0
256 BUILTIN_GPU = neon
257 ARCH = arm
1e212a25 258 CFLAGS += -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
a9422018 259 ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
95527e35 260 MAIN_LDLIBS += -lsocket
261 LIBPTHREAD :=
262 LIBDL :=
958c9818 263 LIBM :=
fb01e82a 264
ea13a2f2
LM
265#Raspberry Pi 2
266else ifeq ($(platform), rpi2)
267 TARGET := $(TARGET_NAME)_libretro.so
268 fpic := -fPIC
ea13a2f2 269 CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
f125f441 270 ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
ea13a2f2
LM
271 HAVE_NEON = 1
272 ARCH = arm
273 BUILTIN_GPU = neon
3d96277d 274 DYNAREC = ari64
778ad9ce 275
46ffb580
LM
276#Raspberry Pi 3
277else ifeq ($(platform), rpi3)
278 TARGET := $(TARGET_NAME)_libretro.so
279 fpic := -fPIC
46ffb580
LM
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
3d96277d 285 DYNAREC = ari64
ea13a2f2 286
40aec7ad
EM
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
3d96277d 296 DYNAREC = ari64
40aec7ad 297
d28150f7
RSH
298# Classic Platforms ####################
299# Platform affix = classic_<ISA>_<µARCH>
166f75f0 300# Help at https://modmyclassic.com/comp
d28150f7
RSH
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 \
10a39de1 314 -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
166f75f0
RSH
315 CXXFLAGS += $(CFLAGS)
316 CPPFLAGS += $(CFLAGS)
d28150f7
RSH
317 ASFLAGS += $(CFLAGS)
318 HAVE_NEON = 1
319 ARCH = arm
320 BUILTIN_GPU = neon
3d96277d 321 DYNAREC = ari64
10a39de1 322 ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
a9422018 323 CFLAGS += -march=armv7-a
10a39de1 324 else
a9422018
HH
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
10a39de1 330 endif
5ffd1f23
WS
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
763dadc7
WS
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
5ffd1f23
WS
340 HAVE_NEON = 1
341 ARCH = arm
342 BUILTIN_GPU = neon
3d96277d 343 DYNAREC = ari64
5ffd1f23
WS
344 LDFLAGS += -static-libgcc -static-libstdc++ -fPIC
345
d28150f7
RSH
346#######################################
347
fb01e82a 348# ARM
1af4c281 349else ifneq (,$(findstring armv,$(platform)))
fb01e82a 350 TARGET := $(TARGET_NAME)_libretro.so
53919f9e 351 fpic := -fPIC
2cf8d379 352 HAVE_NEON = 0
fb01e82a 353 DRC_CACHE_BASE = 0
2cf8d379 354 BUILTIN_GPU = peops
fb01e82a 355 ifneq (,$(findstring cortexa8,$(platform)))
356 CFLAGS += -marm -mcpu=cortex-a8
357 ASFLAGS += -mcpu=cortex-a8
77aa1e8a
A
358 else ifneq (,$(findstring cortexa7,$(platform)))
359 CFLAGS += -marm -mcpu=cortex-a7
360 ASFLAGS += -mcpu=cortex-a7
17d0c85f 361 LIBZ :=
fb01e82a 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
3d96277d 381 DYNAREC = ari64
fb01e82a 382
db0d70df 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
fb01e82a 391# Windows
1c6ab616 392else
fb01e82a 393 TARGET := $(TARGET_NAME)_libretro.dll
a9422018
HH
394 BUILTIN_GPU = peops
395 PLATFORM = libretro
95527e35 396 MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
778ad9ce 397 CFLAGS += -D__WIN32__ -DNO_DYLIB
fb01e82a 398 MMAP_WIN32=1
95527e35 399 MAIN_LDLIBS += -lws2_32
400 LIBPTHREAD :=
401 LIBDL :=
958c9818 402 LIBM :=
1c6ab616 403endif
404
c4052f4d 405CFLAGS += $(fpic)
9aff1963 406MAIN_LDFLAGS += -shared
958c9818 407MAIN_LDLIBS += $(LIBPTHREAD) $(LIBM) $(LIBDL) $(LIBZ)
706252fc 408
99a5a336
HH
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
4e0771f5 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
95527e35 421ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
4e0771f5 422MAIN_LDFLAGS += -Wl,--no-undefined
423endif
424
a4874585 425TARGET ?= libretro.so
706252fc 426PLATFORM = libretro
a4874585 427BUILTIN_GPU ?= peops
706252fc 428SOUND_DRIVERS = libretro
9aff1963 429PLUGINS =
430NO_CONFIG_MAK = yes
706252fc 431
3bc0af70 432# what does this do
433#libretro_all: all
434#ifeq ($(platform),ios)
3d96277d 435#ifeq ($(DYNAREC),1)
436# make -f Makefile.libretro DYNAREC=0 platform=$(platform) clean
437# make -f Makefile.libretro DYNAREC=0 platform=$(platform)
3bc0af70 438#endif
439#endif
cbf0ed57 440
9aff1963 441include Makefile
cd230693 442
af32009f 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 $@