#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution. 
#*************************************************************************
# CONFIG.Host.WIN32
#
#  This file is maintained by the EPICS community.
#  Sites may override these definitions in CONFIG_SITE.WIN32
 
#
# You currently get Visual C++ even if you ask for GNU.
#
# !! borlund support needed here !!
#
ANSI = ACC
CPLUSPLUS = CCC

#
# "\ " forces gnu make to keep this as one token
#
MSVISC = c:\\Program\ Files\\DevStudio\\Vc
WINLINK = link

RCCMD = rc -l 0x409 -i . -i .. -I$(INSTALL_INCLUDE)/os/$(OS_CLASS) -I$(INSTALL_INCLUDE) $(INSTALL_INCLUDES) -I$(EPICS_BASE_INCLUDE)/os/$(OS_CLASS) -I$(EPICS_BASE_INCLUDE) -fo $@ $<

ARCMD = lib /nologo /verbose /out:$@

#
# Configure OS vendor C compiler
ACC = cl

#
# __STDC__=0 is a real great idea of Jeff that gives us both:
# 1) define STDC for EPICS code (pretend ANSI conformance)
# 2) set it to 0 to use MS C "extensions" (open for _open etc.)
# because MS uses:   if __STDC__ ... disable many nice things
#
# Use of /Za would dissable DLL import/export keywords which
# EPICS include/excludes using architecture neutral macros
ACC_ANSI = $(ACC) /nologo /D__STDC__=0
ACC_STRICT = $(ACC) /nologo /D__STDC__=0
ACC_TRAD = $(ACC) /nologo

#
# /W<N> use warning level N
# (maximum (lint type) warnings at level 4)
ACC_WARN_YES = /W3
ACC_WARN_NO =  /W1

#
# /Ox maximum optimizations
# /MD use MSVCRT (run-time as DLL, multi-thread support)
ACC_OPT_YES = /Ox

#
# /Zi include debugging info in object files
# /Fr create source browser file
ACC_OPT_NO = /Zi 

#
# the following options are required when
# vis c++ compiles the code (and includes
# the header files)
#
# /MT static multithreaded C RTL
# /MTd static multithreaded C RTL (debug version)
# /MD multithreaded C RTL in DLL
# /MDd multithreaded C RTL in DLL (debug version)
VISC_EPICS_DLL_NO = -DEPICS_DLL_NO
VISC_EPICS_DLL_YES = 
VISC_EPICS_DLL = $(VISC_EPICS_DLL_$(SHARED_LIBRARIES))
VISC_SFLAGS_DEBUG_NO = d
VISC_SFLAGS_DEBUG_YES =
VISC_SFLAGS_DEBUG = $(VISC_SFLAGS_DEBUG_$(HOST_OPT))
ACC_SFLAGS_YES= /MT$(VISC_SFLAGS_DEBUG) $(VISC_EPICS_DLL)
ACC_SFLAGS_NO= /MD$(VISC_SFLAGS_DEBUG) $(VISC_EPICS_DLL)

#
# no special libs for static link
#
ACC_SLIBS_YES= 
ACC_SLIBS_NO=

# Configure OS vendor C++ compiler
#
# __STDC__=0 is a real great idea of Jeff that gives us both:
# 1) define STDC for EPICS code (pretend ANSI conformance)
# 2) set it to 0 to use MS C "extensions" (open for _open etc.)
# because MS uses:   if __STDC__ ... disable many nice things
#
# Use of /Za would dissable DLL import/export keywords which
# EPICS include/excludes using architecture neutral macros
#
# /EHsc support C++ exceptions
# /GR generate RTTI information
#
CCC = cl /EHsc /GR
CCC_NORMAL = $(CCC) /nologo /D__STDC__=0
CCC_STRICT = $(CCC) /nologo /D__STDC__=0
CCC_TEMPL_INST_FLAG =
ARCH_DEP_CPPFLAGS += /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE

