aboutsummaryrefslogtreecommitdiff
path: root/Makefile.libretro
blob: 60feab413346bcc196d1d62527fb1aac88a58480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# Makefile for PCSX ReARMed (libretro)

DEBUG ?= 0
WANT_ZLIB ?= 1
HAVE_CHD ?= 1

# Dynarec options: lightrec, ari64
DYNAREC ?= lightrec

ifeq ($(platform),)
	platform = unix
	ifeq ($(shell uname -a),)
		platform = win
	else ifneq ($(findstring MINGW,$(shell uname -a)),)
		platform = win
	else ifneq ($(findstring Darwin,$(shell uname -a)),)
		platform = osx
	else ifneq ($(findstring win,$(shell uname -a)),)
		platform = win
	endif
endif

CC ?= gcc
CXX ?= g++
AS ?= as
CC_AS ?= $(CC)
CFLAGS ?=

TARGET_NAME := pcsx_rearmed
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
	CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
ifneq ($(WANT_ZLIB),1)
LIBZ := -lz
endif
LIBPTHREAD := -lpthread
ifneq ($(findstring Haiku,$(shell uname -s)),)
LIBDL := -lroot -lnetwork
else
LIBDL := -ldl
endif
LIBM := -lm
MMAP_WIN32 = 0
EXTRA_LDFLAGS =

# Unix
ifeq ($(platform), unix)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	THREAD_RENDERING = 1
ifneq ($(findstring SunOS,$(shell uname -s)),)
	CC = gcc
