1DEBUG = 0
2FRONTEND_SUPPORTS_RGB565 = 1
3FRONTEND_SUPPORTS_XRGB8888 = 0
4
5TARGET_NAME := handy
6GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
7ifneq ($(GIT_VERSION)," unknown")
8	CXXFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
9endif
10
11ifeq ($(platform),)
12	platform = unix
13	ifeq ($(shell uname -a),)
14		platform = win
15	else ifneq ($(findstring MINGW,$(shell uname -a)),)
16		platform = win
17	else ifneq ($(findstring Darwin,$(shell uname -a)),)
18		platform = osx
19	else ifneq ($(findstring win,$(shell uname -a)),)
20		platform = win
21	endif
22endif
23
24LIBRETRO_DIR := libretro
25CORE_DIR := src
26
27prefix := /usr
28libdir := $(prefix)/lib
29
30LIBRETRO_INSTALL_DIR := libretro
31
32# system platform
33system_platform = unix
34ifeq ($(shell uname -a),)
35	EXE_EXT = .exe
36	system_platform = win
37else ifneq ($(findstring Darwin,$(shell uname -a)),)
38	system_platform = osx
39else ifneq ($(findstring MINGW,$(shell uname -a)),)
40	system_platform = win
41endif
42
43SPACE :=
44SPACE := $(SPACE) $(SPACE)
45BACKSLASH :=
46BACKSLASH := \$(BACKSLASH)
47filter_out1 = $(filter-out $(firstword $1),$1)
48filter_out2 = $(call filter_out1,$(call filter_out1,$1))
49unixpath = $(subst \,/,$1)
50unixcygpath = /$(subst :,,$(call unixpath,$1))
51
52# Unix
53ifneq (,$(findstring unix,$(platform)))
54	fpic := -fPIC
55	TARGET := $(TARGET_NAME)_libretro.so
56	SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
57	FRONTEND_SUPPORTS_XRGB8888 = 1
58
59# OS X
60else ifeq ($(platform),osx)
61	fpic := -fPIC
62	TARGET := $(TARGET_NAME)_libretro.dylib
63	SHARED := -dynamiclib
64	LIBS :=
65	OSXVER = `sw_vers -productVersion | cut -d. -f 2`
66	OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
67ifeq ($(OSX_LT_MAVERICKS),"YES")
68	fpic += -mmacosx-version-min=10.1
69else
70	fpic += -mmacosx-version-min=10.7 -stdlib=libc++
71endif
72	ifndef ($(NOUNIVERSAL))
73		CFLAGS  += $(ARCHFLAGS)
74		CXXFLAGS  += $(ARCHFLAGS)
75		LDFLAGS += $(ARCHFLAGS)
76	endif
77
78# iOS
79else ifneq (,$(findstring ios,$(platform)))
80
81	fpic := -fPIC
82	TARGET := $(TARGET_NAME)_libretro_ios.dylib
83	SHARED := -dynamiclib
84	ifeq ($(IOSSDK),)
85		IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
86	endif
87	ifeq ($(platform),ios-arm64)
88		CC = cc -arch arm64 -isysroot $(IOSSDK)
89		CXX = c++ -arch arm64 -isysroot $(IOSSDK)
90	else
91		CC = cc -arch armv7 -isysroot $(IOSSDK)
92		CXX = c++ -arch armv7 -isysroot $(IOSSDK)
93	endif
94	LIBS :=
95ifeq ($(platform),$(filter $(platform),ios9 ios-arm64))
96	SHARED += -miphoneos-version-min=8.0
97	CC +=  -miphoneos-version-min=8.0
98	CXX +=  -miphoneos-version-min=8.0
99else
100	SHARED += -miphoneos-version-min=5.0
101	CC +=  -miphoneos-version-min=5.0
102	CXX +=  -miphoneos-version-min=5.0
103endif
104
105# tvOS
106else ifeq ($(platform), tvos-arm64)
107	fpic := -fPIC
108	TARGET := $(TARGET_NAME)_libretro_tvos.dylib
109	SHARED := -dynamiclib
110	ifeq ($(IOSSDK),)
111		IOSSDK := $(shell xcodebuild -version -sdk appletvos Path)
112	endif
113	LIBS :=
114
115# Theos iOS
116else ifeq ($(platform), theos_ios)
117	DEPLOYMENT_IOSVERSION = 5.0
118	TARGET = iphone:latest:$(DEPLOYMENT_IOSVERSION)
119	ARCHS = armv7 armv7s
120	TARGET_IPHONEOS_DEPLOYMENT_VERSION=$(DEPLOYMENT_IOSVERSION)
121	THEOS_BUILD_DIR := objs
122	include $(THEOS)/makefiles/common.mk
123	LIBRARY_NAME = $(TARGET_NAME)_libretro_ios
124
125# QNX
126else ifeq ($(platform),qnx)
127	fpic := -fPIC
128	TARGET := $(TARGET_NAME)_libretro_$(platform).so
129	SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
130	CC = qcc -Vgcc_ntoarmv7le
131	CXX = QCC -Vgcc_ntoarmv7le_cpp
132
133# PS3
134else ifeq ($(platform),ps3)
135	TARGET := $(TARGET_NAME)_libretro_$(platform).a
136	CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
137	CXX = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-g++.exe
138	AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
139	FLAGS += -DMSB_FIRST
140	STATIC_LINKING := 1
141	LIBS :=
142
143# sncps3
144else ifeq ($(platform), sncps3)
145	TARGET := $(TARGET_NAME)_libretro_ps3.a
146	CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
147	CXX = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
148	AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
149	FLAGS += -DMSB_FIRST
150	STATIC_LINKING := 1
151	LIBS :=
152
153# PS2
154else ifeq ($(platform),ps2)
155	TARGET := $(TARGET_NAME)_libretro_$(platform).a
156	CC = mips64r5900el-ps2-elf-gcc$(EXE_EXT)
157	CXX = mips64r5900el-ps2-elf-g++$(EXE_EXT)
158	AR = mips64r5900el-ps2-elf-ar$(EXE_EXT)
159	FLAGS += -G0 -DPS2 -DABGR1555 -DHAVE_NO_LANGEXTRA
160	INCFLAGS_PLATFORM += -O3
161	STATIC_LINKING := 1
162	LIBS :=
163
164# PSP
165else ifeq ($(platform),psp1)
166	TARGET := $(TARGET_NAME)_libretro_$(platform).a
167	CC = psp-gcc$(EXE_EXT)
168	CXX = psp-g++$(EXE_EXT)
169	AR = psp-ar$(EXE_EXT)
170	FLAGS += -G0 -DPSP
171	INCFLAGS_PLATFORM += -O3
172	STATIC_LINKING := 1
173	LIBS :=
174
175# Vita
176else ifeq ($(platform),vita)
177	TARGET := $(TARGET_NAME)_libretro_$(platform).a
178	CC = arm-vita-eabi-gcc$(EXE_EXT)
179	CXX = arm-vita-eabi-g++$(EXE_EXT)
180	AR = arm-vita-eabi-ar$(EXE_EXT)
181	FLAGS += -DVITA -DLSB_FIRST
182	STATIC_LINKING := 1
183	LIBS :=
184
185# Nintendo Game Cube
186else ifeq ($(platform), ngc)
187	TARGET := $(TARGET_NAME)_libretro_$(platform).a
188	CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
189	CXX = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
190	AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
191	FLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
192	STATIC_LINKING = 1
193	LIBS :=
194
195# Nintendo Wii
196else ifeq ($(platform), wii)
197	TARGET := $(TARGET_NAME)_libretro_$(platform).a
198	CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
199	CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
200	AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
201	FLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
202	STATIC_LINKING = 1
203	LIBS :=
204
205# Nintendo Wiiu
206else ifeq ($(platform), wiiu)
207	TARGET := $(TARGET_NAME)_libretro_$(platform).a
208	CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
209	CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
210	AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
211	FLAGS += -DGEKKO -DWIIU -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
212	STATIC_LINKING = 1
213	LIBS :=
214
215# CTR (3DS)
216else ifeq ($(platform), ctr)
217	TARGET := $(TARGET_NAME)_libretro_$(platform).a
218	CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
219	CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
220	AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
221	PLATFORM_DEFINES := -DARM11 -D_3DS -DCC_RESAMPLER -DCC_RESAMPLER_NO_HIGHPASS
222	CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard
223	CFLAGS += -Wall -mword-relocations
224	CFLAGS += -fomit-frame-pointer -ffast-math
225	CXXFLAGS += $(CFLAGS)
226	STATIC_LINKING = 1
227
228# GCW0
229else ifeq ($(platform), gcw0)
230   TARGET := $(TARGET_NAME)_libretro.so
231   CC = /opt/gcw0-toolchain/usr/bin/mipsel-linux-gcc
232   CXX = /opt/gcw0-toolchain/usr/bin/mipsel-linux-g++
233   AR = /opt/gcw0-toolchain/usr/bin/mipsel-linux-ar
234   fpic := -fPIC
235   SHARED := -shared -Wl,--no-undefined -Wl,-version-script=$(LIBRETRO_DIR)/link.T
236   FLAGS += -DDINGUX -fomit-frame-pointer -ffast-math -march=mips32 -mtune=mips32r2 -mhard-float
237
238# Nintendo Switch (libnx)
239else ifeq ($(platform), libnx)
240	include $(DEVKITPRO)/libnx/switch_rules
241	EXT=a
242	TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
243	DEFINES := -DSWITCH=1 -U__linux__ -U__linux -DRARCH_INTERNAL
244	CFLAGS := $(DEFINES) -g -O3 -fPIE -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec -Wl,--allow-multiple-definition -specs=$(LIBNX)/switch.specs
245	CFLAGS += $(INCDIRS)
246	CFLAGS += $(INCLUDE)  -D__SWITCH__
247	CXXFLAGS := $(ASFLAGS) $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
248	CFLAGS += -std=gnu11
249	STATIC_LINKING = 1
250
251# Nintendo Switch (libtransistor)
252else ifeq ($(platform), switch)
253   TARGET := $(TARGET_NAME)_libretro_$(platform).a
254   include $(LIBTRANSISTOR_HOME)/libtransistor.mk
255   STATIC_LINKING=1
256
257# Classic Platforms ####################
258# Platform affix = classic_<ISA>_<µARCH>
259# Help at https://modmyclassic.com/comp
260
261# (armv7 a7, hard point, neon based) ###
262# NESC, SNESC, C64 mini
263else ifeq ($(platform), classic_armv7_a7)
264	TARGET := $(TARGET_NAME)_libretro.so
265	fpic := -fPIC
266    SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
267	FLAGS += -Ofast \
268	-flto=4 -fwhole-program -fuse-linker-plugin \
269	-fdata-sections -ffunction-sections -Wl,--gc-sections \
270	-fno-stack-protector -fno-ident -fomit-frame-pointer \
271	-falign-functions=1 -falign-jumps=1 -falign-loops=1 \
272	-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
273	-fmerge-all-constants -fno-math-errno \
274	-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
275	HAVE_NEON = 1
276	ARCH = arm
277	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
278	  CFLAGS += -march=armv7-a
279	else
280	  CFLAGS += -march=armv7ve
281	  # If gcc is 5.0 or later
282	  ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
283	    LDFLAGS += -static-libgcc -static-libstdc++
284	  endif
285	endif
286
287# (armv8 a35, hard point, neon based) ###
288# Playstation Classic
289else ifeq ($(platform), classic_armv8_a35)
290	TARGET := $(TARGET_NAME)_libretro.so
291	fpic := -fPIC
292    SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
293	FLAGS += -Ofast \
294	-flto=4 -fwhole-program -fuse-linker-plugin \
295	-fdata-sections -ffunction-sections -Wl,--gc-sections \
296	-fno-stack-protector -fno-ident -fomit-frame-pointer \
297	-falign-functions=1 -falign-jumps=1 -falign-loops=1 \
298	-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
299	-fmerge-all-constants -fno-math-errno \
300	-marm -mtune=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
301	HAVE_NEON = 1
302	ARCH = arm
303	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
304	CFLAGS += -march=armv8-a
305	else
306	CFLAGS += -march=armv8-a
307	  # If gcc is 5.0 or later
308	  ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
309	    LDFLAGS += -static-libgcc -static-libstdc++
310	  endif
311endif
312#######################################
313
314# ARM
315else ifneq (,$(findstring armv,$(platform)))
316	TARGET := $(TARGET_NAME)_libretro.so
317	SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
318	fpic := -fPIC
319	ifneq (,$(findstring cortexa5,$(platform)))
320		FLAGS += -marm -mcpu=cortex-a5
321	else ifneq (,$(findstring cortexa8,$(platform)))
322		FLAGS += -marm -mcpu=cortex-a8
323	else ifneq (,$(findstring cortexa9,$(platform)))
324		FLAGS += -marm -mcpu=cortex-a9
325	else ifneq (,$(findstring cortexa15a7,$(platform)))
326		FLAGS += -marm -mcpu=cortex-a15.cortex-a7
327	else
328		FLAGS += -marm
329	endif
330	ifneq (,$(findstring softfloat,$(platform)))
331		FLAGS += -mfloat-abi=softfp
332	else ifneq (,$(findstring hardfloat,$(platform)))
333		FLAGS += -mfloat-abi=hard
334	endif
335
336# Emscripten
337else ifeq ($(platform), emscripten)
338	TARGET := $(TARGET_NAME)_libretro_$(platform).bc
339	STATIC_LINKING = 1
340
341# Windows MSVC 2010 x64
342else ifeq ($(platform), windows_msvc2010_x64)
343	CC  = cl.exe
344	CXX = cl.exe
345
346PATH := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/bin/amd64"):$(PATH)
347PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../IDE")
348LIB := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/lib/amd64")
349INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/include")
350
351WindowsSdkDir := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')
352WindowsSdkDir ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')
353
354WindowsSdkDirInc := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
355WindowsSdkDirInc ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
356
357WindowsSDKIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include")
358WindowsSDKGlIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\gl")
359WindowsSDKLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\x64")
360
361INCFLAGS_PLATFORM = -I"$(WindowsSDKIncludeDir)"
362export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKGlIncludeDir)
363export LIB := $(LIB);$(WindowsSDKLibDir)
364TARGET := $(TARGET_NAME)_libretro.dll
365PSS_STYLE :=2
366LDFLAGS += -DLL
367
368# Windows MSVC 2010 x86
369else ifeq ($(platform), windows_msvc2010_x86)
370	CC  = cl.exe
371	CXX = cl.exe
372
373PATH := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/bin"):$(PATH)
374PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../IDE")
375LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS100COMNTOOLS)../../VC/lib")
376INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/include")
377
378WindowsSdkDir := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')
379WindowsSdkDir ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')
380
381WindowsSdkDirInc := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
382WindowsSdkDirInc ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
383
384WindowsSDKIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include")
385WindowsSDKGlIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\gl")
386WindowsSDKLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib")
387
388INCFLAGS_PLATFORM = -I"$(WindowsSDKIncludeDir)"
389export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKGlIncludeDir)
390export LIB := $(LIB);$(WindowsSDKLibDir)
391TARGET := $(TARGET_NAME)_libretro.dll
392PSS_STYLE :=2
393LDFLAGS += -DLL
394
395# Windows MSVC 2005 x86
396else ifeq ($(platform), windows_msvc2005_x86)
397	CC  = cl.exe
398	CXX = cl.exe
399
400PATH := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/bin"):$(PATH)
401PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../IDE")
402INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/include")
403LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS80COMNTOOLS)../../VC/lib")
404BIN := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/bin")
405
406WindowsSdkDir := $(shell reg query "HKLM\SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3" -v "Install Dir" | grep -o '[A-Z]:\\.*')
407
408WindowsSDKIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include")
409WindowsSDKAtlIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\atl")
410WindowsSDKCrtIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\crt")
411WindowsSDKGlIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\gl")
412WindowsSDKMfcIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\mfc")
413WindowsSDKLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib")
414
415export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKAtlIncludeDir);$(WindowsSDKCrtIncludeDir);$(WindowsSDKGlIncludeDir);$(WindowsSDKMfcIncludeDir);libretro-common/include/compat/msvc
416export LIB := $(LIB);$(WindowsSDKLibDir)
417TARGET := $(TARGET_NAME)_libretro.dll
418PSS_STYLE :=2
419LDFLAGS += -DLL
420CFLAGS += -D_CRT_SECURE_NO_DEPRECATE
421LIBS =
422
423# Windows MSVC 2003 Xbox 1
424else ifeq ($(platform), xbox1_msvc2003)
425TARGET := $(TARGET_NAME)_libretro_xdk1.lib
426CC  = CL.exe
427CXX  = CL.exe
428LD   = lib.exe
429
430export INCLUDE := $(XDK)/xbox/include
431export LIB := $(XDK)/xbox/lib
432PATH := $(call unixcygpath,$(XDK)/xbox/bin/vc71):$(PATH)
433PSS_STYLE :=2
434CFLAGS   += -D_XBOX -D_XBOX1
435CXXFLAGS += -D_XBOX -D_XBOX1
436STATIC_LINKING=1
437
438# Windows MSVC 2003 x86
439else ifeq ($(platform), windows_msvc2003_x86)
440	CC  = cl.exe
441	CXX = cl.exe
442
443PATH := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/bin"):$(PATH)
444PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../IDE")
445INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/include")
446LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS71COMNTOOLS)../../Vc7/lib")
447BIN := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/bin")
448
449WindowsSdkDir := $(INETSDK)
450
451export INCLUDE := $(INCLUDE);$(INETSDK)/Include;libretro-common/include/compat/msvc
452export LIB := $(LIB);$(WindowsSdkDir);$(INETSDK)/Lib
453TARGET := $(TARGET_NAME)_libretro.dll
454PSS_STYLE :=2
455LDFLAGS += -DLL
456CFLAGS += -D_CRT_SECURE_NO_DEPRECATE
457
458# Windows MSVC 2017 all architectures
459else ifneq (,$(findstring windows_msvc2017,$(platform)))
460
461   PlatformSuffix = $(subst windows_msvc2017_,,$(platform))
462   ifneq (,$(findstring desktop,$(PlatformSuffix)))
463      WinPartition = desktop
464      MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -FS
465      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
466      LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
467   else ifneq (,$(findstring uwp,$(PlatformSuffix)))
468      WinPartition = uwp
469      MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc -FS
470      LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
471      LIBS += WindowsApp.lib
472   endif
473
474   CFLAGS += $(MSVC2017CompileFlags) -DNOMINMAX
475   CXXFLAGS += $(MSVC2017CompileFlags) -DNOMINMAX
476
477   TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
478
479   CC  = cl.exe
480   CXX = cl.exe
481   LD = link.exe
482
483   reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
484   fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
485
486   ProgramFiles86w := $(shell cmd //c "echo %PROGRAMFILES(x86)%")
487   ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")
488
489   WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
490   WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
491   WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
492   WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
493   WindowsSdkDir := $(WindowsSdkDir)
494
495   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)
496   WindowsSDKVersion := $(WindowsSDKVersion)
497
498   VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
499   VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2017/Enterprise
500   VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2017/Professional
501   VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2017/Community
502
503   VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
504   ifeq ($(VsInstallRoot), )
505      VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
506   endif
507   ifeq ($(VsInstallRoot), )
508      VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
509   endif
510   ifeq ($(VsInstallRoot), )
511      VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
512   endif
513   VsInstallRoot := $(VsInstallRoot)
514
515   VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
516   VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)
517
518   WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
519   WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
520   WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
521   WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
522   WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")
523
524   # For some reason the HostX86 compiler doesn't like compiling for x64
525   # ("no such file" opening a shared library), and vice-versa.
526   # Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
527   # NOTE: What about ARM?
528   ifneq (,$(findstring x64,$(TargetArchMoniker)))
529      VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX64
530   else
531      VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX86
532   endif
533
534   PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)/$(TargetArchMoniker)"):$(PATH)
535   PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
536   INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
537   LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)")
538   ifneq (,$(findstring uwp,$(PlatformSuffix)))
539      LIB := $(LIB)/store;$(LIB)
540   endif
541
542   export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
543   export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
544   TARGET := $(TARGET_NAME)_libretro.dll
545   PSS_STYLE :=2
546   LDFLAGS += -DLL
547
548# Windows
549else
550	fpic :=
551	TARGET := $(TARGET_NAME)_libretro.dll
552	CC ?= gcc
553	CXX ?= g++
554	SHARED := -shared -static-libgcc -static-libstdc++ -Wl,-no-undefined -Wl,-version-script=$(LIBRETRO_DIR)/link.T
555	FRONTEND_SUPPORTS_XRGB8888 = 1
556
557endif
558
559CORE_DIR := .
560
561include Makefile.common
562
563OBJECTS := $(SOURCES_CXX:.cpp=.o)
564
565ifeq ($(DEBUG),1)
566FLAGS += -O0 -g
567else
568FLAGS += -O2 -DNDEBUG
569endif
570
571ifeq (,$(findstring msvc,$(platform)))
572FLAGS += -fomit-frame-pointer
573else
574ifeq ($(DEBUG),1)
575FLAGS += -MTd
576else
577FLAGS += -MT
578endif
579endif
580
581FLAGS += -I. $(fpic) $(libs) $(includes) -DWANT_CRC32
582ifneq (,$(findstring msvc,$(platform)))
583FLAGS += -D_CRT_SECURE_NO_DEPRECATE
584endif
585CXXFLAGS += $(FLAGS) $(INCFLAGS) $(INCFLAGS_PLATFORM)
586CFLAGS += $(FLAGS) $(INCFLAGS) $(INCFLAGS_PLATFORM)
587
588OBJOUT   = -o
589LINKOUT  = -o
590
591ifneq (,$(findstring msvc,$(platform)))
592	OBJOUT = -Fo
593	LINKOUT = -out:
594	LD = link.exe
595else
596	LD = $(CXX)
597endif
598
599%.o: %.cpp
600	$(CXX) -c $(OBJOUT)$@ $< $(CXXFLAGS)
601
602%.o: %.c
603	$(CC) -c $(OBJOUT)$@ $< $(CFLAGS)
604
605ifeq ($(platform), theos_ios)
606COMMON_FLAGS := -DIOS $(COMMON_DEFINES) -I$(THEOS_INCLUDE_PATH) -Wno-error
607$(LIBRARY_NAME)_CFLAGS += $(CFLAGS) $(COMMON_FLAGS)
608$(LIBRARY_NAME)_CXXFLAGS += $(CXXFLAGS) $(COMMON_FLAGS)
609${LIBRARY_NAME}_FILES = $(SOURCES_CXX) $(SOURCES_C)
610include $(THEOS_MAKE_PATH)/library.mk
611else
612all: $(TARGET)
613$(TARGET): $(OBJECTS)
614ifeq ($(STATIC_LINKING), 1)
615	$(AR) rcs $@ $(OBJECTS)
616else
617	$(LD) $(LINKOUT)$@ $(SHARED) $(OBJECTS) $(LDFLAGS) $(LIBS)
618endif
619
620clean-objs:
621	rm -f $(OBJECTS)
622
623clean:
624	rm -f $(OBJECTS)
625	rm -f $(TARGET)
626
627install:
628	install -D -m 755 $(TARGET) $(DESTDIR)$(libdir)/$(LIBRETRO_INSTALL_DIR)/$(TARGET)
629
630uninstall:
631	rm $(DESTDIR)$(libdir)/$(LIBRETRO_INSTALL_DIR)/$(TARGET)
632
633.PHONY: clean clean-objs all install uninstall
634endif
635