# Copyright (c) Microsoft Corporation. All rights reserved.

#


#

# This makefile is included from the beginning of various makefiles.

# It sets up various definitions so that they can be used in the makefiles

# without them getting prematurely expanded.

#


!if !DEFINED(MMLITE_SDK)
!error Cannot find MMLITE_SDK tree, set MMLITE_SDK in your environment first -- NMAKE aborted
!endif

# set default to _OLDSCHED unless overridden

!if !DEFINED(_PAUL_SCHED)
_OLDSCHED=1
!endif

!if "$(TARGETTYPE)"!="debug"
TARGETTYPE=release
!endif

!if !DEFINED(TARGETCPU)
TARGETCPU=i386
!endif

!if "$(TARGETCPU)"=="arm"
!if !DEFINED(TOOLS)
# force TOOLS to be defined for arm

TOOLS=gnu
!endif
!endif

!if !DEFINED(TARGETCONFIG)
!if DEFINED(TOOLS)
TARGETCONFIG=$(TARGETCPU)_$(TOOLS)
!else
TARGETCONFIG=$(TARGETCPU)
!endif
!endif

# Can't override _SILENT with empty so use _VERBOSE for that

!if !DEFINED(_VERBOSE)
_SILENT=@
!endif

# Specify the object file's suffix

!if "$(TARGETCPU)"=="tm1"
O=o
!else
!if "$(TARGETCPU)"=="ecog"
#now is this weird or what ? religions..

O=asm
!else
O=obj
!endif
!endif

# .rel is an intermediary step in linking.

!if "$(TARGETCPU)" == "bf"
# On the bf the tools require the suffix to be .dxe or compilation fails

REL=dxe
!else
REL=rel
!endif

!if "$(TARGETCPU)"=="i386"
_BUILD_PRODUCT=ntsim-std
!else if "$(TOOLS)"=="arm"
_BUILD_PRODUCT=sidearm-std
!else
_BUILD_PRODUCT=aeb-std
!endif

# Some of the tools are lacking C++ support, but most gcc platforms should work in theory

# VS8 support is also incomplete for now

!if "$(TOOLS)"=="gnu4" || "$(TOOLS)"=="arm" || "$(TARGETCPU)"=="tm1" || "$(TARGETCPU)"=="mips" || "$(TARGETCPU)"=="m68k" || "$(TARGETCPU)"=="ecog" || "$(TARGETCPU)"=="h8" || (DEFINED(VCINSTALLDIR) && "$(TARGETCPU)"=="i386")
# Make makefiles skip C++ files

__NO_CPLUSPLUS=1
!endif

# Some platforms have no app linker or no loader

!if "$(TARGETCPU)"=="h8" || "$(TARGETCPU)"=="bf"
__NO_EXECUTABLES=1
!endif
#endif


!if !DEFINED(MMLITE_BUILD_DIR)
MMLITE_BUILD_DIR=$(MMLITE_SDK)\build
!endif

!if !DEFINED(SRC_DIR)
SRC_DIR=$(MMLITE_SDK)\$(SUBDIR)
!endif

DEPENDENCY_DIR=$(MMLITE_SDK)\conf\depends\$(SUBDIR)
GEN_INC_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\include
!if DEFINED(_UNICODE)
OBJECT_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)-u\obj\$(SUBDIR)
LIBRARY_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)-u\lib
SYSTEM_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)-u\bin
!else
OBJECT_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)\obj\$(SUBDIR)
LIBRARY_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)\lib
SYSTEM_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\$(TARGETTYPE)\bin
!endif
SYSTEM_RELEASE_DIR=$(MMLITE_BUILD_DIR)\$(TARGETCONFIG)\bin\release

#

# Libraries that apps link against

#

INTERFACES_LIB=$(LIBRARY_DIR)\iids.lib

EXE_LIBS= $(LIBRARY_DIR)\mmcrt.lib \
	$(LIBRARY_DIR)\basertl.lib \
	$(LIBRARY_DIR)\util.lib \
	$(LIBRARY_DIR)\iids.lib $(MACHDEP_EXE_LIBS)