endif
ifeq ($(ARCH), arm)
ifneq ($(findstring __thumb__,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
	# must disable thumb as recompiler can't handle it
	CFLAGS += -marm
endif
endif

# ODROIDN2
else ifneq (,$(findstring CortexA73_G12B,$(platform)))
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	SHARED := -shared -Wl,-version-script=link.T
	ARCH = arm64
	CFLAGS += -fomit-frame-pointer -ffast-math -DARM
	CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a73 -mtune=cortex-a73.cortex-a53

# ALLWINNER H5
else ifneq (,$(findstring h5,$(platform)))
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	SHARED := -shared -Wl,-version-script=link.T
	ARCH = arm64
	DYNAREC ?= lightrec
	CFLAGS += -fomit-frame-pointer -ffast-math -DARM
	CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a53 -mtune=cortex-a53

else ifeq ($(platform), linux-portable)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC -nostdlib
	EXTRA_LDFLAGS += -fPIC -nostdlib
	LIBZ :=
	LIBPTHREAD :=
	LIBDL :=
	LIBM :=
	NO_UNDEF_CHECK = 1

# OS X
else ifeq ($(platform), osx)
	DYNAREC ?= lightrec
	TARGET := $(TARGET_NAME)_libretro.dylib
	fpic := -fPIC
	fpic += -mmacosx-version-min=10.1

# iOS
else ifeq ($(platform),$(filter $(platform),ios-arm64))
	ARCH := arm64
	HAVE_NEON = 0
	BUILTIN_GPU = peops
	DYNAREC = 0
	TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib

	CC = clang -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
	CXX = clang++ -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
	CFLAGS += -marm -DIOS

else ifneq (,$(findstring ios,$(platform)))
	ARCH := arm
#	DYNAREC ?= ari64
	HAVE_NEON = 1
	BUILTIN_GPU = neon
	TARGET := $(TARGET_NAME)_libretro_ios.dylib
ifeq ($(DYNAREC),lightrec)
	# Override
	DYNAREC := 0
endif
ifeq ($(DYNAREC),0)
	TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
endif
	fpic := -fPIC

	ifeq ($(IOSSDK),)
		IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
	endif

	CC = clang -arch armv7 -isysroot $(IOSSDK)
	CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
	CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
	CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
	ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
	CFLAGS += -DIOS
ifeq ($(platform),ios9)
	CC     += -miphoneos-version-min=8.0
	CXX    += -miphoneos-version-min=8.0
	CC_AS  += -miphoneos-version-min=8.0
	CFLAGS += -miphoneos-version-min=8.0
else
	CC     += -miphoneos-version-min=5.0
	CXX    += -miphoneos-version-min=5.0
	CC_AS  += -miphoneos-version-min=5.0
	CFLAGS += -miphoneos-version-min=5.0
endif

# Nintendo Switch (libnx)
else ifeq ($(platform), libnx)
   export DEPSDIR := $(CURDIR)/
   include $(DEVKITPRO)/libnx/switch_rules
   TARGET := $(TARGET_NAME)_libretro_$(platform).a
   ARCH := arm64
   BUILTIN_GPU = unai
   HAVE_VFS_FD = 0
   CFLAGS += -O3 -fomit-frame-pointer -ffast-math -I$(DEVKITPRO)/libnx/include/ -fPIE -Wl,--allow-multiple-definition -include $(LIBNX)/include/switch.h
   CFLAGS += -specs=$(DEVKITPRO)/libnx/switch.specs -DNO_OS -DNO_DYLIB -DNO_SOCKET -D__arm64__ -D__ARM_NEON__
   CFLAGS += -D__SWITCH__
   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
   CFLAGS += -ftree-vectorize
   CFLAGS += -Ifrontend/switch -ftree-vectorize
   LIBPTHREAD :=
   STATIC_LINKING=1
   # Lightning requires rw/rx patches first
   DYNAREC := 0

# Lakka Switch (arm64)
else ifeq ($(platform), arm64)
   TARGET := $(TARGET_NAME)_libretro.so
   ARCH := arm64
   BUILTIN_GPU = unai
   fpic := -fPIC
   CFLAGS := $(filter-out -O2, $(CFLAGS))
   CFLAGS += -O3 -ftree-vectorize

# Lightweight PS3 Homebrew SDK
else ifeq ($(platform), psl1ght)
	TARGET := $(TARGET_NAME)_libretro_psl1ght.a
	CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
	AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
	CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__

# PSP
else ifeq ($(platform), psp1)
	TARGET := $(TARGET_NAME)_libretro_psp1.a
	CC = psp-gcc$(EXE_EXT)
	AR = psp-ar$(EXE_EXT)
	CFLAGS += -DPSP -G0

# Vita
else ifeq ($(platform), vita)
	TARGET := $(TARGET_NAME)_libretro_vita.a
	CC = arm-vita-eabi-gcc$(EXE_EXT)
	AR = arm-vita-eabi-ar$(EXE_EXT)
	CFLAGS += -DVITA
	CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
	CFLAGS += -fsingle-precision-constant -mword-relocations -fno-unwind-tables
	CFLAGS += -fno-asynchronous-unwind-tables -ftree-vectorize -funroll-loops
	CFLAGS += -fno-optimize-sibling-calls
	CFLAGS += -I$(VITASDK)/include -Ifrontend/vita
	CFLAGS += -DNO_SOCKET -DNO_OS -DNO_DYLIB
	ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon

#	CFLAGS += -U__ARM_NEON__
	HAVE_NEON = 1
	BUILTIN_GPU = neon

	DYNAREC = ari64
	DRC_CACHE_BASE = 0

	ARCH = arm
	STATIC_LINKING = 1

# CTR(3DS)
else ifeq ($(platform), ctr)
	TARGET := $(TARGET_NAME)_libretro_ctr.a
	CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
	CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
	AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
	CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET -DTHREAD_ENABLED -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
	CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
	CFLAGS += -Wall -mword-relocations
	CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
	CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
	CFLAGS += -Werror=implicit-function-declaration

	OBJS += frontend/3ds/utils.o

#	CFLAGS += -DPCSX
	BUILTIN_GPU = unai
	THREAD_RENDERING = 1
	DYNAREC = ari64
	DRC_CACHE_BASE = 0
	ARCH = arm
	HAVE_NEON = 0
	STATIC_LINKING = 1

# Xbox 360
else ifeq ($(platform), xenon)
	TARGET := $(TARGET_NAME)_libretro_xenon360.a
	CC = xenon-gcc$(EXE_EXT)
	AR = xenon-ar$(EXE_EXT)
	CFLAGS += -D__LIBXENON__ -m32 -D__ppc__

# Nintendo Game Cube
else ifeq ($(platform), ngc)
	TARGET := $(TARGET_NAME)_libretro_ngc.a
	CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
	AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
	CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__

# Nintendo Wii
else ifeq ($(platform), wii)
	TARGET := libretro_$(TARGET_NAME)_wii.a
	CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
	AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
	CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__

# QNX
else ifeq ($(platform), qnx)
	TARGET := $(TARGET_NAME)_libretro_qnx.so
	fpic := -fPIC
	CC = qcc -Vgcc_ntoarmv7le
	CC_AS = $(CC)
	HAVE_NEON = 1
	DYNAREC = ari64
	DRC_CACHE_BASE = 0
	BUILTIN_GPU = neon
	ARCH = arm
	CFLAGS += -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
	ASFLAGS += -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
	MAIN_LDLIBS += -lsocket
	LIBPTHREAD :=
	LIBDL :=
	LIBM :=

#Raspberry Pi 2
else ifeq ($(platform), rpi2)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
	ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
	HAVE_NEON = 1
	ARCH = arm
	BUILTIN_GPU = neon
	DYNAREC = ari64

#Raspberry Pi 3
else ifeq ($(platform), rpi3)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
	ASFLAGS += -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
	HAVE_NEON = 1
	ARCH = arm
	BUILTIN_GPU = neon
	DYNAREC = ari64

#Raspberry Pi 4 with a 32bit GNU/Linux OS
else ifeq ($(platform), rpi4)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	CFLAGS += -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
	ASFLAGS += -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
	HAVE_NEON = 1
	ARCH = arm
	BUILTIN_GPU = neon
	DYNAREC = ari64

#Raspberry Pi 4 with a 64bit GNU/Linux OS
else ifeq ($(platform), rpi4_64)
        TARGET := $(TARGET_NAME)_libretro.so
        ARCH := arm64
        BUILTIN_GPU = unai
        DYNAREC = lightrec
        fpic := -fPIC
        CFLAGS += -march=armv8-a+crc+simd -mtune=cortex-a72 -ftree-vectorize

# Classic Platforms ####################
# Platform affix = classic_<ISA>_<µARCH>
# Help at https://modmyclassic.com/comp

# (armv7 a7, hard point, neon based) ### 
# NESC, SNESC, C64 mini 
else ifeq ($(platform), classic_armv7_a7)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	CFLAGS += -Ofast \
	-flto=4 -fwhole-program -fuse-linker-plugin \
	-fdata-sections -ffunction-sections -Wl,--gc-sections \
	-fno-stack-protector -fno-ident -fomit-frame-pointer \
	-falign-functions=1 -falign-jumps=1 -falign-loops=1 \
	-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
	-fmerge-all-constants -fno-math-errno \
	-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
	CXXFLAGS += $(CFLAGS)
	CPPFLAGS += $(CFLAGS)
	ASFLAGS += $(CFLAGS)
	HAVE_NEON = 1
	ARCH = arm
	BUILTIN_GPU = neon
	DYNAREC = ari64
	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
		CFLAGS += -march=armv7-a
	else
		CFLAGS += -march=armv7ve
		# If gcc is 5.0 or later
		ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
			LDFLAGS += -static-libgcc -static-libstdc++
		endif
	endif

# (armv8 a35, hard point, neon based) ###
# PlayStation Classic
else ifeq ($(platform), classic_armv8_a35)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	CFLAGS += -Ofast \
	-fmerge-all-constants -fno-math-errno -march=armv8-a \
	-marm -mcpu=cortex-a35 -mtune=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
	HAVE_NEON = 1
	ARCH = arm
	BUILTIN_GPU = neon
	DYNAREC = ari64
	LDFLAGS += -static-libgcc -static-libstdc++ -fPIC

#######################################

# ARM
else ifneq (,$(findstring armv,$(platform)))
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	HAVE_NEON = 0
	DRC_CACHE_BASE = 0
	BUILTIN_GPU = peops
	ifneq (,$(findstring cortexa8,$(platform)))
		CFLAGS += -marm -mcpu=cortex-a8
		ASFLAGS += -mcpu=cortex-a8
	else ifneq (,$(findstring cortexa7,$(platform)))
		CFLAGS += -marm -mcpu=cortex-a7
		ASFLAGS += -mcpu=cortex-a7
		LIBZ :=
	else ifneq (,$(findstring cortexa9,$(platform)))
		CFLAGS += -marm -mcpu=cortex-a9
		ASFLAGS += -mcpu=cortex-a9
	endif
	CFLAGS += -marm
	ifneq (,$(findstring neon,$(platform)))
		CFLAGS += -mfpu=neon
		ASFLAGS += -mfpu=neon
		HAVE_NEON = 1
		BUILTIN_GPU = neon
	endif
	ifneq (,$(findstring softfloat,$(platform)))
		CFLAGS += -mfloat-abi=softfp
		ASFLAGS += -mfloat-abi=softfp
	else ifneq (,$(findstring hardfloat,$(platform)))
		CFLAGS += -mfloat-abi=hard
		ASFLAGS += -mfloat-abi=hard
	endif
	ARCH = arm
	DYNAREC = ari64

# Emscripten
else ifeq ($(platform), emscripten)
   TARGET  := $(TARGET_NAME)_libretro_$(platform).bc
   fpic    := -fPIC
   SHARED  := -shared -Wl,--no-undefined -Wl,--version-script=link.T
   CFLAGS += -DNO_DYLIB -DNO_SOCKET
   STATIC_LINKING = 1

# Windows
else
	TARGET := $(TARGET_NAME)_libretro.dll
	BUILTIN_GPU = peops
	PLATFORM = libretro
	MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
	CFLAGS += -D__WIN32__ -DNO_DYLIB
	MMAP_WIN32=1
	MAIN_LDLIBS += -lws2_32
	LIBPTHREAD :=
	LIBDL :=
	LIBM :=
endif

CFLAGS += $(fpic)
MAIN_LDFLAGS += -shared
MAIN_LDLIBS += $(LIBPTHREAD) $(LIBM) $(LIBDL) $(LIBZ)

# enable large file support if available
ifeq ($(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h | grep __SIZEOF_LONG__ | awk '{print $$3}'),4)
CFLAGS += -D_FILE_OFFSET_BITS=64
endif

# try to autodetect stuff for the lazy
ifndef ARCH
ARCH = $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
endif
ifndef HAVE_NEON
HAVE_NEON = $(shell $(CC) -E -dD - < /dev/null 2> /dev/null | grep -q __ARM_NEON__ && echo 1 || echo 0)
endif
ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
MAIN_LDFLAGS += -Wl,--no-undefined
endif

TARGET ?= libretro.so
PLATFORM = libretro
BUILTIN_GPU ?= peops
SOUND_DRIVERS = libretro
PLUGINS =
NO_CONFIG_MAK = yes

# what does this do
#libretro_all: all
#ifeq ($(platform),ios)
#ifeq ($(DYNAREC),1)
#	make -f Makefile.libretro DYNAREC=0 platform=$(platform) clean
#	make -f Makefile.libretro DYNAREC=0 platform=$(platform)
#endif
#endif

include Makefile

# no special AS needed for gpu_neon
plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.o: plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.S
	$(CC) $(CFLAGS) -c $^ -o $@