Makefile 31.8 KB
Newer Older
Libretro-Admin's avatar
Libretro-Admin committed
1
DEBUG         := 0
2
3
DEBUG_ASAN    := 0
DEBUG_UBSAN   := 0
Libretro-Admin's avatar
Libretro-Admin committed
4
5
NO_REND       := 0
HAVE_GL       := 1
6
HAVE_GL2      := 0
Libretro-Admin's avatar
Libretro-Admin committed
7
HAVE_OIT      ?= 0
Flyinghead's avatar
Flyinghead committed
8
HAVE_VULKAN   := 0
Libretro-Admin's avatar
Libretro-Admin committed
9
HAVE_CORE     := 0
Libretro-Admin's avatar
Libretro-Admin committed
10
NO_THREADS    := 0
Libretro-Admin's avatar
Libretro-Admin committed
11
NO_EXCEPTIONS := 0
Libretro-Admin's avatar
Typo    
Libretro-Admin committed
12
NO_NVMEM      := 0
13
NO_VERIFY     := 1
14
HAVE_LTCG     ?= 0
15
HAVE_GENERIC_JIT := 1
16
HAVE_GL3      := 0
Libretro-Admin's avatar
Libretro-Admin committed
17
FORCE_GLES    := 0
18
STATIC_LINKING:= 0
19
HAVE_TEXUPSCALE := 1
Libretro-Admin's avatar
Libretro-Admin committed
20
HAVE_OPENMP   := 1
21
HAVE_CHD      := 1
Gino Badouri's avatar
Gino Badouri committed
22
HAVE_CLANG    ?= 0
23
HAVE_CDROM    := 0
Libretro-Admin's avatar
Libretro-Admin committed
24
ENABLE_MODEM  := 1
Libretro-Admin's avatar
Libretro-Admin committed
25

26
TARGET_NAME   := flycast
Libretro-Admin's avatar
Update    
Libretro-Admin committed
27

MastaG's avatar
MastaG committed
28
29
30
31
32
ifeq ($(HAVE_CLANG),1)
	CXX      = ${CC_PREFIX}clang++
	CC       = ${CC_PREFIX}clang
	SHARED   := -fuse-ld=lld
else
Steel01's avatar
Steel01 committed
33
34
	CXX      ?= ${CC_PREFIX}g++
	CC       ?= ${CC_PREFIX}gcc
MastaG's avatar
MastaG committed
35
36
	SHARED   :=
endif
Gino Badouri's avatar
Gino Badouri committed
37
38
39
40
ifeq ($(HAVE_LTCG),1)
	SHARED   += -flto
endif

41
42
43
ifneq (${AS},)
	CC_AS := ${AS}
endif
Steel01's avatar
Steel01 committed
44
CC_AS    ?= ${CC_PREFIX}as
45

Libretro-Admin's avatar
Updates    
Libretro-Admin committed
46
47
48
MFLAGS   := 
ASFLAGS  := 
LDFLAGS  :=
49
LDFLAGS_END :=
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
50
INCFLAGS :=
Libretro-Admin's avatar
Libretro-Admin committed
51
52
LIBS     :=
CFLAGS   := 
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
53
54
CXXFLAGS :=

David Walters's avatar
David Walters committed
55
56
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
orbea's avatar
orbea committed
57
	CXXFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
David Walters's avatar
David Walters committed
58
59
endif

Libretro-Admin's avatar
Libretro-Admin committed
60
61
62
63
64
65
66
67
UNAME=$(shell uname -a)

LIBRETRO_DIR := .

# Cross compile ?

ifeq (,$(ARCH))
	ARCH = $(shell uname -m)
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
68
69
endif

Libretro-Admin's avatar
Libretro-Admin committed
70
71
# Target Dynarec
WITH_DYNAREC = $(ARCH)
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
72

Libretro-Admin's avatar
Libretro-Admin committed
73
74
ifeq ($(ARCH), $(filter $(ARCH), i386 i686))
	WITH_DYNAREC = x86
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
75
76
endif

Libretro-Admin's avatar
Libretro-Admin committed
77
78
ifeq ($(platform),)
	platform = unix
gizmo98's avatar
gizmo98 committed
79
80
81
82
83
84
85
86
87
	ifeq ($(UNAME),)
		platform = win
	else ifneq ($(findstring MINGW,$(UNAME)),)
		platform = win
	else ifneq ($(findstring Darwin,$(UNAME)),)
		platform = osx
	else ifneq ($(findstring win,$(UNAME)),)
		platform = win
	endif
Libretro-Admin's avatar
Libretro-Admin committed
88
89
90
91
92
93
94
95
96
97
endif

# system platform
system_platform = unix
ifeq ($(shell uname -a),)
	EXE_EXT = .exe
	system_platform = win
else ifneq ($(findstring Darwin,$(shell uname -a)),)
	system_platform = osx
	arch = intel
gizmo98's avatar
gizmo98 committed
98
99
100
	ifeq ($(shell uname -p),powerpc)
		arch = ppc
	endif
Libretro-Admin's avatar
Libretro-Admin committed
101
102
103
104
else ifneq ($(findstring MINGW,$(shell uname -a)),)
	system_platform = win
endif

Libretro-Admin's avatar
Libretro-Admin committed
105
CORE_DIR := .
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
106
107

DYNAREC_USED = 0
108
CORE_DEFINES   := -D__LIBRETRO__  -DHAVE_GLSYM_PRIVATE
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
109

110
ifeq ($(NO_VERIFY),1)
orbea's avatar
orbea committed
111
	CORE_DEFINES += -DNO_VERIFY
112
113
endif

Libretro-Admin's avatar
Libretro-Admin committed
114
DC_PLATFORM=dreamcast
Libretro-Admin's avatar
Libretro-Admin committed
115

Libretro-Admin's avatar
Libretro-Admin committed
116
117
118
119
HOST_CPU_X86=0x20000001
HOST_CPU_ARM=0x20000002
HOST_CPU_MIPS=0x20000003
HOST_CPU_X64=0x20000004
120
HOST_CPU_ARM64=0x20000006
Libretro-Admin's avatar
Libretro-Admin committed
121

122
ifeq ($(STATIC_LINKING),1)
orbea's avatar
orbea committed
123
	EXT=a
124
endif
Libretro-Admin's avatar
Libretro-Admin committed
125
126
127

# Unix
ifneq (,$(findstring unix,$(platform)))
128
	EXT    ?= so
orbea's avatar
orbea committed
129
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
130
	SHARED += -shared -Wl,--version-script=link.T
131
	LDFLAGS +=  -Wl,--no-undefined
orbea's avatar
orbea committed
132
	ifneq (,$(findstring Haiku,$(shell uname -s)))
Benjamin FRANCOIS's avatar
Benjamin FRANCOIS committed
133
		LIBS += -lroot -lnetwork
orbea's avatar
orbea committed
134
135
	else
		LIBS += -lrt
kwyxz's avatar
kwyxz committed
136
		HAVE_VULKAN = 1
orbea's avatar
orbea committed
137
138
	endif

139
140
141
142
	ifneq ($(HAVE_GL2), 1)
		ifneq ($(HAVE_OIT), 1)
			HAVE_GL3 = 1
		endif
orbea's avatar
orbea committed
143
144
	endif

145
	HAVE_CDROM = 1
Libretro-Admin's avatar
Libretro-Admin committed
146
147
	fpic = -fPIC

gizmo98's avatar
gizmo98 committed
148
	ifeq ($(WITH_DYNAREC), $(filter $(WITH_DYNAREC), x86_64 x64))
Flyinghead's avatar
Flyinghead committed
149
		CFLAGS += -DTARGET_LINUX_x64
