RetroArch/Makefile.msvc
orbea fb6fe1a87c Makefile: Better respect CFLAGS and CXXFLAGS as environment variables.
This fixes a few subtle problems with passing CFLAGS and CXXFLAGS as
environment variables for configure.

First it will now only add these variables to config.mk when they are
actually set. If they are unset then the default optimizations in the
Makefile are set. This avoids passing more than one conflicting
optimization level to the compiler.

Next all CFLAGS are added to CXXFLAGS to avoid issues with forgetting to
set both CFLAGS and CXXFLAGS. This results in the cxx compiler getting
passed several redundant optimization levels when both the CFLAGS and
CXXFLAGS environment variabls are used. Now these uses of CFLAGS in
Makefile.common are set to DEF_FLAGS. This allows adding $(DEF_FLAGS)
to the CXXFLAGS variable without adding redundant flags from CFLAGS.

v2: Update other build files.
2018-12-30 17:17:19 -08:00

264 lines
7.0 KiB
Makefile

TARGET := retroarch.exe
DEBUG = 0
GRIFFIN_BUILD = 0
OS = Win32
ARCH = amd64
#TARGET_ARCH = x86
BUILD_DIR = objs/msvc
CXX_BUILD = 0
WindowsSdkDir = C:\Program Files (x86)\Windows Kits\10\$(NOTHING)
WindowsSDKVersion := 10.0.14393.0\$(NOTHING)
VCINSTALLDIR := C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\$(NOTHING)
HAVE_D3DX := 1
HAVE_D3D8 := 0
HAVE_D3D9 := 1
HAVE_D3D10 := 1
HAVE_D3D11 := 1
HAVE_D3D12 := 1
HAVE_CG := 1
HAVE_OPENGL := 1
HAVE_VULKAN := 1
HAVE_XAUDIO := 1
HAVE_XINPUT := 1
HAVE_WASAPI := 0
HAVE_THREAD_STORAGE := 1
HAVE_WINMM := 1
HAVE_RPNG := 1
HAVE_ZLIB := 1
WANT_ZLIB := 1
HAVE_RGUI := 1
HAVE_XMB := 1
HAVE_MATERIALUI := 1
HAVE_STB_FONT := 1
HAVE_THREADS := 1
HAVE_LIBRETRODB := 1
HAVE_COMMAND := 1
HAVE_STDIN_CMD := 1
HAVE_CMD := 1
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_DINPUT := 1
HAVE_MENU_COMMON := 1
HAVE_BUILTINZLIB := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
HAVE_RTGA := 1
HAVE_7ZIP := 1
HAVE_NETWORKING := 1
HAVE_NETWORK_CMD := 1
HAVE_OVERLAY := 1
HAVE_LANGEXTRA := 1
HAVE_CHEEVOS := 1
HAVE_SHADERPIPELINE := 1
HAVE_IMAGEVIEWER := 1
include Makefile.common
INCLUDE_DIRS := $(patsubst -isystem%,-I%,$(INCLUDE_DIRS))
CFLAGS := $(filter-out -Wno-unknown-pragmas,$(DEF_FLAGS))
CXXFLAGS := $(filter-out -fpermissive -Wno-switch -Wno-sign-compare -fno-strict-aliasing -Wno-maybe-uninitialized -Wno-reorder -Wno-parentheses,$(CXXFLAGS))
LIBS := $(filter-out -lstdc++,$(LIBS))
ifeq ($(ARCH),x64)
ARCH := amd64
endif
ARCH2 := $(ARCH)
ifeq ($(ARCH),amd64)
ARCH2 := x64
endif
ifeq ($(TARGET_ARCH),)
TARGET_ARCH = $(ARCH)
endif
ifeq ($(TARGET_ARCH),x64)
TARGET_ARCH = amd64
endif
TARGET_ARCH2 = $(TARGET_ARCH)
ifeq ($(TARGET_ARCH2),amd64)
TARGET_ARCH2 = x64
endif
CROSS = $(ARCH)
ifeq ($(ARCH),x86)
CROSS =
endif
INCLUDE := $(VCINSTALLDIR)include;$(VCINSTALLDIR)atlmfc\include;$(WindowsSdkDir)include\$(WindowsSDKVersion)ucrt;$(WindowsSdkDir)include\$(WindowsSDKVersion)shared;$(WindowsSdkDir)include\$(WindowsSDKVersion)um;
LIB := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);$(WindowsSdkDir)lib\$(WindowsSDKVersion)ucrt\$(TARGET_ARCH2);$(WindowsSdkDir)lib\$(WindowsSDKVersion)um\$(TARGET_ARCH2);C:\Program Files (x86)\NVIDIA Corporation\Cg\lib.$(TARGET_ARCH2);C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Lib\$(TARGET_ARCH2);
LIBPATH := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);
PATH := $(shell IFS=$$'\n'; cygpath "$(VCINSTALLDIR)bin\\$(CROSS)"):$(shell IFS=$$'\n'; cygpath "$(WindowsSdkDir)\bin\\$(ARCH2)"):$(PATH)
export INCLUDE := $(INCLUDE)
export LIB := $(LIB)
export LIBPATH := $(LIBPATH)
export PATH := $(PATH)
#$(info WindowsSdkDir : $(WindowsSdkDir))
#$(info WindowsSDKVersion : $(WindowsSDKVersion))
#$(info VCINSTALLDIR : $(VCINSTALLDIR))
#$(info INCLUDE : $(INCLUDE))
#$(info LIB : $(LIB))
#$(info LIBPATH : $(LIBPATH))
#$(info PATH : $(PATH))
#$(error end)
DEFINES += -D__SSE__ -D__SSE2__
ifeq ($(TARGET_ARCH2),x64)
DEFINES += -D__x86_64__
else
#DEFINES += -D__i686__
endif
FLAGS += -nologo -MP
FLAGS += -Gm- -Zc:inline -fp:precise -Zc:forScope -GR- -Gd -Oi -volatile:iso
#FLAGS += -Zc:wchar_t -Zp16 -Z7
#FLAGS += -utf-8
#FLAGS += -source-charset:utf-8
CXXFLAGS += $(CFLAGS) -TP -EHsc
ifeq ($(CXX_BUILD),1)
CFLAGS := $(CXXFLAGS)
DEFINES += -DCXX_BUILD
else
CFLAGS += -TC
endif
WARNINGS += -WX -W3
WARNINGS += -wd4101 -wd4996 -wd4244 -wd4267 -wd4090 -wd4305 -wd4146 -wd4334 -wd4018 -wd4800 -wd4838
CC = cl.exe
CXX = cl.exe
LD = link.exe
RC = rc.exe
LIBS += shell32.lib user32.lib gdi32.lib comdlg32.lib winmm.lib ole32.lib
LDFLAGS += -nologo -wx -nxcompat -machine:$(TARGET_ARCH2)
ifeq ($(DEBUG),1)
FLAGS += -GS -Gy -Od -RTC1 -D_SECURE_SCL=1 -Zi
FLAGS += -MDd
LDFLAGS += -DEBUG
DEFINES += -DDEBUG -D_DEBUG
else
FLAGS += -GS- -Gy- -O2 -Ob2 -GF -GT -Oy -Ot -D_SECURE_SCL=0
FLAGS += -MD
endif
ifeq ($(DEBUG),1)
BUILD_DIR := $(BUILD_DIR)-debug
endif
ifeq ($(GRIFFIN_BUILD),1)
BUILD_DIR := $(BUILD_DIR)-griffin
endif
BUILD_DIR := $(BUILD_DIR)-$(TARGET_ARCH2)
ifneq ($(V), 1)
Q := @
endif
ifeq ($(GRIFFIN_BUILD), 1)
OBJ := griffin/griffin.o griffin/griffin_cpp.o
DEFINES += -DHAVE_GRIFFIN -DUSE_MATH_DEFINES
else
BLACKLIST :=
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
endif
DEFINES += -DRARCH_INTERNAL -DHAVE_DYNAMIC -DJSON_STATIC
INCLUDE_DIRS += -I. -Igfx/include
#OBJ := version_git.o
OBJ := $(patsubst %rarch.o,%rarch.res,$(OBJ))
OBJ := $(addprefix $(BUILD_DIR)/,$(OBJ))
OBJ := $(OBJ:.o=.obj)
LDFLAGS += -WX -SUBSYSTEM:WINDOWS -ENTRY:mainCRTStartup
DEFINES := $(patsubst -f%,,$(DEFINES))
LDFLAGS := $(patsubst -l%,%.lib,$(LDFLAGS))
LIBS := $(filter-out -lm,$(LIBS))
LIBS := $(patsubst -l%,%.lib,$(LIBS))
#$(info INCLUDE_DIRS : $(INCLUDE_DIRS))
#$(info DEFINES : $(DEFINES))
#$(info CFLAGS : $(CFLAGS))
#$(info CXXFLAGS : $(CXXFLAGS))
#$(info LDFLAGS : $(LDFLAGS))
#$(info LIBS : $(LIBS))
#$(info OBJ : $(OBJ))
#$(info target : $(TARGET))
#$(info flags : $(FLAGS))
#$(info INCLUDE : $(INCLUDE))
#$(info LIB : $(LIB))
#$(info LIBPATH : $(LIBPATH))
#$(error end)
$(info os : $(OS))
$(info host : $(ARCH))
$(info target : $(TARGET_ARCH))
all: $(TARGET)
%: $(BUILD_DIR)/%
cp $< $@
ifeq ($(DEBUG),1)
%.exe: $(BUILD_DIR)/%.exe
cp $< $@
cp $(BUILD_DIR)/$*.pdb $*.pbd
endif
SHELL:=$(SHELL) -o pipefail
DEPFLAGS = -showIncludes | tee $(BUILD_DIR)/$*.dtemp | sed /'Note: including file:'/d
MAKEDEPS = echo $@: $< \\ > $(BUILD_DIR)/$*.depend && \
grep 'Note: including file:' $(BUILD_DIR)/$*.dtemp \
| sed '/$(subst \,\\,$(WindowsSdkDir))/Id; /$(subst \,\\,$(VCINSTALLDIR))/Id; s/Note: including file:[ ]*//g; s/\\/\//g; s/ /\\ /g; s/.*/ & \\/g' \
>> $(BUILD_DIR)/$*.depend && \
rm -f $(BUILD_DIR)/$*.dtemp
#DEPFLAGS :=
#MAKEDEPS :=
$(BUILD_DIR)/%.obj: %.cpp
@mkdir -p $(dir $@)
$(Q)$(CXX) -c -Fo:$@ $< $(FLAGS) $(CXXFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
$(BUILD_DIR)/%.obj: %.c
@mkdir -p $(dir $@)
$(Q)$(CC) -c -Fo:$@ $< $(FLAGS) $(CFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
$(BUILD_DIR)/%.res: %.rc
@mkdir -p $(dir $@)
$(Q)$(RC) $<
$(Q)mv $*.res $@
$(BUILD_DIR)/$(TARGET): $(OBJ) .$(TARGET).last
@touch .$(TARGET).last
$(Q)$(LD) $(OBJ) $(LDFLAGS) $(LIBS) -out:$(BUILD_DIR)/$(TARGET)
%.h %.hpp %.depend %.last: ;
clean:
rm -f $(OBJ) $(TARGET)
rm -f $(BUILD_DIR)/$(TARGET)
rm -f .$(TARGET).last
rm -f $(OBJ:.obj=.depend)
.PHONY: clean all
.PRECIOUS: %.depend %.last
-include $(patsubst %.obj,%.depend,$(filter %.obj,$(OBJ)))