# CONFIG.win32-x86.win32-x86
#
# Definitions for win32-x86 host - win32-x86 target build
# Override these definitions in CONFIG_SITE.win32-x86.win32-x86
#-------------------------------------------------------

# Win32 valid build types and include directory suffixes

VALID_BUILDS = Host Ioc

OPT_WHOLE_PROGRAM = YES

# convert UNIX path to native path
PATH_FILTER = $(subst /,\\,$(1))

#-------------------------------------------------------

#
# "\ " forces gnu make to keep this as one token
#
WINLINK = link

RCCMD = rc -l 0x409 $(INCLUDES) -fo $@ $<

ARCMD = lib -nologo -verbose -out:$@ $(LIB_OPT_LDFLAGS) $(LIBRARY_LD_OBJS)

BAFCMD = bscmake /nologo /o $@

#
# Configure OS vendor C compiler
CC = cl

# Override CONFIG.gnuCommon settings for cross builds.
GNU = NO
HDEPENDS_METHOD = CMD

# Compiler flags for C files (C++ is below)

#
# -W<d> display warnings at level d
#    -W4 is for maximum (lint type) warnings
#    -W3 is for production quality warnings
#    -W2 displays significant warnings
#    -W1 is the default and shows severe warnings only
# -w<d><n> Set warning C<n> to be shown at level <d>
WARN_CFLAGS_YES = -W3
WARN_CFLAGS_NO  = -W1

#
# -Ox maximum optimizations
# -GL whole program optimization
# -Oy- re-enable creation of frame pointers
OPT_CFLAGS_YES_YES = -Ox -GL -Oy-
OPT_CFLAGS_YES_NO = -Ox -Oy-
OPT_CFLAGS_YES = $(OPT_CFLAGS_YES_$(OPT_WHOLE_PROGRAM))

#
# -Zi generate program database for debugging information
# -RTCsu enable run-time error checks
OPT_CFLAGS_NO = -Zi -RTCsu

# specify object file name and location
OBJ_CFLAG = -Fo

#
# 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_DLL_NO = -DEPICS_DLL_NO
VISC_DLL_YES =
VISC_DLL = $(VISC_DLL_$(SHARED_LIBRARIES))
VISC_STATIC_CFLAGS_DEBUG_NO = d
VISC_STATIC_CFLAGS_DEBUG_YES =
VISC_STATIC_CFLAGS_DEBUG = $(VISC_STATIC_CFLAGS_DEBUG_$(HOST_OPT))
STATIC_CFLAGS_YES= -MT$(VISC_STATIC_CFLAGS_DEBUG) $(VISC_DLL)
STATIC_CFLAGS_NO= -MD$(VISC_STATIC_CFLAGS_DEBUG) $(VISC_DLL)

# OS vendor c preprocessor
CPP = cl -nologo -C -E

# Configure OS vendor C++ compiler
#
# -EHsc - generate code for exceptions
# -GR - generate code for run time type identification
#
CCC = cl -EHsc -GR

# Other compiler flags, used for CPP, C and C++
#
# -FC - Show absolute path of source file in diagnostics
# -D__STDC__=0 gives us both:
#   1) define STDC for 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
#
CODE_CPPFLAGS += -nologo -FC -D__STDC__=0
CODE_CPPFLAGS += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE


# Compiler flags for C++ files

#
# -W<n> disable warnings from levels > n
# -w<n><m> set warning m to level n
# -w44355 "'this' used in the base initializer list"
# -w44344 "behavior change: use of explicit template arguments results in ..."
# -w44251 "class needs to have dll-interface to be used by clients of ..."
WARN_CXXFLAGS_YES = -W3 -w44355 -w44344 -w44251
WARN_CXXFLAGS_NO  = -W1

#
# -Ox maximum optimizations
# -GL whole program optimization
# -Oy- re-enable creation of frame pointers
OPT_CXXFLAGS_YES_YES = -Ox -GL -Oy-
OPT_CXXFLAGS_YES_NO = -Ox -Oy-
OPT_CXXFLAGS_YES = $(OPT_CXXFLAGS_YES_$(OPT_WHOLE_PROGRAM))