Libretro-Admin's avatar
Libretro-Admin committed
150
		SINGLE_PREC_FLAGS=1
151
		HAVE_GENERIC_JIT = 0
gizmo98's avatar
gizmo98 committed
152
	else ifeq ($(WITH_DYNAREC), x86)
Flyinghead's avatar
Flyinghead committed
153
		CFLAGS += -m32 -D TARGET_LINUX_x86 -D TARGET_NO_AREC
Libretro-Admin's avatar
Libretro-Admin committed
154
155
		SINGLE_PREC_FLAGS=1
		MFLAGS += -m32
156
157
		ASFLAGS += --32
		LDFLAGS += -m32
158
		HAVE_GENERIC_JIT = 0
gizmo98's avatar
gizmo98 committed
159
	endif
Libretro-Admin's avatar
Libretro-Admin committed
160
161
162
163
	PLATFORM_EXT := unix

# Raspberry Pi
else ifneq (,$(findstring rpi,$(platform)))
164
165
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
166
	SHARED += -shared -Wl,--version-script=link.T
Libretro-Admin's avatar
Libretro-Admin committed
167
	fpic = -fPIC
168
	LIBS += -lrt
169
170
	ARM_FLOAT_ABI_HARD = 1
	SINGLE_PREC_FLAGS = 1
171
172
173
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm
	HAVE_GENERIC_JIT = 0
174
	
175
	ifneq (,$(findstring rpi4,$(platform)))
gizmo98's avatar
gizmo98 committed
176
		FORCE_GLES = 1
177
178
179
		ifneq (,$(findstring rpi4_64,$(platform)))
			# 64-bit userspace
			ARM_FLOAT_ABI_HARD = 0
180
			CPUFLAGS += -DTARGET_LINUX_ARMv8 -frename-registers
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
			CFLAGS += -march=armv8-a+crc -mcpu=cortex-a72 -mtune=cortex-a72 $(CPUFLAGS)
			CXXFLAGS += -march=armv8-a+crc -mcpu=cortex-a72 -mtune=cortex-a72 $(CPUFLAGS)
			ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
			WITH_DYNAREC=arm64
		else
			# rpi4 flags are taken from rockpro64
			CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
			# as of 2020-05-07, the following workaround doesn't seem required
			# CORE_DEFINES += -DRPI4_SET_UNIFORM_ATTRIBUTES_BUG
			CFLAGS += -marm -mfloat-abi=hard -mcpu=cortex-a72 -mtune=cortex-a72 -mfpu=neon-vfpv4 $(CPUFLAGS)
			CXXFLAGS += -marm -mfloat-abi=hard -mcpu=cortex-a72 -mtune=cortex-a72 -mfpu=neon-vfpv4 $(CPUFLAGS)
			ifeq ($(HAVE_CLANG),0)
				CFLAGS += -mvectorize-with-neon-quad
				CXXFLAGS += -mvectorize-with-neon-quad
			endif
			ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
		endif
Juliano Dorigão's avatar
Juliano Dorigão committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
	else ifneq (,$(findstring rpi3,$(platform)))
			FORCE_GLES = 1
			ifneq (,$(findstring rpi3_64,$(platform)))
				# 64-bit userspace
				ARM_FLOAT_ABI_HARD = 0
				CPUFLAGS += -DTARGET_LINUX_ARMv8 -frename-registers
				CFLAGS += -march=armv8-a+crc -mcpu=cortex-a53 -mtune=cortex-a53 $(CPUFLAGS)
				CXXFLAGS += -march=armv8-a+crc -mcpu=cortex-a53 -mtune=cortex-a53 $(CPUFLAGS)
				ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
				WITH_DYNAREC=arm64
			else
				CFLAGS += -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
				CXXFLAGS += -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
			endif
212
213
214
215
216
217
218
219
220
221
222
223
224
225
	else
		ifeq (,$(findstring mesa,$(platform)))
			GLES = 1
			GL_LIB := -L/opt/vc/lib -lbrcmGLESv2
			INCFLAGS += -I/opt/vc/include
			CFLAGS += -DTARGET_NO_STENCIL
		else
			FORCE_GLES = 1
		endif
		ifneq (,$(findstring rpi2,$(platform)))
			CFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
			CXXFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
		endif
		CORE_DEFINES += -DLOW_END
gizmo98's avatar
gizmo98 committed
226
	endif
Libretro-Admin's avatar
Libretro-Admin committed
227

228
# Classic Platforms #####################
CompCom's avatar
CompCom committed
229
# Platform affix = classic_<ISA>_<µARCH>
230
231
#########################################
# (armv7 a7, hard point, neon based) ####
CompCom's avatar
CompCom committed
232
233
234
235
# NESC, SNESC, C64 mini 
else ifeq ($(platform), classic_armv7_a7)
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
236
	SHARED += -shared -Wl,--version-script=link.T
CompCom's avatar
CompCom committed
237
238
239
240
241
242
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	HAVE_LTCG = 0
liberodark's avatar
liberodark committed
243
	HAVE_OPENMP = 1
CompCom's avatar
CompCom committed
244
	CFLAGS += -Ofast \
CompCom's avatar
CompCom committed
245
	-flto=4 -fwhole-program -fuse-linker-plugin \
CompCom's avatar
CompCom committed
246
247
248
249
250
251
252
253
	-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)
	ASFLAGS += $(CFLAGS)
CompCom's avatar
CompCom committed
254
	LDFLAGS += -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
CompCom's avatar
CompCom committed
255
256
	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
		CFLAGS += -march=armv7-a
CompCom's avatar
CompCom committed
257
		LDFLAGS += -march=armv7-a
CompCom's avatar
CompCom committed
258
259
	else
		CFLAGS += -march=armv7ve
CompCom's avatar
CompCom committed
260
		LDFLAGS += -march=armv7ve
CompCom's avatar
CompCom committed
261
262
263
264
265
266
		# If gcc is 5.0 or later
		ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
			LDFLAGS += -static-libgcc -static-libstdc++
		endif
	endif
	PLATFORM_EXT := unix
Ryan 'Swingflip' Hamlin's avatar
Ryan 'Swingflip' Hamlin committed
267
	WITH_DYNAREC = arm
268
	HAVE_GENERIC_JIT = 0
269
	CORE_DEFINES += -DLOW_END -DLOW_RES
270
271
272
273
274
275
#########################################
# (armv8 a35, hard point, neon based) ###
# PlayStation Classic
else ifeq ($(platform), classic_armv8_a35)
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
276
	SHARED += -shared -Wl,--version-script=link.T
277
278
279
280
281
282
283
284
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	HAVE_LTCG = 0
	HAVE_OPENMP = 0
	CFLAGS += -Ofast \
Flyinghead's avatar
Flyinghead committed
285
	-fuse-linker-plugin \
286
	-fno-stack-protector -fno-ident -fomit-frame-pointer \
Wes Smith's avatar
Wes Smith committed
287
288
	-fmerge-all-constants -ffast-math -funroll-all-loops \
	-marm -mcpu=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
289
290
	CXXFLAGS += $(CFLAGS)
	ASFLAGS += $(CFLAGS)
Wes Smith's avatar
Wes Smith committed
291
	LDFLAGS += -marm -mcpu=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard -Ofast -flto -fuse-linker-plugin
292
293
294
	PLATFORM_EXT := unix
	WITH_DYNAREC = arm
	HAVE_GENERIC_JIT = 0
295
	CORE_DEFINES += -DLOW_END -DLOW_RES
microplay's avatar
microplay committed
296
	
297
#########################################
CompCom's avatar
CompCom committed
298

