SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
libretro/Makefile
1 STATIC_LINKING := 0
2 AR := ar
3
4 CFLAGS := -Wall $(CFLAGS)
5
6 GIT_VERSION ?= " $(shell git rev-parse --short HEAD || echo unknown)"
7 ifneq ($(GIT_VERSION)," unknown")
8 CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
9 endif
10
11 SPACE :=
12 SPACE := $(SPACE) $(SPACE)
13 BACKSLASH :=
14 BACKSLASH := \$(BACKSLASH)
15 filter_out1 = $(filter-out $(firstword $1),$1)
16 filter_out2 = $(call filter_out1,$(call filter_out1,$1))
17 unixpath = $(subst \,/,$1)
18 unixcygpath = /$(subst :,,$(call unixpath,$1))
19
20 ifeq ($(platform),)
21 platform = unix
22 ifeq ($(shell uname -a),)
23 platform = win
24 else ifneq ($(findstring MINGW,$(shell uname -a)),)
25 platform = win
26 else ifneq ($(findstring Darwin,$(shell uname -a)),)
27 platform = osx
28 else ifneq ($(findstring win,$(shell uname -a)),)
29 platform = win
30 endif
31 endif
32
33 # system platform
34 system_platform = unix
35 ifeq ($(shell uname -a),)
36 EXE_EXT = .exe
37 system_platform = win
38 else ifneq ($(findstring Darwin,$(shell uname -a)),)
39 system_platform = osx
40 arch = intel
41 ifeq ($(shell uname -p),powerpc)
42 arch = ppc
43 endif
44 ifeq ($(shell uname -p),arm)
45 arch = arm
46 endif
47 else ifneq ($(findstring MINGW,$(shell uname -a)),)
48 system_platform = win
49 endif
50
51 ifeq ($(platform), win)
52 INCFLAGS += -I Windows
53 endif
54
55 CORE_DIR = ..
56
57 TARGET_NAME = sameboy
58 LIBM = -lm
59
60
61 ifneq ($(SANITIZER),)
62 CFLAGS := -fsanitize=$(SANITIZER) $(CFLAGS)
63 CXXFLAGS := -fsanitize=$(SANITIZER) $(CXXFLAGS)
64 LDFLAGS := -fsanitize=$(SANITIZER) $(LDFLAGS) -lasan
65 endif
66
67 ifeq ($(STATIC_LINKING), 1)
68 EXT := a
69 endif
70
71 ifeq ($(platform), unix)
72 EXT ?= so
73 TARGET := $(TARGET_NAME)_libretro.$(EXT)
74 fpic := -fPIC
75 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
76 else ifeq ($(platform), linux-portable)
77 TARGET := $(TARGET_NAME)_libretro.$(EXT)
78 fpic := -fPIC -nostdlib
79 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T
80 LIBM :=
81 # (armv7 a7, hard point, neon based) ###
82 # NESC, SNESC, C64 mini
83 else ifeq ($(platform),$(filter $(platform),classic_armv7_a7 unix-armv7-hardfloat-neon))
84 TARGET := $(TARGET_NAME)_libretro.so
85 fpic := -fPIC
86 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
87 CFLAGS += -Ofast \
88 -flto=4 -fwhole-program -fuse-linker-plugin \
89 -fdata-sections -ffunction-sections -Wl,--gc-sections \
90 -fno-stack-protector -fno-ident -fomit-frame-pointer \
91 -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
92 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
93 -fmerge-all-constants -fno-math-errno \
94 -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
95 CXXFLAGS += $(CFLAGS)
96 CPPFLAGS += $(CFLAGS)
97 ASFLAGS += $(CFLAGS)
98 HAVE_NEON = 1
99 ARCH = arm
100 BUILTIN_GPU = neon
101 USE_DYNAREC = 1
102 ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
103 CFLAGS += -march=armv7-a
104 else
105 CFLAGS += -march=armv7ve
106 # If gcc is 5.0 or later
107 ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
108 LDFLAGS += -static-libgcc -static-libstdc++
109 endif
110 endif
111
112 ###########################
113 # Raspberry Pi 4 in 64 mode
114 else ifneq (,$(findstring rpi4_64,$(platform)))
115 EXT ?= so
116 TARGET := $(TARGET_NAME)_libretro.$(EXT)
117 fpic := -fPIC
118 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
119 CFLAGS += -O2 -march=armv8-a+crc+simd -mtune=cortex-a72
120 ###########################
121
122 #######################################
123 # Nintendo Switch (libtransistor)
124 else ifeq ($(platform), switch)
125 TARGET := $(TARGET_NAME)_libretro_$(platform).a
126 include $(LIBTRANSISTOR_HOME)/libtransistor.mk
127 CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls
128 STATIC_LINKING=1
129 # Nintendo Switch (libnx)
130 else ifeq ($(platform), libnx)
131 include $(DEVKITPRO)/libnx/switch_rules
132 TARGET := $(TARGET_NAME)_libretro_$(platform).a
133 DEFINES += -DSWITCH=1 -D__SWITCH__ -DARM
134 CFLAGS += $(DEFINES) -fPIE -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec
135 CFLAGS += -march=armv8-a -mtune=cortex-a57 -mtp=soft -mcpu=cortex-a57+crc+fp+simd -ffast-math
136 CXXFLAGS := $(ASFLAGS) $(CFLAGS)
137 STATIC_LINKING = 1
138 # Nintendo WiiU
139 else ifeq ($(platform), wiiu)
140 TARGET := $(TARGET_NAME)_libretro_$(platform).a
141 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
142 AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
143 CFLAGS += -DGEKKO -DHW_RVL -DWIIU -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST -I$(DEVKITPRO)/libogc/include
144 CFLAGS += -ffunction-sections -fdata-sections -D__wiiu__ -D__wut__
145 STATIC_LINKING = 1
146 else ifneq (,$(findstring osx,$(platform)))
147 TARGET := $(TARGET_NAME)_libretro.dylib
148 fpic := -fPIC
149 SHARED := -dynamiclib
150 MACSOSVER = `sw_vers -productVersion | cut -d. -f 1`
151 OSXVER = `sw_vers -productVersion | cut -d. -f 2`
152 OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
153 MINVERSION :=
154
155 ifeq ($(UNIVERSAL),1)
156 ifeq ($(archs),ppc)
157 ARCHFLAGS = -arch ppc -arch ppc64
158 else ifeq ($(archs),arm64)
159 ARCHFLAGS = -arch x86_64 -arch arm64
160 else
161 ARCHFLAGS = -arch i386 -arch x86_64
162 endif
163 CFLAGS += $(ARCHFLAGS)
164 LFLAGS += $(ARCHFLAGS)
165 endif
166
167 ifeq ($(CROSS_COMPILE),1)
168 TARGET_RULE = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
169 CFLAGS += $(TARGET_RULE)
170 CPPFLAGS += $(TARGET_RULE)
171 CXXFLAGS += $(TARGET_RULE)
172 LDFLAGS += $(TARGET_RULE)
173 endif
174
175 CFLAGS += $(ARCHFLAGS)
176 CXXFLAGS += $(ARCHFLAGS)
177 LDFLAGS += $(ARCHFLAGS)
178
179 else ifneq (,$(findstring ios,$(platform)))
180 TARGET := $(TARGET_NAME)_libretro_ios.dylib
181 fpic := -fPIC
182 SHARED := -dynamiclib
183 MINVERSION :=
184
185 ifeq ($(IOSSDK),)
186 IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
187 endif
188
189 DEFINES := -DIOS
190 ifeq ($(platform),ios-arm64)
191 CC = cc -arch arm64 -isysroot $(IOSSDK)
192 else
193 CC = cc -arch armv7 -isysroot $(IOSSDK)
194 endif
195 ifeq ($(platform),$(filter $(platform),ios9 ios-arm64))
196 MINVERSION = -miphoneos-version-min=8.0
197 else
198 MINVERSION = -miphoneos-version-min=5.0
199 endif
200 CFLAGS += $(MINVERSION)
201
202 else ifeq ($(platform), tvos-arm64)
203 EXT?=dylib
204 TARGET := $(TARGET_NAME)_libretro_tvos.$(EXT)
205 fpic := -fPIC
206 SHARED := -dynamiclib
207 DEFINES := -DIOS
208 ifeq ($(IOSSDK),)
209 IOSSDK := $(shell xcodebuild -version -sdk appletvos Path)
210 endif
211 CC = cc -arch arm64 -isysroot $(IOSSDK)
212
213 else ifneq (,$(findstring qnx,$(platform)))
214 TARGET := $(TARGET_NAME)_libretro_qnx.so
215 fpic := -fPIC
216 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
217 else ifeq ($(platform), emscripten)
218 TARGET := $(TARGET_NAME)_libretro_emscripten.bc
219 fpic := -fPIC
220 SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
221 else ifeq ($(platform), vita)
222 TARGET := $(TARGET_NAME)_libretro_vita.a
223 CC = arm-vita-eabi-gcc
224 AR = arm-vita-eabi-ar
225 CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls
226 STATIC_LINKING = 1
227
228 # Windows MSVC 2017 all architectures
229 else ifneq (,$(findstring windows_msvc2017,$(platform)))
230
231 NO_GCC := 1
232 CFLAGS += -DNOMINMAX
233 CXXFLAGS += -DNOMINMAX
234 WINDOWS_VERSION = 1
235
236 PlatformSuffix = $(subst windows_msvc2017_,,$(platform))
237 ifneq (,$(findstring desktop,$(PlatformSuffix)))
238 WinPartition = desktop
239 MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -FS
240 LDFLAGS += -MANIFEST -LTCG:incremental -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1
241 LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
242 else ifneq (,$(findstring uwp,$(PlatformSuffix)))
243 WinPartition = uwp
244 MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc -FS
245 LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
246 LIBS += WindowsApp.lib
247 endif
248
249 CFLAGS += $(MSVC2017CompileFlags)
250 CXXFLAGS += $(MSVC2017CompileFlags)
251
252 TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
253
254 CC ?= cl.exe
255 CXX ?= cl.exe
256 LD ?= link.exe
257
258 reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
259 fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
260
261 ProgramFiles86w := $(shell cmd //c "echo %PROGRAMFILES(x86)%")
262 ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")
263
264 WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
265 WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
266 WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
267 WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
268 WindowsSdkDir := $(WindowsSdkDir)
269
270 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)
271 WindowsSDKVersion := $(WindowsSDKVersion)
272
273 VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
274 VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2017/Enterprise
275 VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2017/Professional
276 VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2017/Community
277
278 VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
279 ifeq ($(VsInstallRoot), )
280 VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
281 endif
282 ifeq ($(VsInstallRoot), )
283 VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
284 endif
285 ifeq ($(VsInstallRoot), )
286 VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
287 endif
288 VsInstallRoot := $(VsInstallRoot)
289
290 VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
291 VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)
292
293 WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
294 WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
295 WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
296 WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
297 WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")
298
299 # For some reason the HostX86 compiler doesn't like compiling for x64
300 # ("no such file" opening a shared library), and vice-versa.
301 # Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
302 # NOTE: What about ARM?
303 ifneq (,$(findstring x64,$(TargetArchMoniker)))
304 VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX64
305 else
306 VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX86
307 endif
308
309 PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)/$(TargetArchMoniker)"):$(PATH)
310 PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
311 INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
312 LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)")
313 ifneq (,$(findstring uwp,$(PlatformSuffix)))
314 LIB := $(LIB);$(shell IFS=$$'\n'; cygpath -w "$(LIB)/store")
315 endif
316
317 export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
318 export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
319 TARGET := $(TARGET_NAME)_libretro.dll
320 PSS_STYLE :=2
321 LDFLAGS += -DLL
322
323 else
324 CC ?= gcc
325 TARGET := $(TARGET_NAME)_libretro.dll
326 SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
327 endif
328
329 ifeq ($(STATIC_LINKING), 1)
330 # For some reason libretro's buildbot expects the output to be at ./libretro/ for static targets
331 BIN ?= $(abspath $(CORE_DIR)/libretro)
332 else
333 BIN ?= $(abspath $(CORE_DIR))
334 endif
335 TARGET := $(BIN)/$(TARGET)
336
337
338 # To force use of the Unix version instead of the Windows version
339 MKDIR := $(shell which mkdir)
340
341 LDFLAGS += $(LIBM)
342
343 ifeq ($(DEBUG), 1)
344 CFLAGS += -O0 -g
345 else
346 CFLAGS += -O2 -DNDEBUG
347 endif
348
349 include Makefile.common
350
351 CFLAGS += -DGB_VERSION=\"$(VERSION)\"
352
353 OBJECTS := $(patsubst $(CORE_DIR)/%.c,$(CORE_DIR)/build/obj/%_libretro.c.o,$(SOURCES_C))
354
355 OBJOUT = -o
356 LINKOUT = -o
357
358 ifneq (,$(findstring msvc,$(platform)))
359 OBJOUT = -Fo
360 LINKOUT = -out:
361 ifeq ($(STATIC_LINKING),1)
362 LD ?= lib.exe
363 STATIC_LINKING=0
364 else
365 LD = link.exe
366 endif
367 else
368 LD = $(CC)
369 endif
370
371 CFLAGS += -D__LIBRETRO__ $(fpic) $(INCFLAGS) -std=gnu11 -D_GNU_SOURCE -D_USE_MATH_DEFINES
372
373 all: $(TARGET)
374
375 $(CORE_DIR)/libretro/%_boot.c: $(BOOTROMS_DIR)/%_boot.bin
376 echo "/* AUTO-GENERATED */" > $@
377 echo "const unsigned char $(notdir $(@:%.c=%))[] = {" >> $@
378 ifneq ($(findstring Haiku,$(shell uname -s)),)
379 # turns out od is posix, hexdump is not hence is less portable
380 # this is still rather ugly and could be done better I guess
381 od -A none -t x1 -v $< | sed -e 's/^\ /0x/' -e 's/\ /,\ 0x/g' -e 's/$$/,/g' | tr '\n' ' ' >> $@
382 else
383 hexdump -v -e '/1 "0x%02x, "' $< >> $@
384 endif
385 echo "};" >> $@
386 echo "const unsigned $(notdir $(@:%.c=%))_length = sizeof($(notdir $(@:%.c=%)));" >> $@
387
388 $(abspath $(CORE_DIR))/build/bin/BootROMs/%_boot.bin:
389 $(MAKE) -C $(CORE_DIR) $@
390
391 $(TARGET): $(OBJECTS)
392 -@$(MKDIR) -p $(dir $@)
393 ifeq ($(STATIC_LINKING), 1)
394 $(AR) rcs $@ $(OBJECTS)
395 else
396 $(LD) $(fpic) $(SHARED) $(INCFLAGS) $(LINKOUT)$@ $(OBJECTS) $(LDFLAGS)
397 endif
398
399 $(CORE_DIR)/build/obj/%_libretro.c.o: $(CORE_DIR)/%.c
400 -@$(MKDIR) -p $(dir $@)
401 $(CC) -c $(OBJOUT)$@ $< $(CFLAGS) $(fpic) -DGB_INTERNAL
402
403 %.o: %.c
404 $(CC) $(CFLAGS) $(fpic) -c $(OBJOUT)$@ $<
405
406 clean:
407 rm -f $(OBJECTS) $(TARGET)
408
409 .PHONY: clean
410
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.