#
# /W<N> use warning level N
# (maximum lint level warnings at level 4)
CCC_WARN_YES = /W3
CCC_WARN_NO =  /W1

#
# /Ox maximum optimizations
CCC_OPT_YES = /Ox

#
# /Zi include debugging info in object files
# /Fr create source browser file
CCC_OPT_NO = /Zi 

#
# the following options are required when
# vis c++ compiles the code (and includes
# the header files)
#
# /MT static multithreaded C RTL
# /MTd static multithreaded C RTL (debug version)
# /MD multithreaded C RTL in DLL
# /MDd multithreaded C RTL in DLL (debug version)
CCC_SFLAGS_YES= /MT$(VISC_SFLAGS_DEBUG) $(VISC_EPICS_DLL)
CCC_SFLAGS_NO= /MD$(VISC_SFLAGS_DEBUG) $(VISC_EPICS_DLL)

#
# no special libs for static link
#
CCC_SLIBS_YES=
CCC_SLIBS_NO=

LINK_OPT_FLAGS_YES = /warn:3 /incremental:no /opt:ref\
/release $(PROD_VERSION:%=/version:%)
LINK_OPT_FLAGS_NO = /warn:3 /debug /incremental:no
OPT_LDFLAGS = $(LINK_OPT_FLAGS_$(HOST_OPT))

ARCH_DEP_CFLAGS=

#	to identify the general architecture class:
#	should be BSD, SYSV, WIN32, ...
#	is: WIN32, sun4, hpux, linux, ...
#
ARCH_CLASS=WIN32

#	ifdef WIN32   looks better that  ifeq ($(ARCH_CLASS),WIN32)  ??
WIN32=1

EXE=.exe
OBJ=.obj
RES=.res

#       Problem: MS Visual C++ does not recognize  *.cc as C++ source,
#       we have to compile xx.cc  using the flag -Tp xx.cc,
#       i.e.  -Tp  has to be immediately before the source file name
SOURCE_CXXFLAG = /Tp

#	Operating system flags 
OP_SYS_CFLAGS =

#
# WIN32 specific include files
#
#OP_SYS_INCLUDES = -I$(EPICS_BASE_INCLUDE)\\os\\WIN32

#
# These are now added to the individual makefiles that use them in order to
# speed up the build
#
#OP_SYS_LDLIBS = user32.lib kernel32.lib advapi32.lib winmm.lib
OP_SYS_LDLIBS = 

#	Files and flags needed to link DLLs (used in RULES.Host)
#
#	Strange but seems to work without: WIN32_DLLFLAGS should contain
#	an entry point:
#		'-entry:_DllMainCRTStartup$(DLLENTRY)'
DLLENTRY = @12

WIN32_DLLFLAGS = /subsystem:windows /dll $(OPT_LDFLAGS)

#
# specify dll .def file only if it exists
#
DLL_DEF_FLAG = $(addprefix /def:,$(wildcard ../$(LIBRARY).def))

#	HOST_OPT_FLAGS is part of CFLAGS/CXXFLAGS,
#	which in turn are used in COMPILE.c[c]
#
#	If we compile a .c, .cc into an $(OBJ),
#	we test if this object is part of the 
#	library objects LIBOBJS.
#	If so, we define _WINDLL so that
#	e.g. include/shareLib.h works correctly.
#
HOST_OPT_FLAGS += $(subst $@, /_WINDLL, $(findstring $@,$(LIBOBJS)))

#
#	A WIN32 dll has three parts:
#	x.dll: the real dll (SHRLIBNAME)
#	x.lib: what you link to progs that use the dll (LIBNAME)
#	x.exp: what you need to build the dll (in no variable)
#
LINK.shrlib = $(WINLINK) /nologo $(WIN32_DLLFLAGS) /implib:$(DLL_LINK_LIBNAME) /out:$(SHRLIBNAME) $(DLL_DEF_FLAG)