microplay's avatar
microplay committed
299
300
301
302
# sun8i Allwinner H2+ / H3 for mainline Builds
# like Orange PI, Nano PI, Banana PI, Tritium, Sunvell R69, AlphaCore2
# by MPCORE-HUB/Liontek1985

Fredy's avatar
Fredy committed
303
else ifeq ($(platform), sun8i)
microplay's avatar
microplay committed
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
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
	CFLAGS += -marm -mfloat-abi=hard -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard $(CPUFLAGS)
	CXXFLAGS += -marm -mfloat-abi=hard -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard $(CPUFLAGS)
	ifeq ($(HAVE_CLANG),0)
		CFLAGS += -mvectorize-with-neon-quad
		CXXFLAGS += -mvectorize-with-neon-quad
	endif
	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
		CFLAGS += -march=armv7-a
		CXXFLAGS += -march=armv7-a
	else
		CFLAGS += -march=armv7ve
		CXXFLAGS += -march=armv7ve
		# If gcc is 5.0 or later
		ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
			CXXFLAGS += -static-libgcc -static-libstdc++
		endif
	endif
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm
	HAVE_GENERIC_JIT = 0
	CORE_DEFINES += -DLOW_END
	
#########################################

# sun8i Allwinner H2+ / H3 for Legacy Builds
# like Orange PI, Nano PI, Banana PI, Tritium, Sunvell R69, AlphaCore2
# by MPCORE-HUB/Liontek1985

else ifeq ($(platform), sun8i_legacy)
Fredy's avatar
Fredy committed
343
344
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
345
	SHARED += -shared -Wl,--version-script=link.T
Fredy's avatar
Fredy committed
346
347
348
349
350
351
352
353
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	HAVE_LTCG = 0
	HAVE_OPENMP = 0
	CFLAGS += -Ofast \
microplay's avatar
microplay committed
354
	-flto -fuse-linker-plugin \
Fredy's avatar
Fredy committed
355
	-fno-stack-protector -fno-ident -fomit-frame-pointer \
microplay's avatar
microplay committed
356
	-fmerge-all-constants -ffast-math -funroll-all-loops \
Fredy's avatar
Fredy committed
357
358
359
	-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
	CXXFLAGS += $(CFLAGS)
	ASFLAGS += $(CFLAGS)
microplay's avatar
microplay committed
360
	LDFLAGS += -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -Ofast -flto -fuse-linker-plugin
Fredy's avatar
Fredy committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
		CFLAGS += -march=armv7-a
		LDFLAGS += -march=armv7-a
	else
		CFLAGS += -march=armv7ve
		LDFLAGS += -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
	PLATFORM_EXT := unix
	WITH_DYNAREC = arm
	HAVE_GENERIC_JIT = 0
Fredy's avatar
Fredy committed
375
	CORE_DEFINES += -DLOW_END
microplay's avatar
microplay committed
376
	
Fredy's avatar
Fredy committed
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
# Generic AArch64 Cortex-A53 OpenGL ES 2.0 target
else ifeq ($(platform), arm64_cortex_a53_gles2)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	LDFLAGS +=  -Wl,--no-undefined
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 0
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	CPUFLAGS += -DHOST_CPU=0x20000006 -DTARGET_LINUX_ARMv8 -frename-registers
	CFLAGS += -mcpu=cortex-a53 -mtune=cortex-a53 $(CPUFLAGS)
	CXXFLAGS += -mcpu=cortex-a53 -mtune=cortex-a53 $(CPUFLAGS)
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
	HAVE_VULKAN = 0
	HAVE_LTCG = 0
	CORE_DEFINES += -DLOW_END

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

# ARM64 SM1 Odroid C4
else ifeq ($(platform), odroidc4)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	LDFLAGS +=  -Wl,--no-undefined
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 0
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	CPUFLAGS += -DHOST_CPU=0x20000006 -DTARGET_LINUX_ARMv8 -frename-registers
	CFLAGS += -mcpu=cortex-a55 -mtune=cortex-a55 $(CPUFLAGS)
	CXXFLAGS += -mcpu=cortex-a55 -mtune=cortex-a55 $(CPUFLAGS)
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
	HAVE_VULKAN = 0
	HAVE_LTCG = 0

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

426
427
428
429
430
431
432
433
434
435
436
# ARM64 (switch-lakka)
else ifeq ($(platform), arm64)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	LDFLAGS +=  -Wl,--no-undefined
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 0
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
437
	CPUFLAGS += -DTARGET_LINUX_ARMv8 -frename-registers
438
439
440
441
442
443
444
445
446
447
448
449
	CFLAGS += $(CPUFLAGS)
	CXXFLAGS += $(CPUFLAGS)
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
	HAVE_LTCG = 0
	LDFLAGS := $(filter-out -flto, $(LDFLAGS))
	CFLAGS := $(filter-out -flto, $(CFLAGS))
	CXXFLAGS := $(filter-out -flto, $(CXXFLAGS))
#######################################

450
451
452
453
454
455
456
457
458
459
# nvidia developer jetson nano kit (jetson-nano)
else ifeq ($(platform), jetson-nano)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	LDFLAGS +=  -Wl,--no-undefined
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 0
	SINGLE_PREC_FLAGS = 1
460
	CPUFLAGS += -DTARGET_LINUX_ARMv8 -frename-registers
461
462
	CFLAGS += -march=armv8-a+crc -mtune=cortex-a57 -mcpu=cortex-a57+crc+fp+simd $(CPUFLAGS)
	CXXFLAGS += -march=armv8-a+crc -mtune=cortex-a57 -mcpu=cortex-a57+crc+fp+simd $(CPUFLAGS)
463
464
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
465
	ARCH=arm
466
467
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
468
	HAVE_VULKAN = 1
469
470
471
472
	HAVE_LTCG = 0
	LDFLAGS := $(filter-out -flto, $(LDFLAGS))
	CFLAGS := $(filter-out -flto, $(CFLAGS))
	CXXFLAGS := $(filter-out -flto, $(CXXFLAGS))
m4xw's avatar
m4xw committed
473
474
475
476
477
478

# Nintendo Switch (Libnx)
else ifeq ($(platform), libnx)
   include $(DEVKITPRO)/libnx/switch_rules
   CC_AS = aarch64-none-elf-as
   TARGET := $(TARGET_NAME)_libretro_$(platform).a
slash0042's avatar
slash0042 committed
479
   DEFINES := -DSWITCH=1 -D__SWITCH__=1 -fcommon -DHAVE_LIBNX=1 -DTARGET_LIBNX -DTARGET_NO_OPENMP -DFEAT_NO_RWX_PAGES
m4xw's avatar
m4xw committed
480
481
   CFLAGS := $(DEFINES) -fPIE -I$(LIBNX)/include/ -I$(PORTLIBS)/include/ -isystem$(CORE_DIR)/core/deps/switch/ -ffunction-sections -fdata-sections -ftls-model=local-exec
   CPUFLAGS += -march=armv8-a -mtune=cortex-a57 -mtp=soft -mcpu=cortex-a57+crc+fp+simd -ffast-math -frename-registers -funroll-loops -ftree-vectorize
482
   CFLAGS += $(CPUFLAGS) -DTARGET_LIBNX -DTARGET_NO_AREC
m4xw's avatar
m4xw committed
483
484
485
   WITH_DYNAREC=arm64
   HAVE_GENERIC_JIT = 0
   STATIC_LINKING = 1
486
   ENABLE_MODEM = 0
m4xw's avatar
m4xw committed
487
488
489
490
   HAVE_LTCG = 0
   NO_NVMEM = 1
   # stubs
   SOURCES_C += $(CORE_DIR)/core/deps/switch/stubs.c
491
492
#######################################

