# ***************************************************************************
#     HERC_FLAGS.msvc      (!INCLUDE ed by "makefile-dllmod.msvc")
# --------------------------------------------------------------------------
# (C) Copyright Roger Bowler, 2005-2007
# --------------------------------------------------------------------------
#
#  Sets additional Hercules-related compiler/linker flags & #defines...
#
# ***************************************************************************

# Set some additional flags...

ldebug = $(ldebug) $(MAPFILE)

# user32.lib for the MessageBeep and MessageBox functions
LIBS = $(LIBS) user32.lib

# "C4702 unreachable code" is always a potentially very serious error
cflags = $(cflags) /we4702

# The following line makes all warnings into errors
cflags = $(cflags) /WX

!IFDEF ASSEMBLY_LISTINGS
# /FAcs = source code, assembly code, and machine code
cflags = $(cflags) /FAcs /Fa$(ASMDIR)\$(NULL)
!ENDIF

rcflags = $(rcflags) /nologo

# PRERELEASE Flag support
!IFDEF PRERELEASE
rcflags = $(rcflags) -D PRERELEASE=1
!ENDIF

!IFDEF _WIN64
rcflags = $(rcflags) -D _WIN64
!ENDIF

!IFNDEF MAX_CPU_ENGS
MAX_CPU_ENGS = 8
!ENDIF

rcflags = $(rcflags) /D _MSVC_ /D MAX_CPU_ENGS=$(MAX_CPU_ENGS)
cflags  = $(cflags)  /D _MSVC_ /D MAX_CPU_ENGS=$(MAX_CPU_ENGS)

!IF DEFINED(CUSTOM_BUILD_STRING)
cflags  = $(cflags)  /D CUSTOM_BUILD_STRING=\"$(CUSTOM_BUILD_STRING)\"
!ENDIF

# Allow version.c to display the name of the target host CPU architecture
cflags = $(cflags) /D HOST_ARCH=$(CPU)

# Suppress some deprecation warnings that aren't really deprecation warnings
cflags = $(cflags) -D _CRT_SECURE_NO_DEPRECATE
cflags = $(cflags) -D _CRT_NONSTDC_NO_DEPRECATE

# ... or warnings that would unduly become promoted into errors due to option /WX
# C4172 (level 1): returning address of local variable or temporary
# C4312 (level 1): 'operation' : conversion from 'type1' to 'type2' of greater size
# C4996 (level 3): 'function': was declared deprecated
cflags = $(cflags) /wd4172
cflags = $(cflags) /wd4312
cflags = $(cflags) /wd4996

ldebug = $(ldebug) /MANIFEST

# Specifically request the following (IMHO) important warning be treated
# as a Level 1 warning instead of a Level 4 warning (which is its default):
# "C4296: warning: expression is always false".
cflags = $(cflags) /w14296

# Convert the following warnings into errors
# C4101 "'identifier' : unreferenced local variable"
# C4102 "'label' : unreferenced label"
cflags = $(cflags) /we4101
cflags = $(cflags) /we4102

# D9035: option 'Wp64' has been deprecated and will be removed in a future release.
cflags = $(cflags:-Wp64=)
cflags = $(cflags:/Wp64=)

# Enable "/MP (Build with Multiple Processes)" option
# if the building host has more than one processor...
!IF $(vsversion) >= $(vers_vs2008) && $(NUMBER_OF_PROCESSORS) > 1
cflags = $(cflags) /MP
!ENDIF

# Note: the "/Gm (Enable Minimal Rebuild)" option is incompatible
# with the "/MP (Build with Multiple Processes)" option (and besides
# that it's still somewhat buggy) so remove it if it's present...
cdebug  = $(cdebug:-Gm=)
cdebug  = $(cdebug:/Gm=)

# Specify module base address directly via linker option
# so we don't have to rely on user having rebase utility.
!IFDEF _WIN64
# Using a value greater than 4GB prevents LNK4281 in later versions of MSVC
ldebug = $(ldebug) /base:0x100400000
!ELSE
ldebug = $(ldebug) /base:0x000400000
!ENDIF

!IF "$(CPU)" == "AMD64"
!IF $(vsversion) >= $(vers_vs2015)
# Optimize for Intel CPU architecture
cflags = $(cflags) /favor:INTEL64
!ELSE
# Optimize for AMD CPU architecture
cflags = $(cflags) /favor:AMD64
!ENDIF
!ENDIF

# Increase the sockets set size limit/default to be the
# same value as used on most non-Windows platforms (1024)
cflags  = $(cflags)  /D FD_SETSIZE=1024

# Define a "Use precompiled header" compiler options string macro.
# We define it as an namke string macro to make it easier for HQA
# to remove the option if desired by setting it to an empty string.

use_pch_opt = /Fp"$(OBJDIR)\\build_pch.pch" /Yu"hstdinc.h"