#
# -Zi generate program database for debugging information
# -RTCsu enable run-time error checks
OPT_CXXFLAGS_NO = -RTCsu -Zi

# specify object file name and location
OBJ_CXXFLAG = -Fo

#
# 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)
STATIC_CXXFLAGS_YES= -MT$(VISC_STATIC_CFLAGS_DEBUG) $(VISC_DLL)
STATIC_CXXFLAGS_NO= -MD$(VISC_STATIC_CFLAGS_DEBUG) $(VISC_DLL)

STATIC_LDLIBS_YES=ws2_32.lib advapi32.lib user32.lib kernel32.lib winmm.lib
STATIC_LDLIBS_NO=
STATIC_LDFLAGS=
RANLIB=

#
# option needed for parallel builds with Visual Studio 2015 onward
#
# -FS Force Synchronous PDB Writes
ifneq ($(VisualStudioVersion),)
  OPT_CXXFLAGS_NO += -FS
  OPT_CFLAGS_NO += -FS
endif


#
# add -profile here to run the ms profiler
# -LTCG whole program optimization
# -incremental:no full linking
# -fixed:no generate relocatable code
# -version:<major>.<minor> - only 2 components allowed, 0-65535 each
# -debug generate debugging info
LINK_OPT_FLAGS_WHOLE_YES = -LTCG
LINK_OPT_FLAGS_YES = $(LINK_OPT_FLAGS_WHOLE_$(OPT_WHOLE_PROGRAM))
LINK_OPT_FLAGS_YES += -incremental:no -opt:ref
LINK_OPT_FLAGS_YES += -release $(PROD_VERSION:%=-version:%)
LINK_OPT_FLAGS_NO = -debug -incremental:no -fixed:no
OPT_LDFLAGS = $(LINK_OPT_FLAGS_$(HOST_OPT))

LIB_OPT_FLAGS_YES = $(LINK_OPT_FLAGS_WHOLE_$(OPT_WHOLE_PROGRAM))
LIB_OPT_LDFLAGS = $(LIB_OPT_FLAGS_$(HOST_OPT))

ARCH_DEP_CFLAGS=
SHRLIB_CFLAGS=

OS_CLASS=WIN32
POSIX=NO

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

EXE=.exe
OBJ=.obj
RES=.res
BAF=.bsc
BOF=.sbr

#       Problem: MS Visual C++ does not recognize  *.cc as C++ source,
#       so we do C++ compiles using the global flag -TP
COMPILER_CXXFLAGS = -TP

#	Operating system flags
OP_SYS_CFLAGS =
OP_SYS_CXXFLAGS = $(COMPILER_CXXFLAGS)

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

#	Files and flags needed to link DLLs (used in RULES_BUILD)
#
#	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) \
 $(USR_LDFLAGS) $(CMD_LDFLAGS) $(TARGET_LDFLAGS) $(LIB_LDFLAGS)

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

#
#	A WIN32 dll has three parts:
#	x.dll: the real dll (SHRLIBNAME)
#	x.lib: what you link to progs that use the dll (DLL_LINK_LIBNAME)
#	x.exp: what you need to build the dll (in no variable)
#
LINK.shrlib = $(WINLINK) -nologo $(WIN32_DLLFLAGS) -implib:$*.lib -out:$*.dll $(DLL_DEF_FLAG)
LINK.shrlib += $(call PATH_FILTER, $(LIBRARY_LD_OBJS) $(LIBRARY_LD_RESS) $(SHRLIB_LDLIBS))
MUNCH_CMD =  $(CCC) -Fo $@ $^


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