6alileo's avatar
6alileo committed
493
494
495
496
# Odroid-N2
else ifeq ($(platform), odroid-n2)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
497
	SHARED += -shared -Wl,--version-script=link.T
6alileo's avatar
6alileo committed
498
	LDFLAGS +=  -Wl,--no-undefined
6alileo's avatar
6alileo committed
499
500
	fpic = -fPIC
	LIBS += -lrt
6alileo's avatar
6alileo committed
501
	ARM_FLOAT_ABI_HARD = 0
6alileo's avatar
6alileo committed
502
503
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
504
	CPUFLAGS += -DTARGET_LINUX_ARMv8 -frename-registers
6alileo's avatar
6alileo committed
505
506
	CFLAGS += -mcpu=cortex-a73 -mtune=cortex-a73.cortex-a53 $(CPUFLAGS)
	CXXFLAGS += -mcpu=cortex-a73 -mtune=cortex-a73.cortex-a53 $(CPUFLAGS)
6alileo's avatar
6alileo committed
507
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
slaminger's avatar
slaminger committed
508
509
510
511
512
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
	HAVE_LTCG = 0
	
slaminger's avatar
slaminger committed
513
	# Libre Computer La Frite
slaminger's avatar
slaminger committed
514
515
516
517
518
519
520
521
522
523
else ifeq ($(platform), mali-drm-gles2)
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -shared -Wl,--version-script=link.T
	LDFLAGS +=  -Wl,--no-undefined
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 0
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
slaminger's avatar
slaminger committed
524
	CPUFLAGS += -march=armv8-a
slaminger's avatar
slaminger committed
525
	CFLAGS += -mtune=cortex-a53 $(CPUFLAGS)
6alileo's avatar
6alileo committed
526
527
528
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm64
	HAVE_GENERIC_JIT = 0
6alileo's avatar
6alileo committed
529
	HAVE_LTCG = 0
6alileo's avatar
6alileo committed
530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# Amlogic S905/S905X/S912 (AMLGXBB/AMLGXL/AMLGXM) e.g. Khadas VIM1/2 / S905X2 (AMLG12A) & S922X/A311D (AMLG12B) e.g. Khadas VIM3 - 32-bit userspace
else ifneq (,$(findstring AMLG,$(platform)))
  EXT ?= so
  TARGET := $(TARGET_NAME)_libretro.$(EXT)
  SHARED += -shared -Wl,--version-script=link.T
  LDFLAGS +=  -Wl,--no-undefined
  fpic = -fPIC
  LIBS += -lrt
  ARM_FLOAT_ABI_HARD = 1
  FORCE_GLES = 1
  SINGLE_PREC_FLAGS = 1

  CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
  CFLAGS += -march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 $(CPUFLAGS)
  CXXFLAGS += -march=armv8-a+crc -mfloat-abi=hard -mfpu=neon-fp-armv8 $(CPUFLAGS)

  ifneq (,$(findstring AMLG12,$(platform)))
    ifneq (,$(findstring AMLG12B,$(platform)))
      CFLAGS += -mtune=cortex-a73.cortex-a53
      CXXFLAGS += -mtune=cortex-a73.cortex-a53
    else
      CFLAGS += -mtune=cortex-a53
      CXXFLAGS += -mtune=cortex-a53
    endif
  else ifneq (,$(findstring AMLGX,$(platform)))
    CFLAGS += -mtune=cortex-a53
    CXXFLAGS += -mtune=cortex-a53
    CORE_DEFINES += -DLOW_END
  endif

  ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize

  PLATFORM_EXT := unix
  WITH_DYNAREC=arm
  HAVE_GENERIC_JIT = 0

# Rockchip RK3288 e.g. Asus Tinker Board / RK3328 e.g. PINE64 Rock64 / RK3399 e.g. PINE64 RockPro64 - 32-bit userspace
else ifneq (,$(findstring RK,$(platform)))
  EXT ?= so
  TARGET := $(TARGET_NAME)_libretro.$(EXT)
  SHARED += -shared -Wl,--version-script=link.T
  fpic = -fPIC
  LIBS += -lrt
  ARM_FLOAT_ABI_HARD = 1
  FORCE_GLES = 1
  SINGLE_PREC_FLAGS = 1
  CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
578
  HAVE_LTCG = 0
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609

  ifneq (,$(findstring RK33,$(platform)))
    CFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8
    CXXFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8

    ifneq (,$(findstring RK3399,$(platform)))
      CFLAGS += -mtune=cortex-a72.cortex-a53
      CXXFLAGS += -mtune=cortex-a72.cortex-a53
    else ifneq (,$(findstring RK3328,$(platform)))
      CFLAGS += -mtune=cortex-a53
      CXXFLAGS += -mtune=cortex-a53
      CORE_DEFINES += -DLOW_END
    endif

    ifeq ($(HAVE_CLANG),0)
      CFLAGS += -mvectorize-with-neon-quad
      CXXFLAGS += -mvectorize-with-neon-quad
    endif
  else ifneq (,$(findstring RK3288,$(platform)))
    CFLAGS += -march=armv7ve -mtune=cortex-a17 -mfpu=neon-vfpv4
    CXXFLAGS += -march=armv7ve -mtune=cortex-a17 -mfpu=neon-vfpv4
  endif

  CFLAGS += -mfloat-abi=hard $(CPUFLAGS)
  CXXFLAGS += -mfloat-abi=hard $(CPUFLAGS)

  ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
  PLATFORM_EXT := unix
  WITH_DYNAREC=arm
  HAVE_GENERIC_JIT = 0

6alileo's avatar
6alileo committed
610
611
# RockPro64
else ifeq ($(platform), rockpro64)
6alileo's avatar
6alileo committed
612
613
	EXT ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
614
	SHARED += -shared -Wl,--version-script=link.T
6alileo's avatar
6alileo committed
615
616
617
618
619
620
	fpic = -fPIC
	LIBS += -lrt
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
	CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
MastaG's avatar
MastaG committed
621
622
623
624
625
626
	CFLAGS += -marm -mfloat-abi=hard -mcpu=cortex-a72 -mtune=cortex-a72.cortex-a53 -mfpu=neon-fp-armv8 $(CPUFLAGS)
	CXXFLAGS += -marm -mfloat-abi=hard -mcpu=cortex-a72 -mtune=cortex-a72.cortex-a53 -mfpu=neon-fp-armv8 $(CPUFLAGS)
	ifeq ($(HAVE_CLANG),0)
		CFLAGS += -mvectorize-with-neon-quad
		CXXFLAGS += -mvectorize-with-neon-quad
	endif
6alileo's avatar
6alileo committed
627
628
629
	ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm
630
	HAVE_GENERIC_JIT = 0
Flyinghead's avatar
Flyinghead committed
631
	HAVE_LTCG = 0
6alileo's avatar
6alileo committed
632

Steven Drinkwater's avatar
Steven Drinkwater committed
633
634
635
636
# Tinkerboard
else ifeq ($(platform), tinkerboard)
    EXT ?= so
    TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
637
    SHARED += -shared -Wl,--version-script=link.T
Steven Drinkwater's avatar
Steven Drinkwater committed
638
639
640
641
642
643
644
645
646
647
648
649
650
    fpic = -fPIC
    LIBS += -lrt
    ARM_FLOAT_ABI_HARD = 1
    FORCE_GLES = 1
    SINGLE_PREC_FLAGS = 1
    CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
    CFLAGS += -marm -mfpu=neon-vfpv4 -mtune=cortex-a17 -mfloat-abi=hard $(CPUFLAGS)
    CXXFLAGS += -marm -mfpu=neon-vfpv4 -mtune=cortex-a17 -mfloat-abi=hard $(CPUFLAGS)
    ASFLAGS += $(CFLAGS) -c -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
    PLATFORM_EXT := unix
    WITH_DYNAREC=arm
    HAVE_GENERIC_JIT = 0
		