COB_LIBS=  $(EXE_LIBS)

DLL_LIBS= $(COB_LIBS)

# Scheduler backward compatibility

!if DEFINED(_OLDSCHED)
CBSCHED=cb_sched
NOSCHED=no_sched
!if !DEFINED(____OLDSCHED)
____OLDSCHED=1
 # avoid duplicate def or ccblkfn will output warning.

CC_FLAGS=$(CC_FLAGS) $(CC_DEF)_OLDSCHED=1
!endif
!else
CBSCHED=cb_sched2
NOSCHED=no_sched2
!endif

!if DEFINED(_CLR)
CC_FLAGS = $(CC_FLAGS) -D_CLR=1
NO_CLR_LIB = $(LIBRARY_DIR)\no_clr.lib
CLR_BUILD_DIR = clr.dir
!else
NO_CLR_LIB =
CLR_BUILD_DIR =
!endif

#

# Win32 libs

#

# If MSVCDIR is defined we use the preinstalled compiler.

!if DEFINED(MSVCDIR)
!if DEFINED(VSINSTALLDIR)
# VS7 installed

WIN32_LIB_PATH=$(MSVCDIR)\lib
WIN32_LIB_PATH2=$(MSVCDIR)\PlatformSDK\lib
!else
# VC6 with Platform SDK installed

WIN32_LIB_PATH=$(MSVCDIR)\lib
WIN32_LIB_PATH2=$(MSSDK)\lib
!endif
!else
!if DEFINED(VCINSTALLDIR)
# VS8 installed!

WIN32_LIB_PATH=$(VCINSTALLDIR)\lib
WIN32_LIB_PATH2=$(VCINSTALLDIR)\PlatformSDK\lib
!else
# VC6 and platform files dumped into MMLITE_SDK\tools

WIN32_LIB_PATH=$(MMLITE_SDK)\tools\$(TARGETCPU)\lib
WIN32_LIB_PATH2=$(MMLITE_SDK)\tools\$(TARGETCPU)\lib
!endif
!endif

WIN32_WINSOCK_LIB = \
    "$(WIN32_LIB_PATH2)\ws2_32.lib"

!if "$(TARGETTYPE)"=="release"
WIN32_LIBS= \
    $(MMLITE_SDK)\tools\VC_debug_patch\debugsyn.lib \
    "$(WIN32_LIB_PATH)\oldnames.lib" \
    "$(WIN32_LIB_PATH2)\user32.lib" \
    "$(WIN32_LIB_PATH2)\advapi32.lib" \
    "$(WIN32_LIB_PATH2)\gdi32.lib" \
    "$(WIN32_LIB_PATH)\kernel32.lib"

WIN32_APPLIBS= $(WIN32_LIBS) "$(WIN32_LIB_PATH)\msvcrt.lib"
!else
WIN32_LIBS= \
    $(MMLITE_SDK)\tools\VC_debug_patch\debugsyn.lib \
    "$(WIN32_LIB_PATH)\oldnames.lib" \
    "$(WIN32_LIB_PATH2)\user32.lib" \
    "$(WIN32_LIB_PATH2)\advapi32.lib" \
    "$(WIN32_LIB_PATH2)\gdi32.lib" \
    "$(WIN32_LIB_PATH)\kernel32.lib"

!if DEFINED(VS71COMNTOOLS)
# VS7.1 no longer seems to have a msvcrtd.dll

WIN32_APPLIBS= $(WIN32_LIBS) "$(WIN32_LIB_PATH)\msvcrt.lib"
!else
WIN32_APPLIBS= $(WIN32_LIBS) "$(WIN32_LIB_PATH)\msvcrtd.lib"
!endif
!endif

# Some tools

!ifdef _VERBOSE
SEDIT=$(MMLITE_SDK)\tools\bin\sedit.exe -v
!else
SEDIT=$(MMLITE_SDK)\tools\bin\sedit.exe
!endif