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