#	adjust names of libraries to build
#
#	But: if there are no objects LIBOBJS to include
#	in this library (may be for e.g. base/src/libCompat
#	on some archs), don't define (and build) any library!
SHRLIBNAME = $(LIBRARY).dll

#
# Under WIN32 we have the unique situation where the DLL link creates the
# DLL link library xxx.lib and we need to be very careful to avoid replacing
# the xxx.lib created by the dll link with an xxx.lib created by $(AR).
# Therefore, the object library is named xxxObj.lib
#
# SHARED_LIBRARIES is YES if we are building a DLL and NO if we aren't
#
DLL_LINK_LIBNAME_YES = $(LIBRARY).lib
DLL_LINK_LIBNAME = $(DLL_LINK_LIBNAME_$(SHARED_LIBRARIES))
LIBNAME = $(LIBRARY)Obj.lib

#	dll install location
INSTALL_SHRLIB = $(INSTALL_BIN)

#--------------------------------------------------
# Dependancy definitions
OBJECT_LIB_EXT_YES = Obj.lib # object library extension for static build
OBJECT_LIB_EXT_NO = .lib # object library extension for dynamic build
OBJECT_LIB_EXT = $(OBJECT_LIB_EXT_$(STATIC_BUILD))
COND_PROD_DEPLIBS = $(foreach prod,$(PROD), $(foreach lib, $($(basename $(prod))_LIBS),\
 $(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib)$(OBJECT_LIB_EXT)))
PRODNAME_DEPLIBS = $(foreach lib,$(PRODNAME_LIBS),$(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib)$(OBJECT_LIB_EXT))
PROD_DEPLIBS = $(foreach lib,$(PROD_LIBS),$(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib)$(OBJECT_LIB_EXT))

USR_DEPLIBS = $(foreach lib,$(USR_LIBS),$(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib)$(OBJECT_LIB_EXT))

# by default the libraries used when linking the DLL are just
# PROD_LIBS ans SYS_PROD_LIBS minus the DLL name
DLL_LIBS = $(patsubst $(LIBRARY),, $(PROD_LIBS))
 
#
#	EPICS libs that we need to link the DLL with
#	(it isnt necessary to rebuild the dll if these change)
DLL_DEPLIBS = $(foreach lib,$(DLL_LIBS),$(firstword $($(lib)_DIR) $(EPICS_BASE_LIB))/$(lib).lib)

USR_LDLIBS = $(PRODNAME_DEPLIBS) $(PROD_DEPLIBS) $(USR_DEPLIBS) $(SYS_PROD_LIBS:%=%.lib)

DLL_LDLIBS = $(DLL_DEPLIBS) $(SYS_PROD_LIBS:%=%.lib) $(OP_SYS_LDLIBS)

LINK.c = $(WINLINK) -nologo $(LDFLAGS) -out:$@
LINK.cc = $(WINLINK) -nologo $(LDFLAGS) -out:$@

#--------------------------------------------------
# Determine ld flags
#USR_DIRS = $(dir $(PRODNAME_DEPLIBS)) $(dir $(PROD_DEPLIBS))\
# $(dir $(USR_DEPLIBS))
#USR_LDFLAGS += $(sort $(USR_DIRS:%=-L%))

# Overrides for CONFIG_COMMON default
POSIX_CPPFLAGS_YES = 

#--------------------------------------------------
# UseManifestTool.pl checks MS Visual c++ compiler version number to
# decide whether or not to use the Manifest Tool command to embed the
# linker created .manifest file into a library or product target.
# useManifestTool.pl returns 0(don't use) or 1(use).
#
ifeq ($(shell $(PERL) $(EPICS_BASE_TOOLS)/useManifestTool.pl),1)
MT_DLL_COMMAND = mt.exe /manifest $@.manifest "/outputresource:$@;\#2"
MT_EXE_COMMAND = mt.exe /manifest $@.manifest "/outputresource:$@;\#1"
endif

