forked from libretro/citra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
438 lines (377 loc) · 13.9 KB
/
Makefile
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
HAVE_DYNARMIC = 0
HAVE_FFMPEG = 0
HAVE_FFMPEG_STATIC = 0
HAVE_GLAD = 1
HAVE_SSE = 0
HAVE_RGLGEN = 0
HAVE_RPC = 1
FFMPEG_DISABLE_VDPAU ?= 0
HAVE_FFMPEG_CROSSCOMPILE ?= 0
FFMPEG_XC_CPU ?=
FFMPEG_XC_ARCH ?=
FFMPEG_XC_PREFIX ?=
FFMPEG_XC_SYSROOT ?=
FFMPEG_XC_NM ?=
FFMPEG_XC_AR ?=
FFMPEG_XC_AS ?=
FFMPEG_XC_CC ?=
FFMPEG_XC_LD ?=
TARGET_NAME := citra
EXTERNALS_DIR += ./externals
SRC_DIR += ./src
LIBS = -lm
DEFINES := -DHAVE_LIBRETRO
STATIC_LINKING := 0
AR := ar
SPACE :=
SPACE := $(SPACE) $(SPACE)
BACKSLASH :=
BACKSLASH := \$(BACKSLASH)
filter_out1 = $(filter-out $(firstword $1),$1)
filter_out2 = $(call filter_out1,$(call filter_out1,$1))
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
ifeq (,$(ARCH))
ARCH = $(shell uname -m)
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
ifeq ($(shell uname -p),powerpc)
arch = ppc
endif
else ifneq ($(findstring MINGW,$(shell uname -a)),)
system_platform = win
endif
ifeq ($(ARCHFLAGS),)
ifeq ($(archs),ppc)
ARCHFLAGS = -arch ppc -arch ppc64
else
ARCHFLAGS = -arch i386 -arch x86_64
endif
endif
ifeq ($(platform), osx)
ifndef ($(NOUNIVERSAL))
CXXFLAGS += $(ARCHFLAGS)
LFLAGS += $(ARCHFLAGS)
endif
endif
ifeq ($(STATIC_LINKING), 1)
EXT := a
endif
GIT_REV := "$(shell git rev-parse HEAD || echo unknown)"
GIT_BRANCH := "$(shell git rev-parse --abbrev-ref HEAD || echo unknown)"
GIT_DESC := "$(shell git describe --always --long --dirty || echo unknown)"
BUILD_DATE := "$(shell date +'%d/%m/%Y_%H:%M')"
DEFINES += -DGIT_REV=\"$(GIT_REV)\" \
-DGIT_BRANCH=\"$(GIT_BRANCH)\" \
-DGIT_DESC=\"$(GIT_DESC)\" \
-DBUILD_NAME=\"citra-libretro\" \
-DBUILD_DATE=\"$(BUILD_DATE)\" \
-DBUILD_VERSION=\"$(GIT_BRANCH)-$(GIT_DESC)\" \
-DBUILD_FULLNAME=\"\" \
-DSHADER_CACHE_VERSION=\"0\"
ifeq ($(platform), unix)
EXT ?= so
TARGET := $(TARGET_NAME)_libretro.$(EXT)
fpic := -fPIC
SHARED := -shared -Wl,--version-script=$(SRC_DIR)/citra_libretro/link.T -Wl,--no-undefined
LIBS +=-lpthread -lGL -ldl
HAVE_FFMPEG = 1
HAVE_FFMPEG_STATIC = 1
ifeq ($(HAVE_FFMPEG_STATIC), 1)
LIBS += $(EXTERNALS_DIR)/ffmpeg/libavcodec/libavcodec.a $(EXTERNALS_DIR)/ffmpeg/libavutil/libavutil.a
else
LIBS += -lavcodec -lavutil
endif
#######################################
# Nintendo Switch (libnx)
else ifeq ($(platform), libnx)
include $(DEVKITPRO)/libnx/switch_rules
TARGET := $(TARGET_NAME)_libretro_$(platform).a
DEFINES += -DSWITCH=1 -D__SWITCH__=1 -DHAVE_LIBNX=1 \
-D__LINUX_ERRNO_EXTENSIONS__ -DBOOST_ASIO_DISABLE_SIGACTION -DOS_RNG_AVAILABLE
fpic := -fPIE
CFLAGS = $(DEFINES) -I$(LIBNX)/include/ -I$(PORTLIBS)/include/ -specs=$(LIBNX)/switch.specs
CFLAGS += -march=armv8-a -mtune=cortex-a57 -mtp=soft -mcpu=cortex-a57+crc+fp+simd -ffast-math
CXXFLAGS = $(ASFLAGS) $(CFLAGS)
ARCH = aarch64
STATIC_LINKING = 1
HAVE_GLAD = 0
HAVE_RGLGEN = 1
HAVE_RPC = 0
DEBUG = 0
else ifneq (,$(findstring windows_msvc2019,$(platform)))
LIBS =
PlatformSuffix = $(subst windows_msvc2019_,,$(platform))
ifneq (,$(findstring desktop,$(PlatformSuffix)))
WinPartition = desktop
MSVC2019CompileFlags = -D_UNICODE -DUNICODE -DWINVER=0x0600 -D_WIN32_WINNT=0x0600
LDFLAGS += -MANIFEST -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1
else ifneq (,$(findstring uwp,$(PlatformSuffix)))
WinPartition = uwp
MSVC2019CompileFlags = -DWINDLL -D_UNICODE -DUNICODE -DWRL_NO_DEFAULT_LIB
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
endif
ifeq ($(DEBUG), 1)
MSVC2019CompileFlags += -DEBUG
else
MSVC2019CompileFlags += -O2 -GS"-" -MD
endif
MSVC2019CompileFlags += -D_WIN32=1 -DNOMINMAX -DBOOST_ALL_NO_LIB
CFLAGS += $(MSVC2019CompileFlags) -nologo
CXXFLAGS += $(MSVC2019CompileFlags) -nologo -EHsc -Zc:throwingNew,inline
TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
CC = cl.exe
CXX = cl.exe
SPACE :=
SPACE := $(SPACE) $(SPACE)
BACKSLASH :=
BACKSLASH := \$(BACKSLASH)
filter_out1 = $(filter-out $(firstword $1),$1)
filter_out2 = $(call filter_out1,$(call filter_out1,$1))
reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>/dev/null)))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
b1 := (
b2 := )
ProgramFiles86w := $(ProgramFiles$(b1)x86$(b2))
ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir := $(WindowsSdkDir)
WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))$(BACKSLASH)
WindowsSDKVersion := $(WindowsSDKVersion)
VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2019/BuildTools
VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2019/Enterprise
VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2019/Professional
VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2019/Community
VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
endif
VsInstallRoot := $(VsInstallRoot)
VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)
VcCompilerLibDir := $(VcCompilerToolsDir)/lib/$(TargetArchMoniker)
WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerLibDir)")
INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
# For some reason the HostX86 compiler doesn't like compiling for x64
# ("no such file" opening a shared library), and vice-versa.
# Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
# NOTE: What about ARM?
ifneq (,$(findstring x64,$(TargetArchMoniker)))
override TARGET_ARCH = x86_64
VCCompilerToolsBinDir := $(VcCompilerToolsDir)/bin/HostX64/$(TargetArchMoniker)
LIB := $(LIB);$(CORE_DIR)/dx9sdk/Lib/x64
else
override TARGET_ARCH = x86
VCCompilerToolsBinDir := $(VcCompilerToolsDir)/bin/HostX86/$(TargetArchMoniker)
LIB := $(LIB);$(CORE_DIR)/dx9sdk/Lib/x86
endif
PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir);$(FFMPEGDIR)/Windows/$(TARGET_ARCH)/lib
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
PLATFORM_EXT = win32
LDFLAGS += ws2_32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib imm32.lib ole32.lib oleaut32.lib version.lib uuid.lib mfuuid.lib
HAVE_MF = 1
# RPC crashes, TODO: Figure out why
HAVE_RPC = 0
else
CC ?= gcc
TARGET := $(TARGET_NAME)_libretro.dll
DEFINES += -D_WIN32_WINNT=0x0600 -DWINVER=0x0600
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=$(SRC_DIR)/citra_libretro/link.T -Wl,--no-undefined
LDFLAGS += -static -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -lws2_32
ifeq ($(MSYSTEM),MINGW64)
CC ?= x86_64-w64-mingw32-gcc
CXX ?= x86_64-w64-mingw32-g++
LDFLAGS += -lopengl32 -lmfuuid
ASFLAGS += -DWIN64
HAVE_MF = 1
endif
endif
ifneq (,$(findstring msvc,$(platform)))
CFLAGS += -D_CRT_SECURE_NO_WARNINGS
CXXFLAGS += -D_CRT_SECURE_NO_WARNINGS
endif
# x86_64 is expected to support both SSE and Dynarmic
ifeq ($(ARCH), x86_64)
DEFINES += -DARCHITECTURE_x86_64
HAVE_DYNARMIC = 1
HAVE_SSE = 1
endif
ifeq ($(DEBUG), 1)
CXXFLAGS += -O0 -g
else
# Add Unix optimization flags
ifeq (,$(findstring msvc,$(platform)))
CXXFLAGS += -O3 -ffast-math -ftree-vectorize -DNDEBUG
endif
endif
# Set ffmpeg configure options
ifeq ($(HAVE_FFMPEG_STATIC), 1)
FFMPEG_CONF_OPTS =--disable-encoders --disable-decoders --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm --disable-programs
ifeq ($(FFMPEG_DISABLE_VDPAU), 1)
FFMPEG_CONF_OPTS += --disable-vdpau
endif
ifeq ($(HAVE_FFMPEG_CROSSCOMPILE), 1)
FFMPEG_CONF_OPTS+= --enable-cross-compile --target-os="linux"
ifeq ($(FFMPEG_XC_CPU),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_CPU provided)
else
FFMPEG_CONF_OPTS += --cpu="$(FFMPEG_XC_CPU)"
endif
ifeq ($(FFMPEG_XC_ARCH),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_ARCH provided)
else
FFMPEG_CONF_OPTS += --arch="$(FFMPEG_XC_ARCH)"
endif
ifeq ($(FFMPEG_XC_PREFIX),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_PREFIX provided)
else
FFMPEG_CONF_OPTS += --cross-prefix="$(FFMPEG_XC_PREFIX)"
endif
ifeq ($(FFMPEG_XC_SYSROOT),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_SYSROOT provided)
else
FFMPEG_CONF_OPTS += --sysroot="$(FFMPEG_XC_SYSROOT)" --sysinclude="$(FFMPEG_XC_SYSROOT)/usr/include"
endif
ifeq ($(FFMPEG_XC_NM),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_NM provided)
else
FFMPEG_CONF_OPTS += --nm="$(FFMPEG_XC_NM)"
endif
ifeq ($(FFMPEG_XC_AR),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_AR provided)
else
FFMPEG_CONF_OPTS += --ar="$(FFMPEG_XC_AR)"
endif
ifeq ($(FFMPEG_XC_AS),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_AS provided)
else
FFMPEG_CONF_OPTS += --as="$(FFMPEG_XC_AS)"
endif
ifeq ($(FFMPEG_XC_CC),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_CC provided)
else
FFMPEG_CONF_OPTS += --cc="$(FFMPEG_XC_CC)"
endif
ifeq ($(FFMPEG_XC_LD),)
$(error HAVE_FFMPEG_CROSSCOMPILE set, but no FFMPEG_XC_LD provided)
else
FFMPEG_CONF_OPTS += --ld="$(FFMPEG_XC_LD)"
endif
endif
endif
include Makefile.common
SOURCES_CXX += $(DYNARMICSOURCES_CXX)
CPPFILES = $(filter %.cpp,$(SOURCES_CXX))
CCFILES = $(filter %.cc,$(SOURCES_CXX))
OBJECTS := $(SOURCES_C:.c=.o) $(CPPFILES:.cpp=.o) $(CCFILES:.cc=.o)
ifeq (,$(findstring msvc,$(platform)))
CXXFLAGS += -std=c++17
else
CXXFLAGS += -std:c++latest
endif
CFLAGS += -D__LIBRETRO__ $(fpic) $(DEFINES) $(INCFLAGS) $(INCFLAGS_PLATFORM)
DYNARMICFLAGS += -D__LIBRETRO__ $(fpic) $(DEFINES) $(DYNARMICINCFLAGS) $(INCFLAGS_PLATFORM) $(CXXFLAGS)
CXXFLAGS += -D__LIBRETRO__ $(fpic) $(DEFINES) $(INCFLAGS) $(INCFLAGS_PLATFORM)
OBJOUT = -o
LINKOUT = -o
ifneq (,$(findstring msvc,$(platform)))
OBJOUT = -Fo
LINKOUT = -out:
ifeq ($(STATIC_LINKING),1)
LD ?= lib.exe
ifeq ($(DEBUG), 1)
CFLAGS += -MTd
CXXFLAGS += -MTd
else
CFLAGS += -MT
CXXFLAGS += -MT
endif
else
LD = link.exe
ifeq ($(DEBUG), 1)
CFLAGS += -MDd
CXXFLAGS += -MDd
else
CFLAGS += -MD
CXXFLAGS += -MD
endif
endif
else
LD = $(CXX)
endif
all: shaders $(TARGET)
ffmpeg_configure:
ifeq ($(HAVE_FFMPEG_STATIC), 1)
cd $(EXTERNALS_DIR)/ffmpeg && ./configure $(FFMPEG_CONF_OPTS)
endif
ffmpeg_static: ffmpeg_configure
ifeq ($(HAVE_FFMPEG_STATIC), 1)
cd $(EXTERNALS_DIR)/ffmpeg && $(MAKE) -j$(NUMPROC)
endif
$(TARGET): ffmpeg_static $(OBJECTS)
ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJECTS)
else
$(LD) $(fpic) $(SHARED) $(INCLUDES) $(LINKOUT)$@ $(OBJECTS) $(LDFLAGS) $(LIBS)
endif
%.o: %.c
$(CC) $(CFLAGS) $(fpic) -c $(OBJOUT)$@ $<
$(foreach p,$(OBJECTS),$(if $(findstring $(EXTERNALS_DIR)/dynarmic/src,$p),$p,)):
$(CXX) $(DYNARMICFLAGS) $(fpic) -c $(OBJOUT)$@ $(@:.o=.cpp)
%.o: %.cc
$(CXX) $(CXXFLAGS) $(fpic) -c $(OBJOUT)$@ $<
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(fpic) -c $(OBJOUT)$@ $<
clean:
rm -f $(OBJECTS) $(TARGET)
ifeq ($(HAVE_FFMPEG_STATIC), 1)
cd $(EXTERNALS_DIR)/ffmpeg && $(MAKE) clean
endif
shaders: $(SHADER_FILES)
mkdir -p $(SRC_DIR)/video_core/shaders
for SHADER_FILE in $^; do \
FILENAME=$$(basename "$$SHADER_FILE"); \
SHADER_NAME=$$(echo "$$FILENAME" | sed -e "s/\./_/g"); \
rm -f $(SRC_DIR)/video_core/shaders/$$FILENAME; \
echo "#pragma once" >> $(SRC_DIR)/video_core/shaders/$$FILENAME; \
echo "constexpr std::string_view $$SHADER_NAME = R\"(" >> $(SRC_DIR)/video_core/shaders/$$FILENAME; \
cat $$SHADER_FILE >> $(SRC_DIR)/video_core/shaders/$$FILENAME; \
echo ")\";" >> $(SRC_DIR)/video_core/shaders/$$FILENAME; \
done
.PHONY: clean ffmpeg_static