Libretro-Admin's avatar
Libretro-Admin committed
651
652
# ODROIDs
else ifneq (,$(findstring odroid,$(platform)))
653
654
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
Gino Badouri's avatar
Gino Badouri committed
655
	BOARD ?= $(shell cat /proc/cpuinfo | grep -i odroid | awk '{print $$3}')
MastaG's avatar
MastaG committed
656
	SHARED += -shared -Wl,--version-script=link.T
Libretro-Admin's avatar
Libretro-Admin committed
657
	fpic = -fPIC
658
	LIBS += -lrt
gizmo98's avatar
gizmo98 committed
659
660
661
	ARM_FLOAT_ABI_HARD = 1
	FORCE_GLES = 1
	SINGLE_PREC_FLAGS = 1
662
	HAVE_LTCG = 0
gizmo98's avatar
gizmo98 committed
663

MastaG's avatar
MastaG committed
664
665
666
	CPUFLAGS += -DNO_ASM -DARM_ASM -frename-registers -ftree-vectorize
	CFLAGS += -marm -mfloat-abi=hard $(CPUFLAGS)
	CXXFLAGS += -marm -mfloat-abi=hard $(CPUFLAGS)
667

Libretro-Admin's avatar
Libretro-Admin committed
668
669
	ifneq (,$(findstring ODROIDC,$(BOARD)))
		# ODROID-C1
MastaG's avatar
MastaG committed
670
671
672
		MFLAGS += -mcpu=cortex-a5
	else ifneq (,$(findstring ODROID-XU,$(BOARD)))
		# ODROID-XU3, XU4  & XU3 Lite
MastaG's avatar
MastaG committed
673
		ifeq ($(HAVE_CLANG),1)
MastaG's avatar
MastaG committed
674
			MFLAGS += -mcpu=cortex-a15 -mtune=cortex-a15.cortex-a7 -mfpu=neon-vfpv4
root's avatar
root committed
675
		else
MastaG's avatar
MastaG committed
676
			MFLAGS += -mcpu=cortex-a15 -mtune=cortex-a15.cortex-a7 -mfpu=neon-vfpv4 -mvectorize-with-neon-quad
Libretro-Admin's avatar
Libretro-Admin committed
677
678
679
		endif
	else
		# ODROID-U2, -U3, -X & -X2
MastaG's avatar
MastaG committed
680
		MFLAGS += -mcpu=cortex-a9 -mfpu=neon
Libretro-Admin's avatar
Libretro-Admin committed
681
	endif
682
683

	#Since we are using GCC, we use the CFLAGS and we add some extra parameters to be able to compile (taken from reicast/reicast-emulator)
MastaG's avatar
MastaG committed
684
	ASFLAGS += $(CFLAGS) $(MFLAGS) -c  -frename-registers -fno-strict-aliasing -ffast-math -ftree-vectorize
685

Libretro-Admin's avatar
Libretro-Admin committed
686
687
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm
688
	HAVE_GENERIC_JIT = 0
Libretro-Admin's avatar
Libretro-Admin committed
689
690
691

# i.MX6
else ifneq (,$(findstring imx6,$(platform)))
692
693
	EXT    ?= so
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
694
	SHARED += -shared -Wl,--version-script=link.T
Libretro-Admin's avatar
Libretro-Admin committed
695
	fpic = -fPIC
gizmo98's avatar
gizmo98 committed
696
	FORCE_GLES = 1
697
	LIBS += -lrt
Libretro-Admin's avatar
Libretro-Admin committed
698
699
700
	CPUFLAGS += -DNO_ASM
	PLATFORM_EXT := unix
	WITH_DYNAREC=arm
701
	HAVE_GENERIC_JIT = 0
Libretro-Admin's avatar
Libretro-Admin committed
702
703
704

# OS X
else ifneq (,$(findstring osx,$(platform)))
705
706
707
	EXT    ?= dylib
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
	SHARED += -dynamiclib
Libretro-Admin's avatar
Libretro-Admin committed
708
709
	OSXVER = `sw_vers -productVersion | cut -d. -f 2`
	OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
710
        fpic += -mmacosx-version-min=10.7
Libretro-Admin's avatar
Libretro-Admin committed
711
712
	LDFLAGS += -stdlib=libc++
	fpic = -fPIC
Flyinghead's avatar
Flyinghead committed
713
	CFLAGS += -DHAVE_GLSYM_PRIVATE
Libretro-Admin's avatar
Libretro-Admin committed
714
	SINGLE_PREC_FLAGS=1
Libretro-Admin's avatar
Libretro-Admin committed
715
716
717
718
	PLATCFLAGS += -D__MACOSX__ -DOSX
	GL_LIB := -framework OpenGL
	PLATFORM_EXT := unix
	# Target Dynarec
719
720
	ifeq ($(ARCH), $(filter $(ARCH), ppc))
		WITH_DYNAREC =
721
722
    else
		HAVE_GENERIC_JIT = 0
723
	endif
Libretro-Admin's avatar
Libretro-Admin committed
724
	HAVE_OPENMP=0
Libretro-Admin's avatar
Libretro-Admin committed
725
726
727

# iOS
else ifneq (,$(findstring ios,$(platform)))
728
	EXT    ?= dylib
Libretro-Admin's avatar
Libretro-Admin committed
729
730
731
732
	ifeq ($(IOSSDK),)
		IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
	endif

733
	TARGET := $(TARGET_NAME)_libretro_ios.$(EXT)
Libretro-Admin's avatar
Libretro-Admin committed
734
735
	DEFINES += -DIOS
	GLES = 1
736
	WITH_DYNAREC=
Libretro-Admin's avatar
Libretro-Admin committed
737
	PLATFORM_EXT := unix
738
	#HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_ARM)
Libretro-Admin's avatar
Libretro-Admin committed
739
740
741
742
743

	PLATCFLAGS += -DHAVE_POSIX_MEMALIGN -DNO_ASM
	PLATCFLAGS += -DIOS -marm
	CPUFLAGS += -DNO_ASM  -DARM -D__arm__ -DARM_ASM -D__NEON_OPT
	CPUFLAGS += -marm -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp
744
	SHARED += -dynamiclib
Libretro-Admin's avatar
Libretro-Admin committed
745
746
747
748
749
750
751

	fpic = -fPIC
	GL_LIB := -framework OpenGLES

	CC = clang -arch armv7 -isysroot $(IOSSDK)
	CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
	CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
gizmo98's avatar
gizmo98 committed
752
753
754
755
756
757
758
759
760
761
762
	ifeq ($(platform),ios9)
		CC         += -miphoneos-version-min=8.0
		CC_AS      += -miphoneos-version-min=8.0
		CXX        += -miphoneos-version-min=8.0
		PLATCFLAGS += -miphoneos-version-min=8.0
	else
		CC += -miphoneos-version-min=5.0
		CC_AS += -miphoneos-version-min=5.0
		CXX += -miphoneos-version-min=5.0
		PLATCFLAGS += -miphoneos-version-min=5.0
	endif
Libretro-Admin's avatar
Libretro-Admin committed
763
	HAVE_OPENMP=0
Libretro-Admin's avatar
Libretro-Admin committed
764
765
766
767
768
769
770
771
772
773
774
775

