###############################################################################
# File:         TOOLSET/CSHARP2015.DEF
# Contents:     Visual Studio .NET 2015 C# defines
###############################################################################

toolset		= csharp2012

o		= 
s		= asm
a		= netmodule
exe		= .exe

.SUFFIXES:	.asm

#
#   Setup the basic .NET environment paths
#   This is taken from "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
#
#   Cannot use vsvars.bat data imported from the environment as it
#   will conflict with other versions of MS
#
#   The following are the default installed locations
#   Currently assume default installation of Visual Studio 2015
#
PROGRAMFILES        ?= C:/Program Files
WINDIR              ?= C:/WINDOWS

CommandPromptType   := Native
Platform            := X86

UCRTVersion         :=  10.0.10240.0
VisualStudioVersion :=  14.0
WindowsSDKLibVersion:=  winv6.3


VSINSTALLDIR        ?=  $(PROGRAMFILES)/Microsoft Visual Studio $(VisualStudioVersion)
VCINSTALLDIR        ?=  $(VSINSTALLDIR)/VC

FrameworkVersion    ?= v4.0.30319
FrameworkVersion32  ?= $(FrameworkVersion)
FrameworkDir32      ?= $(WINDIR)/Microsoft.NET/Framework
FrameworkDir        ?= $(FrameworkDir32)

UniversalCRTSdkDir  ?=  $(PROGRAMFILES)/Windows Kits/10
WindowsSdkDir       ?=  $(PROGRAMFILES)/Windows Kits/8.1
NETFXSDKDir         ?=  $(PROGRAMFILES)/Windows Kits/NETFXSDK/4.6.1
CheckWindowsSdkDir  ?=  $(WindowsSdkDir)/include/winrt

DevEnvDir           :=  $(VSINSTALLDIR)/Common7/IDE
MSVCDir             :=  $(VCINSTALLDIR)/VC

WindowsSDK_ExecutablePath_x86 := $(PROGRAMFILES)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.6.1 Tools
WindowsSDK_ExecutablePath_x64 := $(WindowsSDK_ExecutablePath_x86)/x64

WindowsSDK_ExecutablePath_x86 := $(subst \,/,$(patsubst %\,%,$(WindowsSDK_ExecutablePath_x86)))
WindowsSDK_ExecutablePath_x64 := $(subst \,/,$(patsubst %\,%,$(WindowsSDK_ExecutablePath_x64)))
export WindowsSDK_ExecutablePath_x86 WindowsSDK_ExecutablePath_x64

# Clean up directory paths and remove trailing backslash
VSINSTALLDIR        := $(subst \,/,$(patsubst %\,%,$(VSINSTALLDIR)))
VCINSTALLDIR        := $(subst \,/,$(patsubst %\,%,$(VCINSTALLDIR)))
UniversalCRTSdkDir  := $(subst \,/,$(patsubst %\,%,$(UniversalCRTSdkDir)))
FrameworkDir        := $(subst \,/,$(patsubst %\,%,$(FrameworkDir)))
FrameworkDir32      := $(subst \,/,$(patsubst %\,%,$(FrameworkDir32)))
WindowsSdkDir       := $(subst \,/,$(patsubst %\,%,$(WindowsSdkDir)))
NETFXSDKDir         := $(subst \,/,$(patsubst %\,%,$(NETFXSDKDir)))
CheckWindowsSdkDir  := $(subst \,/,$(patsubst %\,%,$(CheckWindowsSdkDir)))

DevEnvDir           := $(subst \,/,$(patsubst %\,%,$(DevEnvDir)))
MSVCDir             := $(subst \,/,$(patsubst %\,%,$(MSVCDir)))

# Check for required update installed
GBE_VS2015_ENVVER   ?= HKCU/SOFTWARE/Microsoft/VisualStudio/14.0_Config/SplashInfo/EnvVersion

GBE_VS2015_ENVVAL3   ?= 14.0.25431.01 Update 3
GBE_VS2015_ENVVAL4   ?= 14.0.25425.01 Update 4
 

