
#   ************************************************************************
#   *              SOURCES Inclusion For Building PROFILE.EXE              *
#   ************************************************************************

#   PROFILE uses NtCreateProfile and related functions to build a
#   statistical profile of the execution of replaceable test code.

#   ************************************************************************
#   General Description of Target

#   The program is a Windows console application that uses the Unicode form
#   of C-language entry point.

TARGETNAME = profile
TARGETPATH = obj
TARGETTYPE = PROGRAM
UMENTRY    = wmain
UMTYPE     = console

#   ************************************************************************
#   Source files

#   The essence of the program is in three source files.

#       Entry point, command-line parsing, and coordination of profiling
#       with execution of test code

SOURCES = main.cpp

#       The code whose execution is to be profiled - known only to MAIN.CPP
#       but depending on PROFSEG.H so that PROFILE.CPP (below) can find it

SOURCES = $(SOURCES) test.cpp

#       Generalised support for self-profiling - known only to MAIN.CPP but
#       depending only on PROFSEG.H to locate the test code

SOURCES = $(SOURCES) profile.cpp

#   Originally from libraries but copied here to make demonstration
#   self-standing

#       Formatted output to console, mostly to report errors

SOURCES = $(SOURCES) puterror.cpp

#   ========================================================================
#   Include Files

#   There are no include files. This source code is self-standing for
#   publication to demonstrate written-up research.

#   ========================================================================
#   Version Resources

SOURCES = $(SOURCES) profile.rc

#   ========================================================================
#   Libraries

#   Microsoft import libraries not linked by default - this one is necessary

TARGETLIBS = $(TARGETLIBS) $(SDK_LIB_PATH)\ntdll.lib

#   Import C Run-Time (CRT) Library functions from a DLL for space and
#   simplicity - including such things as having an operator new that
#   returns NULL on failure. This is only a preference.

USE_MSVCRT = 1

#   ************************************************************************
#   Preferences

#   Warnings
#   ========

#   Makefile inclusions in the Windows Driver Kit (WDK) have /W3 as the
#   default for setting the warning level, but let's not accept code that
#   raises warnings even at the strictest level.

#   That said, remember that even this isn't as strict as can be, since
#   Microsoft's makefile inclusions force inclusion of a header that
#   disables numerous warnings. Microsoft's choices have not always been
#   inconsequential, however much they do seem to be nowadays.

#   Be ambitious. Don't settle even for /W4 but instead enable all warnings
#   except for those we truly seem unable to do anything about, e.g.,
#   because they're raised by Microsoft's own headers from the WDK.

MSC_WARNING_LEVEL = /Wall /wd4619 /wd4668 /wd4820

#   The WDK's makefile inclusions nowadays set /WX by default for free
#   builds. But they haven't always and they still don't for the compiler
#   in checked builds. So, let's force it.

#   Curiously, the way that warnings get allowed is by interpreting
#   environment variables, e.g., BUILD_ALLOW_COMPILER_WARNINGS, before
#   including any file that we can provide. The best that we can do is
#   ensure that macros for the relevant /WX switch get defined anyway.

!ifdef BUILD_ALLOW_COMPILER_WARNINGS
!undef BUILD_ALLOW_COMPILER_WARNINGS
COMPILER_WX_SWITCH = /WX
!endif

!ifdef BUILD_ALLOW_LINKER_WARNINGS
!undef BUILD_ALLOW_LINKER_WARNINGS
LINKER_WX_SWITCH = /WX
!endif

!undef BUILD_ALLOW_ALL_WARNINGS

#   Optimisation
#   ============

#   Aim in general for the most optimisation. Almost all of Microsoft's
#   low-level code is optimised for space.

#   Microsoft's makefile inclusions expect the compiler optimisations to be
#   defined via the documented MSC_OPTIMIZATION macro, either from defaults
#   that the inclusions prepare or from our specification.

MSC_OPTIMIZATION = /Oxs

#   Also desirable in general is whole-program optimisation at link-time.

#   Microsoft's makefile inclusions support Link-Time Code Generation via an
#   undocumented macro named LINK_TIME_CODE_GENERATION. The main effect of
#   defining this (to anything) is to add /GL to the compiler flags.

#   The macro is defined automatically for 64-bit builds (unless either
#   TEST_CODE or NTTESTENV is defined).

LINK_TIME_CODE_GENERATION = 1

#   For who knows what reason, defining LINK_TIME_CODE_GENERATION adds /ltcg
#   to the command line for the librarian but not for the linker. Without
#   it, builds are slower and leave a line in the log file about adding the
#   switch for better performance.

LINKER_FLAGS = $(LINKER_FLAGS) /ltcg

#   Since we have no intention of hot-patching our executables, space that
#   exists only to support hot-patching is usefully shed - though note that
#   the following macros (which are undocumented, by the way) apply to
#   64-bit builds only.

#   Defining USE_LOCAL_FUNCTIONPAD stops Microsoft's AMD64MK.INC from
#   adding /functionpadmin:6 to the LINKER_FLAGS.

#   Defining USE_LOCAL_HOTPATCHBUFFER stops Microsoft's AMD64MK.INC from
#   adding a hotpatch.obj file to the linker's inputs.

USE_LOCAL_FUNCTIONPAD = 1
USE_LOCAL_HOTPATCHBUFFER = 1

#   ************************************************************************