# Theos iOS
else ifneq (,$(findstring theos_ios,$(platform)))
	DEPLOYMENT_IOSVERSION = 5.0
	TARGET = iphone:latest:$(DEPLOYMENT_IOSVERSION)
	ARCHS = armv7
	TARGET_IPHONEOS_DEPLOYMENT_VERSION=$(DEPLOYMENT_IOSVERSION)
	THEOS_BUILD_DIR := objs
	include $(THEOS)/makefiles/common.mk

	LIBRARY_NAME = $(TARGET_NAME)_libretro_ios
	DEFINES += -DIOS
gizmo98's avatar
gizmo98 committed
776
	FORCE_GLES = 1
Libretro-Admin's avatar
Libretro-Admin committed
777
	WITH_DYNAREC=arm
778
	HAVE_GENERIC_JIT = 0
Libretro-Admin's avatar
Libretro-Admin committed
779
780
781
782
783
784
785
786

	PLATCFLAGS += -DHAVE_POSIX_MEMALIGN -DNO_ASM
	PLATCFLAGS += -DIOS -marm
	CPUFLAGS += -DNO_ASM  -DARM -D__arm__ -DARM_ASM -D__NEON_OPT -DNOSSE

# Android
else ifneq (,$(findstring android,$(platform)))
	fpic = -fPIC
orbea's avatar
orbea committed
787
	EXT ?= so
788
	TARGET := $(TARGET_NAME)_libretro_android.$(EXT)
MastaG's avatar
MastaG committed
789
	SHARED += -shared -Wl,--version-script=link.T -Wl,--no-undefined -Wl,--warn-common
Libretro-Admin's avatar
Libretro-Admin committed
790
791
792
793

	CC = arm-linux-androideabi-gcc
	CXX = arm-linux-androideabi-g++
	WITH_DYNAREC=arm
794
	HAVE_GENERIC_JIT = 0
gizmo98's avatar
gizmo98 committed
795
	FORCE_GLES = 1
Libretro-Admin's avatar
Libretro-Admin committed
796
797
798
799
800
801
	PLATCFLAGS += -DANDROID
	CPUCFLAGS  += -DNO_ASM
	CPUFLAGS += -marm -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -D__arm__ -DARM_ASM -D__NEON_OPT
	CFLAGS += -DANDROID

	PLATFORM_EXT := unix
Flyinghead's avatar
Flyinghead committed
802
	HAVE_VULKAN = 1
Libretro-Admin's avatar
Libretro-Admin committed
803
804
805
806

# QNX
else ifeq ($(platform), qnx)
	fpic = -fPIC
orbea's avatar
orbea committed
807
	EXT ?= so
Libretro-Admin's avatar
Libretro-Admin committed
808
	TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
MastaG's avatar
MastaG committed
809
	SHARED += -shared -Wl,--version-script=link.T -Wl,--no-undefined -Wl,--warn-common
Libretro-Admin's avatar
Libretro-Admin committed
810
811
812
813
814
815

	CC = qcc -Vgcc_ntoarmv7le
	CC_AS = qcc -Vgcc_ntoarmv7le
	CXX = QCC -Vgcc_ntoarmv7le
	AR = QCC -Vgcc_ntoarmv7le
	WITH_DYNAREC=arm
816
	HAVE_GENERIC_JIT = 0
gizmo98's avatar
gizmo98 committed
817
	FORCE_GLES = 1
818
	DEFINES += -DTHREADED_RENDERING_DEFAULT
Libretro-Admin's avatar
Libretro-Admin committed
819
820
821
822
823
824
825
826
	PLATCFLAGS += -DNO_ASM -D__BLACKBERRY_QNX__
	CPUFLAGS += -marm -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp -D__arm__ -DARM_ASM -D__NEON_OPT
	CFLAGS += -D__QNX__

	PLATFORM_EXT := unix

# ARM
else ifneq (,$(findstring armv,$(platform)))
orbea's avatar
orbea committed
827
	EXT    ?= so
828
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
MastaG's avatar
MastaG committed
829
	SHARED += -shared -Wl,--version-script=link.T -Wl,--no-undefined
Libretro-Admin's avatar
Libretro-Admin committed
830
831
832
	fpic := -fPIC
	CPUFLAGS += -DNO_ASM -DARM -D__arm__ -DARM_ASM -DNOSSE
	WITH_DYNAREC=arm
833
	HAVE_GENERIC_JIT = 0
Libretro-Admin's avatar
Libretro-Admin committed
834
835
	PLATCFLAGS += -DARM
	ifneq (,$(findstring gles,$(platform)))
gizmo98's avatar
gizmo98 committed
836
		FORCE_GLES = 1
Libretro-Admin's avatar
Libretro-Admin committed
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
	endif
	ifneq (,$(findstring cortexa5,$(platform)))
		CPUFLAGS += -marm -mcpu=cortex-a5
	else ifneq (,$(findstring cortexa8,$(platform)))
		CPUFLAGS += -marm -mcpu=cortex-a8
	else ifneq (,$(findstring cortexa9,$(platform)))
		CPUFLAGS += -marm -mcpu=cortex-a9
	else ifneq (,$(findstring cortexa15a7,$(platform)))
		CPUFLAGS += -marm -mcpu=cortex-a15.cortex-a7
	else
		CPUFLAGS += -marm
	endif
	ifneq (,$(findstring neon,$(platform)))
		CPUFLAGS += -D__NEON_OPT -mfpu=neon
	endif
	ifneq (,$(findstring softfloat,$(platform)))
		CPUFLAGS += -mfloat-abi=softfp
	else ifneq (,$(findstring hardfloat,$(platform)))
		CPUFLAGS += -mfloat-abi=hard
	endif
857
	DEFINES += -DTHREADED_RENDERING_DEFAULT
Libretro-Admin's avatar
Libretro-Admin committed
858
859
860

# emscripten
else ifeq ($(platform), emscripten)
861
	EXT       ?= bc
Libretro-Admin's avatar
Libretro-Admin committed
862
	TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
gizmo98's avatar
gizmo98 committed
863
	FORCE_GLES := 1
864
	WITH_DYNAREC=
Libretro-Admin's avatar
Libretro-Admin committed
865
866
	CPUFLAGS += -Dasm=asmerror -D__asm__=asmerror -DNO_ASM -DNOSSE
	SINGLE_THREAD := 1
867
868
	PLATCFLAGS += -Drglgen_resolve_symbols_custom=reicast_rglgen_resolve_symbols_custom \
					  -Drglgen_resolve_symbols=reicast_rglgen_resolve_symbols
Libretro-Admin's avatar
Libretro-Admin committed
869

gizmo98's avatar
gizmo98 committed
870
	NO_REC=0
Libretro-Admin's avatar
Libretro-Admin committed
871
872
873
874
	PLATFORM_EXT := unix
	#HAVE_SHARED_CONTEXT := 1

# Windows
Libretro-Admin's avatar
Libretro-Admin committed
875
else
876
877
878
879
	ifneq ($(HAVE_GL2), 1)
		ifneq ($(HAVE_OIT), 1)
			HAVE_GL3 = 1
		endif
orbea's avatar
orbea committed
880
	endif
881
	EXT       ?= dll
882
	HAVE_GENERIC_JIT = 0
883
	HAVE_CDROM = 1
884
	TARGET := $(TARGET_NAME)_libretro.$(EXT)
Libretro-Admin's avatar
Libretro-Admin committed
885
	LDFLAGS += -shared -static-libgcc -static-libstdc++ -Wl,--version-script=link.T -lwinmm -lgdi32
Libretro-Admin's avatar
Libretro-Admin committed
886
	GL_LIB := -lopengl32
Libretro-Admin's avatar
Libretro-Admin committed
887
	LIBS := -lws2_32 -liphlpapi
Libretro-Admin's avatar
Libretro-Admin committed
888
	PLATFORM_EXT := win32
Libretro-Admin's avatar
Libretro-Admin committed
889
	SINGLE_PREC_FLAGS=1