# Verify environment variable requirements
.PHONY:		csharp
csharp:
  ifndef GBE_NOTOOLSTEST
	    $(AA_PRE)$(echo) '[Toolset VCWIN32 - Visual Studio .NET 2015]'; \
	    if [ ! -d "$(VSINSTALLDIR)" ]; then echo "Directory VSINSTALLDIR does not exist: $(VSINSTALLDIR)"; exit 2; fi; \
	    if [ ! -d "$(VCINSTALLDIR)" ]; then echo "Directory VCINSTALLDIR does not exist: $(VCINSTALLDIR)"; exit 2; fi; \
	    if [ ! -d "$(FrameworkDir)" ]; then echo "Directory FrameworkDir does not exist: $(FrameworkDir)"; exit 2; fi; \
	    if [ ! -d "$(FrameworkDir)/$(FrameworkVersion)" ]; then echo "Directory FrameworkVersion does not exist: $(FrameworkVersion)"; exit 2; fi; \
	    if [ ! -d "$(WindowsSdkDir)" ]; then echo "Directory WindowsSdkDir does not exist: $(WindowsSdkDir)"; exit 2; fi ; \
	    if [ ! -d "$(CheckWindowsSdkDir)" ]; then echo "Directory Check WindowsSdkDir does not exist: $(CheckWindowsSdkDir)"; exit 2; fi ; \
		checkReg "-key:$(GBE_VS2015_ENVVER)" "-value:$(GBE_VS2015_ENVVAL3)" && update3=1 ;\
		checkReg "-key:$(GBE_VS2015_ENVVER)" "-value:$(GBE_VS2015_ENVVAL4)" && update4=1 ;\
	    if [ "$${update3}$${update4}" ]; then true; else echo "VS2015 Update 3 or 4 not installed"; exit 2; fi;
  endif

VISUALC		:= $(subst \,/,$(strip $(MSVCDir)))
visualc		:= $(subst $(space),$(spacealt),$(subst \,/,$(strip $(MSVCDir))))

#
#   Setup PATH, VC_LIB and INCLUDE for the SDK
#
NET_PATH:=$(DevEnvDir)/CommonExtensions/Microsoft/TestWindow
NET_PATH:=$(NET_PATH);$(PROGRAMFILES)/MSBuild/$(VisualStudioVersion)/bin
NET_PATH:=$(NET_PATH);$(DevEnvDir)/
NET_PATH:=$(NET_PATH);$(VCINSTALLDIR)/BIN
NET_PATH:=$(NET_PATH);$(VSINSTALLDIR)/Common7/Tools
NET_PATH:=$(NET_PATH);$(FrameworkDir)/$(FrameworkVersion)
NET_PATH:=$(NET_PATH);$(VCINSTALLDIR)/VCPackages
NET_PATH:=$(NET_PATH);$(PROGRAMFILES)/HTML Help Workshop
NET_PATH:=$(NET_PATH);$(VSINSTALLDIR)/Team Tools/Performance Tools
NET_PATH:=$(NET_PATH);$(WindowsSdkDir)/bin/x86
NET_PATH:=$(NET_PATH);$(WindowsSDK_ExecutablePath_x86)/
NET_PATH:= $(subst \,/,$(strip $(NET_PATH)))

ifeq "$(findstring $(NET_PATH),$(PATH))" ""
PATH    := $(NET_PATH);$(PATH)
endif
Path    := $(PATH)
export PATH

INCLUDE:=$(VCINSTALLDIR)/INCLUDE
INCLUDE:=$(INCLUDE);$(VCINSTALLDIR)/ATLMFC/INCLUDE
INCLUDE:=$(INCLUDE);$(UniversalCRTSdkDir)/include/$(UCRTVersion)/ucrt
INCLUDE:=$(INCLUDE);$(NETFXSDKDir)/include/um
INCLUDE:=$(INCLUDE);$(WindowsSdkDir)/include/shared
INCLUDE:=$(INCLUDE);$(WindowsSdkDir)/include/um
INCLUDE:=$(INCLUDE);$(WindowsSdkDir)/include/winrt

export INCLUDE

LIB :=
export LIB

VC_LIB:=$(VCINSTALLDIR)/LIB
VC_LIB:=$(VC_LIB);$(VCINSTALLDIR)/ATLMFC/LIB
VC_LIB:=$(VC_LIB);$(UniversalCRTSdkDir)/lib/$(UCRTVersion)/ucrt/x86
VC_LIB:=$(VC_LIB);$(NETFXSDKDir)/lib/um/x86
VC_LIB:=$(VC_LIB);$(WindowsSdkDir)/lib/$(WindowsSDKLibVersion)/um/x86

# Don't know if this needs to be used at all
# Derived from LIBPATH

LIBPATH:=$(FrameworkDir)/$(FrameworkVersion)
LIBPATH:=$(LIBPATH);$(VCINSTALLDIR)/LIB
LIBPATH:=$(LIBPATH);$(VCINSTALLDIR)/ATLMFC/LIB
LIBPATH:=$(LIBPATH);$(WindowsLibPath)
LIBPATH:=$(LIBPATH);/Microsoft.VCLibs/$(VisualStudioVersion)/References/CommonConfiguration/neutral
export LIBPATH

# rpcgen configuration
#
RPCGEN_CPP	:= cl
RPCGEN_CFLAGS	:= -EP
export RPCGEN_CPP RPCGEN_CFLAGS

#