#
# When SHARED_LIBRARIES is YES we are building a DLL link library
# and when SHARED_LIBRARIES is NO we are building an object library
#
DLL_LINK_LIBNAME_YES = $(BUILD_LIBRARY:%=%.lib)
DLL_LINK_LIBNAME = $(DLL_LINK_LIBNAME_$(SHARED_LIBRARIES))
LIB_PREFIX=
LIB_SUFFIX=.lib
LIBNAME_NO = $(BUILD_LIBRARY:%=%.lib)
LIBNAME = $(LIBNAME_$(SHARED_LIBRARIES))

#	dll install location
INSTALL_SHRLIB = $(INSTALL_BIN)


#--------------------------------------------------
# Products dependancy definitions

# SYS_PROD_LIBS deprecated
# Use PROD_SYS_LIBS

PROD_DEPLIBS=$(foreach lib, $(PROD_LIBS) $(USR_LIBS), \
    $(firstword $(wildcard $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $($(lib)_DIR) $(SHRLIB_SEARCH_DIRS))) \
    $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $(firstword $($(lib)_DIR) $(INSTALL_LIB)))))

PROD_LDLIBS += $($*_DEPLIBS) $(PROD_DEPLIBS)
PROD_LDLIBS += $(addsuffix .lib, \
         $($*_SYS_LIBS) $(PROD_SYS_LIBS) $(USR_SYS_LIBS) )

LDLIBS_STATIC_YES = LDLIBS
LDLIBS_SHARED_NO = LDLIBS
PROD_LDLIBS += $(STATIC_LDLIBS) $($(firstword $(LDLIBS_STATIC_$(STATIC_BUILD)) \
               $(LDLIBS_SHARED_$(SHARED_LIBRARIES))))

#--------------------------------------------------
#Libraries dependancy definitions

# <name>_DLL_LIBS <name>_SYS_DLL_LIBS deprecated.
# Use <name>_LIBS and <name>_SYS_LIBS.
# DLL_LIBS, and SYS_DLL_LIBS deprecated
# Use LIB_LIBS and LIB_SYS_LIBS
LIB_LIBS += $(DLL_LIBS)
LIB_SYS_LIBS += $(SYS_DLL_LIBS)

#   libs that we need to link the DLL with
#   (it isnt necessary to rebuild the dll if these change)

SHRLIB_DEPLIBS += $(foreach lib, $(LIB_LIBS) $(USR_LIBS), \
    $(firstword $(wildcard $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $($(lib)_DIR) $(SHRLIB_SEARCH_DIRS))) \
    $(addsuffix /$(LIB_PREFIX)$(lib)$(LIB_SUFFIX), \
    $(firstword $($(lib)_DIR) $(INSTALL_LIB)))))

SHRLIB_LDLIBS += $($*_DLL_DEPLIBS) $($*_DEPLIBS) $(SHRLIB_DEPLIBS)
SHRLIB_LDLIBS += $(addsuffix .lib, \
         $($*_SYS_DLL_LIBS) \
         $($*_SYS_LIBS) $(LIB_SYS_LIBS) $(USR_SYS_LIBS) )

#--------------------------------------------------
# Linker definition
LINK.cpp = $(WINLINK) -nologo $(STATIC_LDFLAGS) $(LDFLAGS) $(PROD_LDFLAGS) \
    -out:$@ $(call PATH_FILTER, $(PROD_LD_OBJS) $(PROD_LD_RESS) $(PROD_LDLIBS))

#--------------------------------------------------
# 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).
#
MT.exe = mt.exe -nologo -manifest $@.manifest
MT_DLL_COMMAND1 = $(MT.exe) "-outputresource:$@;\#2"
MT_EXE_COMMAND_YES =
MT_EXE_COMMAND_NO = $(MT.exe) "-outputresource:$@;\#1"
MT_EXE_COMMAND1 = $(MT_EXE_COMMAND_$(STATIC_BUILD))
MT_DLL_COMMAND = $(MT_DLL_COMMAND$(shell $(PERL) $(TOOLS)/useManifestTool.pl))
MT_EXE_COMMAND = $(MT_EXE_COMMAND$(shell $(PERL) $(TOOLS)/useManifestTool.pl))