Steel01's avatar
Steel01 committed
890
891
	CC ?= gcc
	CXX ?= g++
892
ifeq ($(WITH_DYNAREC), x86)
893
	LDFLAGS += -m32
894
895
	CFLAGS += -m32
endif
Flyinghead's avatar
Flyinghead committed
896
	HAVE_VULKAN = 1
Libretro-Admin's avatar
Libretro-Admin committed
897

Libretro-Admin's avatar
Libretro-Admin committed
898
899
endif

900
ifeq ($(STATIC_LINKING),1)
gizmo98's avatar
gizmo98 committed
901
902
	fpic=
	SHARED=
903
904
endif

905
ifeq ($(SINGLE_PREC_FLAGS),1)
Libretro-Admin's avatar
Libretro-Admin committed
906
	CORE_DEFINES += -fno-builtin-sqrtf
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
endif

ifeq ($(ARMV7A_FLAGS),1)
	MFLAGS += -marm -march=armv7-a
	ASFLAGS += -march=armv7-a
endif

ifeq ($(ARMV7_CORTEX_A9_FLAGS),1)
	MFLAGS += -mcpu=cortex-a9
endif

ifeq ($(ARM_FLOAT_ABI_HARD),1)
	MFLAGS += -mfloat-abi=hard
	ASFLAGS += -mfloat-abi=hard
	CFLAGS += -DARM_HARDFP
endif

ifeq ($(WITH_DYNAREC), $(filter $(WITH_DYNAREC), x86_64 x64))
	HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_X64)
flyinghead's avatar
flyinghead committed
926
	HAVE_LTCG = 0
927
928
929
930
931
932
933
934
935
936
endif

ifeq ($(WITH_DYNAREC), x86)
	HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_X86)
endif

ifeq ($(WITH_DYNAREC), arm)
	HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_ARM)
endif

937
ifeq ($(WITH_DYNAREC), $(filter $(WITH_DYNAREC), arm64 aarch64))
938
939
940
	HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_ARM64)
endif

941
942
943
944
945
946
947
948
949
950
ifeq ($(WITH_DYNAREC), mips)
	HOST_CPU_FLAGS = -DHOST_CPU=$(HOST_CPU_MIPS)
endif

ifeq ($(FORCE_GLES),1)
	GLES = 1
	GL_LIB := -lGLESv2
else ifneq (,$(findstring gles,$(platform)))
	GLES = 1
	GL_LIB := -lGLESv2
Libretro-Admin's avatar
Libretro-Admin committed
951
952
else ifeq ($(platform), win)
	GL_LIB := -lopengl32
Libretro-Admin's avatar
Libretro-Admin committed
953
954
955
956
else ifneq (,$(findstring osx,$(platform)))
	GL_LIB := -framework OpenGL
else ifneq (,$(findstring ios,$(platform)))
	GL_LIB := -framework OpenGLES
Flyinghead's avatar
Flyinghead committed
957
else ifeq ($(GL_LIB),)
958
959
960
	GL_LIB := -lGL
endif

gizmo98's avatar
gizmo98 committed
961
962
CFLAGS       += $(HOST_CPU_FLAGS)
CXXFLAGS     += $(HOST_CPU_FLAGS)
Libretro-Admin's avatar
Libretro-Admin committed
963
964
RZDCY_CFLAGS += $(HOST_CPU_FLAGS)

Libretro-Admin's avatar
Updates    
Libretro-Admin committed
965
966
include Makefile.common

Libretro-Admin's avatar
Libretro-Admin committed
967
968
969
970
ifeq ($(WITH_DYNAREC), x86)
	HAVE_LTCG = 0
endif

971
972
973
974
975
976
977
978
979
980
981
982
983
ifeq ($(DEBUG_ASAN),1)
	DEBUG           = 1
	DEBUG_UBSAN     = 0
	LDFLAGS        += -lasan -fsanitize=address
	CFLAGS         += -fsanitize=address
endif

ifeq ($(DEBUG_UBSAN),1)
	DEBUG           = 1
	CFLAGS         += -fsanitize=undefined
	LDFLAGS        += -lubsan -fsanitize=undefined
endif

Libretro-Admin's avatar
Libretro-Admin committed
984
ifeq ($(DEBUG),1)
gizmo98's avatar
gizmo98 committed
985
986
987
	OPTFLAGS       := -O0
	LDFLAGS        += -g
	CFLAGS         += -g
Libretro-Admin's avatar
Libretro-Admin committed
988
else
orbea's avatar
orbea committed
989
990
	ifneq (,$(findstring msvc,$(platform)))
		OPTFLAGS       := -O2
991
992
993
	else ifneq (,$(findstring classic_arm,$(platform)))
		OPTFLAGS       := -O2
	else ifeq (,$(findstring classic_arm,$(platform)))
orbea's avatar
orbea committed
994
995
996
		OPTFLAGS       := -O3
	endif

Libretro-Admin's avatar
Libretro-Admin committed
997
	CORE_DEFINES   += -DNDEBUG
gizmo98's avatar
gizmo98 committed
998
	LDFLAGS        += -DNDEBUG
Libretro-Admin's avatar
Libretro-Admin committed
999

orbea's avatar
orbea committed
1000
1001
1002
	ifeq ($(HAVE_LTCG), 1)
		CORE_DEFINES   += -flto
	endif
Libretro-Admin's avatar
Libretro-Admin committed
1003
endif
gizmo98's avatar
gizmo98 committed
1004

1005
1006
1007
1008
1009
ifeq ($(HAVE_GL3), 1)
	HAVE_CORE = 1
	CORE_DEFINES += -DHAVE_GL3
endif

1010
RZDCY_CFLAGS	+= $(CFLAGS) -c $(OPTFLAGS) -frename-registers -ftree-vectorize -fomit-frame-pointer 
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1011
1012

ifeq ($(WITH_DYNAREC), arm)
MastaG's avatar
MastaG committed
1013
	ifneq (,$(findstring odroid,$(platform)))
Gino Badouri's avatar
Gino Badouri committed
1014
		BOARD ?= $(shell cat /proc/cpuinfo | grep -i odroid | awk '{print $$3}')
MastaG's avatar
MastaG committed
1015
1016
1017
		ifneq (,$(findstring ODROIDC,$(BOARD)))
			# ODROID-C1
			RZDCY_CFLAGS += -marm -mcpu=cortex-a5
MastaG's avatar
MastaG committed
1018
1019
1020
		else ifneq (,$(findstring ODROID-XU,$(BOARD)))
			# ODROID-XU3, XU4 & XU3 Lite
			RZDCY_CFLAGS += -marm -mcpu=cortex-a15 -mtune=cortex-a15.cortex-a7 -mfpu=neon-vfpv4
MastaG's avatar
MastaG committed
1021
1022
1023
1024
1025
1026
1027
		else
			# ODROID-U2, -U3, -X & -X2
			RZDCY_CFLAGS += -marm -mcpu=cortex-a9 -mfpu=neon
		endif
	else
		RZDCY_CFLAGS += -march=armv7-a -mcpu=cortex-a9 -mfpu=vfpv3-d16
	endif
gizmo98's avatar
gizmo98 committed
1028
	RZDCY_CFLAGS += -DTARGET_LINUX_ARMELv7
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1029
else
gizmo98's avatar
gizmo98 committed
1030
	RZDCY_CFLAGS += -DTARGET_LINUX_x86
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1031
1032
endif

1033
ifeq ($(NO_THREADS),1)
Libretro-Admin's avatar
Libretro-Admin committed
1034
	CORE_DEFINES += -DTARGET_NO_THREADS
