# Copyright (c) 2005-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
#

# Per-build Makefile rules (for recursive $(MAKE) calls from Makefile)

# Base compile/link options
MYCXXFLAGS = /nologo /EHsc /Zc:forScope /D WIN32 /D _MBCS /D _CRT_SECURE_NO_DEPRECATE /MP $(CXXFLAGS)
MYLFLAGS = /link /incremental:no /fixed:no $(LFLAGS)
CXXFLAGS_NDEBUG = /MD /O2 /Ot /Gy /D NDEBUG
CXXFLAGS_DEBUG = /MDd /Od /Zi /D _DEBUG

# Specify library directory for Direct X SDK
DDLIB_DIR=$(DXSDK_DIR)\lib\$(XARCH:AMD64=x64)

# Input and output files
#SOURCE = v
#RCNAME = specified externaly
#EXE =    ^
# defaults on XARCH = x86
UISRC = ../../common/gui/$(UI)video.cpp

default:

build_echo:
	-@echo Building$(DEBUG) $(EXE) with UI=$(UI) XARCH=$(XARCH)

build_one:	build_echo build_$(UI)$(DEBUG)

build_con: $(SOURCE) $(UISRC) compiler_check
	$(CXX) $(CXXFLAGS_NDEBUG) $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) /subsystem:console /OUT:$(EXE)
	@cmd.exe /C del *.obj

build_con_debug: $(SOURCE) $(UISRC) compiler_check
	$(CXX) $(CXXFLAGS_DEBUG) $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) /debug /subsystem:console /OUT:$(EXE)
	@cmd.exe /C del *.obj

build_gdi: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
	$(CXX) $(CXXFLAGS_NDEBUG) /D _WINDOWS $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) msvs/$(RCNAME).res /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
	@cmd.exe /C del *.obj

build_gdi_debug: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
	$(CXX) $(CXXFLAGS_DEBUG) /D _WINDOWS $(MYCXXFLAGS) $(SOURCE) $(UISRC) $(MYLFLAGS) msvs/$(RCNAME).res /debug /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
	@cmd.exe /C del *.obj

build_d2d: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
	-@echo Using DirectX SDK from "$(DDLIB_DIR)"
	$(CXX) $(CXXFLAGS_NDEBUG) /D _WINDOWS $(MYCXXFLAGS) /I "$(DXSDK_DIR)\include" $(SOURCE) $(UISRC) $(MYLFLAGS) /LIBPATH:"$(DDLIB_DIR)" msvs/$(RCNAME).res /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
	@cmd.exe /C del *.obj

build_d2d_debug: $(SOURCE) $(UISRC) msvs/$(RCNAME).res compiler_check
	-@echo Using DirectX SDK from "$(DDLIB_DIR)"
	$(CXX) $(CXXFLAGS_DEBUG) /D _WINDOWS $(MYCXXFLAGS) /I "$(DXSDK_DIR)\include" $(SOURCE) $(UISRC) $(MYLFLAGS) /LIBPATH:"$(DDLIB_DIR)" msvs/$(RCNAME).res /debug /subsystem:windows /machine:$(XARCH) /OUT:$(EXE)
	@cmd.exe /C del *.obj

msvs/$(RCNAME).res:
	rc /r msvs/$(RCNAME)
compiler_check:
	@echo compiler_test>compiler_test && @$(CXX) /E compiler_test >nul 2>&1  || echo "$(CXX) command not found. Check if CXX=$(CXX) is set properly"
	@cmd.exe /C del compiler_test