Libretro-Admin's avatar
Libretro-Admin committed
1035
else
Libretro-Admin's avatar
Libretro-Admin committed
1036
	NEED_PTHREAD=1
Libretro-Admin's avatar
Libretro-Admin committed
1037
1038
endif

1039
ifeq ($(NO_REC),1)
Libretro-Admin's avatar
Libretro-Admin committed
1040
	CORE_DEFINES += -DTARGET_NO_REC
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1041
1042
endif

Libretro-Admin's avatar
Libretro-Admin committed
1043
ifeq ($(NO_REND),1)
Libretro-Admin's avatar
Libretro-Admin committed
1044
	CORE_DEFINES += -DNO_REND=1
Libretro-Admin's avatar
Libretro-Admin committed
1045
1046
endif

Libretro-Admin's avatar
Libretro-Admin committed
1047
ifeq ($(NO_EXCEPTIONS),1)
Libretro-Admin's avatar
Libretro-Admin committed
1048
	CORE_DEFINES += -DTARGET_NO_EXCEPTIONS=1
Libretro-Admin's avatar
Libretro-Admin committed
1049
1050
endif

Libretro-Admin's avatar
Libretro-Admin committed
1051
ifeq ($(NO_NVMEM),1)
Libretro-Admin's avatar
Libretro-Admin committed
1052
	CORE_DEFINES += -DTARGET_NO_NVMEM=1
Libretro-Admin's avatar
Libretro-Admin committed
1053
1054
endif

Libretro-Admin's avatar
Libretro-Admin committed
1055
RZDCY_CXXFLAGS := $(RZDCY_CFLAGS) -fexceptions -fno-rtti -std=gnu++11
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1056

Libretro-Admin's avatar
Libretro-Admin committed
1057
ifeq (,$(findstring msvc,$(platform)))
orbea's avatar
orbea committed
1058
	CORE_DEFINES   += -funroll-loops
Libretro-Admin's avatar
Libretro-Admin committed
1059
1060
1061
endif

ifeq ($(HAVE_OIT), 1)
orbea's avatar
orbea committed
1062
1063
	HAVE_CORE = 1
	CORE_DEFINES += -DHAVE_OIT -DHAVE_GL4
Libretro-Admin's avatar
Libretro-Admin committed
1064
1065
endif

Libretro-Admin's avatar
Libretro-Admin committed
1066
1067
1068
1069
ifeq ($(HAVE_CORE), 1)
	CORE_DEFINES += -DCORE
endif

1070
1071
ifeq ($(HAVE_TEXUPSCALE), 1)
	CORE_DEFINES += -DHAVE_TEXUPSCALE
Libretro-Admin's avatar
Libretro-Admin committed
1072
1073
ifeq ($(HAVE_OPENMP), 1)
	CFLAGS += -fopenmp
1074
	CXXFLAGS += -fopenmp
Libretro-Admin's avatar
Typo    
Libretro-Admin committed
1075
	LDFLAGS += -fopenmp
Libretro-Admin's avatar
Libretro-Admin committed
1076
1077
1078
else
	CFLAGS += -DTARGET_NO_OPENMP
	CXXFLAGS += -DTARGET_NO_OPENMP
Libretro-Admin's avatar
Libretro-Admin committed
1079
endif
Libretro-Admin's avatar
Libretro-Admin committed
1080
ifeq ($(platform), win)
Libretro-Admin's avatar
Libretro-Admin committed
1081
	LDFLAGS_END += -Wl,-Bstatic -lgomp -lwsock32 -lws2_32 -liphlpapi
Libretro-Admin's avatar
Libretro-Admin committed
1082
endif
Libretro-Admin's avatar
Libretro-Admin committed
1083
	NEED_CXX11=1
Libretro-Admin's avatar
Libretro-Admin committed
1084
1085
1086
1087
1088
	NEED_PTHREAD=1
endif

ifeq ($(NEED_PTHREAD), 1)
	LIBS         += -lpthread
1089
1090
endif

Libretro-Admin's avatar
Libretro-Admin committed
1091
1092
ifeq ($(HAVE_GL), 1)
	ifeq ($(GLES),1)
Flyinghead's avatar
Flyinghead committed
1093
		CORE_DEFINES += -DHAVE_OPENGLES -DHAVE_OPENGLES2
Libretro-Admin's avatar
Libretro-Admin committed
1094
1095
1096
1097
1098
	else
		CORE_DEFINES += -DHAVE_OPENGL
	endif
endif

Flyinghead's avatar
Flyinghead committed
1099
1100
1101
1102
ifeq ($(HAVE_VULKAN), 1)
	CORE_DEFINES += -DHAVE_VULKAN
endif

Libretro-Admin's avatar
Libretro-Admin committed
1103
1104
1105
1106
1107
1108
ifeq ($(DEBUG), 1)
	HAVE_GENERIC_JIT = 0
endif

ifeq ($(HAVE_GENERIC_JIT), 1)
	CORE_DEFINES += -DTARGET_NO_JIT
Libretro-Admin's avatar
Libretro-Admin committed
1109
1110
1111
1112
	NEED_CXX11=1
endif

ifeq ($(NEED_CXX11), 1)
Libretro-Admin's avatar
Libretro-Admin committed
1113
1114
1115
	CXXFLAGS     += -std=c++11
endif

1116
ifeq ($(HAVE_CHD),1)
Libretro-Admin's avatar
Libretro-Admin committed
1117
CORE_DEFINES += -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_SYS_PARAM_H -D_7ZIP_ST -DUSE_FLAC -DUSE_LZMA
1118
1119
endif

Libretro-Admin's avatar
Libretro-Admin committed
1120
1121
1122
1123
1124
1125
RZDCY_CFLAGS   += $(CORE_DEFINES)
RZDCY_CXXFLAGS += $(CORE_DEFINES)
CFLAGS         += $(CORE_DEFINES)
CXXFLAGS       += $(CORE_DEFINES)

CFLAGS   += $(OPTFLAGS) -c
1126
CFLAGS   += -fno-strict-aliasing
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1127
CXXFLAGS += -fno-rtti -fpermissive -fno-operator-names
Libretro-Admin's avatar
Libretro-Admin committed
1128
LIBS     += -lm 
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1129
1130
1131

PREFIX        ?= /usr/local

gizmo98's avatar
gizmo98 committed
1132
ifneq (,$(findstring arm, $(ARCH)))
liberodark's avatar
liberodark committed
1133
	CC_AS    = ${CC_PREFIX}${CC} #The ngen_arm.S must be compiled with gcc, not as
1134
	ASFLAGS  += $(CFLAGS)
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1135
1136
endif

1137
ifeq ($(PGO_MAKE),1)
gizmo98's avatar
gizmo98 committed
1138
1139
	CFLAGS += -fprofile-generate -pg
	LDFLAGS += -fprofile-generate
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1140
else
gizmo98's avatar
gizmo98 committed
1141
	CFLAGS += -fomit-frame-pointer
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1142
1143
endif

1144
ifeq ($(PGO_USE),1)
gizmo98's avatar
gizmo98 committed
1145
	CFLAGS += -fprofile-use
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1146
1147
endif

1148
ifeq ($(LTO_TEST),1)
gizmo98's avatar
gizmo98 committed
1149
1150
	CFLAGS += -flto -fwhole-program 
	LDFLAGS +=-flto -fwhole-program 
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
1151
1152
endif

Libretro-Admin's avatar
Libretro-Admin committed
1153
1154
CFLAGS     += $(fpic)
CXXFLAGS   += $(fpic)
Libretro-Admin's avatar
Libretro-Admin committed
1155
LDFLAGS    += $(fpic)
Libretro-Admin's avatar
Update    
Libretro-Admin committed
1156