# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

# Common nmake file to be included in each NTMakfile.
#
# Required definitions:
#     AFSDEV_BUILDTYPE = [ CHECKED | FREE ]
#     AFSDEV_INCLUDE = <default include directories>
#     AFSDEV_LIB = <default library directories>
#
# Optional definitions:
#     AFSDEV_DESTDIR = <top-level install directory>  (default is $(AFSROOT)\DEST)
#     AFSDEV_WARNLEVEL = [0 | 1 | 2 | 3 | 4]  (default is 3)
#     AFSDEV_AUXCDEFINES = <auxiliary C preprocessor defs> (default is null)
#     AFSDEV_AUXRCFLAGS = <auxiliary resource compiler flags> (default is null)
#     AFSDEV_TEXTMODE = <text mode is default if defined>  (default is null)
#     AFSDEV_CRTDEBUG = <utilize debug C runtime if define> (default is null)
#
############################################################################


# Definitions provided here are based on WIN32.MAK, a common nmake
# file included with the MS SDK and MS VC distributions.
# WIN32.MAK, and this nmake file, are targeted to the MSVC compiler;
# port this nmake file if additional compiler support is required.

# Define default target-type macros required by WIN32.MAK.
# Allow them to be overriden in an NTMakefile or via an environment variable.

!IFNDEF APPVER
APPVER = 4.0
!ENDIF

#define used in Win9x installation and program version display
AFSPRODUCT_VERSION=1.3.60
CELLNAME_DEFAULT=Your Cell Name
CELLSERVDB_INSTALL=CellServDB.GrandCentral
CELLSERVDB_WEB=http://grand.central.org/dl/cellservdb/CellServDB

!IFNDEF TARGETOS
TARGETOS = WIN95
#TARGETOS = WINNT
!ENDIF

!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE 
NULL=nul
!ENDIF 

!IFNDEF _WIN32_IE
_WIN32_IE = 0x0300
!ENDIF

# Check that build type is correctly specified.

!IF (DEFINED(PROFILE) || DEFINED(TUNE))
#    Build type ignored when profiling or tuning.
AFSDEV_BUILDTYPE = NONE

!ELSE
#    Build type must be checked or free.
!IF ("$(AFSDEV_BUILDTYPE)" != "CHECKED" && "$(AFSDEV_BUILDTYPE)" != "FREE")
!ERROR Must define AFSDEV_BUILDTYPE to be CHECKED or FREE.
!ENDIF

!ENDIF

# Limit default include and library directories to those specified for build.

!IFNDEF AFSDEV_INCLUDE
!ERROR Must define AFSDEV_INCLUDE to be the default include directories.
!ENDIF

!IF ((!DEFINED(INCLUDE)) && ([set INCLUDE=$(AFSDEV_INCLUDE)] != 0))
#    If env. var. INCLUDE not defined then macro assignment won't set it.
!ERROR Failed setting environment variable INCLUDE.
!ENDIF
INCLUDE = $(AFSDEV_INCLUDE)


!IFNDEF AFSDEV_LIB
!ERROR Must define AFSDEV_LIB to be the default library directories.
!ENDIF

!IF ((!DEFINED(LIB)) && ([set LIB=$(AFSDEV_LIB)] != 0))
#    If env. var. LIB not defined then macro assignment won't set it.
!ERROR Failed setting environment variable LIB.
!ENDIF
LIB = $(AFSDEV_LIB)

# Undefine WIN32.MAK NODEBUG macro.
# Always generate full debug info, unless profiling or tuning (see below).

!UNDEF NODEBUG

# Include WIN32.MAK nmake file

!INCLUDE <WIN32.MAK>

# Extend and/or supplement definitions in WIN32.MAK.

# Standard install directory.
!IFDEF AFSDEV_DESTDIR
DESTDIR = $(AFSDEV_DESTDIR)
!ELSE
DESTDIR = $(AFSROOT)\DEST
!ENDIF

# Command macros.
COPY = copy
#DEL = del
#DEL = rm -f       # to delete multiple files on one command line
DEL = $(DESTDIR)\BIN\rmbat 	   # win 98 must use batch file
MKDIR = mkdir
REN = ren
ECHO = echo
CD = cd
MC = mc -vcsU
MAKECMD = nmake.exe



COMPILE_ET = $(DESTDIR)\bin\compile_et
RXGEN = $(DESTDIR)\bin\rxgen
MIDL  = midl

# Common clean target.
# Double colon (::) syntax allows supplemental clean target to be specified.
clean::
	$(DEL) *.obj *.lib *.dll *.exe
	$(DEL) *_component_version_number.*

# Common lang target.
# Double colon (::) syntax allows supplemental lang target to be specified.
lang::


# Compiler include paths and preprocessor defines

afscdefs =\
	-I. \
	-I$(DESTDIR)\include \
	-I$(DESTDIR)\include\afs \
	-I$(DESTDIR)\include\rx \
	-DWIN32_LEAN_AND_MEAN \
	-DSTRICT \
	-D_WIN32_IE=0x0400 \
     -DAFS_AFSDB_ENV \
     -DAFS_FREELANCE_CLIENT

!	IF ((EXIST($(MSSDK)\include)) && (("$(SYS_NAME)"=="i386_win95" ) || ("$(SYS_NAME)"=="I386_WIN95" )))
afscdefs=$(afscdefs) -I$(MSSDK)\include $(afscppdefs) \
!	ENDIF

afscdefs = $(afscdefs) $(AFSDEV_AUXCDEFINES)

#add a few defines for win9xpanel
afscppdefs = -D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_WINNT" /D "_AFXDLL"

# Compiler switches (except include paths and preprocessor defines)
#
# Note: if conflicting options are specified, rightmost option applies.
#
# /Oy-  specifies no frame-pointer omission
# /GF   pool strings and place in read-only memory
# /Gd   use cdecl calling convention by default
# /Gy   enable function-level linking
# /GX   enable C++ exceptions (assumes extern C funcs never throw exceptions)
# /Os   favor small (over fast) code; seems to avoid 64-bit bugs in VC compiler

afscflags =\
	/Oy- \
	/GF \
	/Gd \
	/Gy \
	/GX \
	/Os

# Set optimization and debugging level based on build type.

!IF ("$(AFSDEV_BUILDTYPE)" == "FREE")
#    Apply full optimization; generate full debug info in obj.
afscflags = $(afscflags) /Ox /Z7
ldebug = $(ldebug) -debugtype:both
cdebug = $(cdebug:-Od=)  # avoid annoying override warning (D4025)

!ELSEIF ("$(AFSDEV_BUILDTYPE)" == "CHECKED")
#    Disable optimization; generate full debug info in obj.
afscflags = $(afscflags) /Od /Z7
ldebug = $(ldebug) -debugtype:both
!ENDIF

# Set compiler warning level

!IFNDEF AFSDEV_WARNLEVEL
AFSDEV_WARNLEVEL = 3
!ELSE
!IF ("$(AFSDEV_WARNLEVEL)" != "0" && \
     "$(AFSDEV_WARNLEVEL)" != "1" && \
     "$(AFSDEV_WARNLEVEL)" != "2" && \
     "$(AFSDEV_WARNLEVEL)" != "3" && \
     "$(AFSDEV_WARNLEVEL)" != "4")
!ERROR Must define AFSDEV_WARNLEVEL to be one of 0 through 4.
!ENDIF
!ENDIF

afscflags = $(afscflags) /W$(AFSDEV_WARNLEVEL)


# Linker switches
#
# /FIXED:NO   generates a relocation section in the executable

afslflags =\
	/FIXED:NO



# For checked builds, define DEBUG (but not the MS control flag _DEBUG).

!IF ("$(AFSDEV_BUILDTYPE)" == "CHECKED")
afscdefs = $(afscdefs) -DDEBUG
!ENDIF

# Utilize the debug version of the MSVC runtime, if requested.

!IFDEF AFSDEV_CRTDEBUG
afscdefs = $(afscdefs) -D_DEBUG
conlibsdll = $(conlibsdll:msvcrt.lib=msvcrtd.lib)
guilibsdll = $(guilibsdll:msvcrt.lib=msvcrtd.lib)
!ENDIF

# Link with binmode.obj; files will be opened in binary mode by default.

!IFNDEF AFSDEV_TEXTMODE
conlibsdll = $(conlibsdll) binmode.obj
guilibsdll = $(guilibsdll) binmode.obj
!ENDIF


# Define MFC link and library macros
#     Note that MFC seems to make extensive use of default libraries,
#     thus we do not specify a general /NODEFAULTLIB.

mfclflags = $(guilflags)
mfclflags = $(mfclflags:/NODEFAULTLIB=)

mfcdlllflags = $(dlllflags)
mfcdlllflags = $(mfcdlllflags:/NODEFAULTLIB=)

mfclibsdll = $(guilibsdll)
mfclibsdll = $(mfclibsdll:msvcrtd.lib=)
mfclibsdll = $(mfclibsdll:msvcrt.lib=)

!IFNDEF AFSDEV_CRTDEBUG
mfclflags = $(mfclflags) /NODEFAULTLIB:msvcrtd.lib
mfcdlllflags = $(mfcdlllflags) /NODEFAULTLIB:msvcrtd.lib
!ELSE
mfclflags = $(mfclflags) /NODEFAULTLIB:msvcrt.lib
mfcdlllflags = $(mfcdlllflags) /NODEFAULTLIB:msvcrt.lib
!ENDIF


# Macros for creating/modifying binary targets

# EXE link macro for console applications
EXECONLINK = $(link) /OUT:$@ $(ldebug) $(conlflags) $(afslflags) $(conlibsdll) $**

# EXE link macro for GUI applications
EXEGUILINK = $(link) /OUT:$@ $(ldebug) $(guilflags) $(afslflags) $(guilibsdll) $**

# EXE link macro for MFC applications
EXEMFCLINK = $(link) /OUT:$@ $(ldebug) $(mfclflags) $(afslflags) $(mfclibsdll) $**

# DLL link macro for console applications
DLLCONLINK = $(link) /OUT:$@ $(ldebug) $(dlllflags) $(afslflags) $(conlibsdll) $**

# DLL link macro for GUI applications
DLLGUILINK = $(link) /OUT:$@ $(ldebug) $(dlllflags) $(afslflags) $(guilibsdll) $**

# DLL link macro for MFC applications
DLLMFCLINK = $(link) /OUT:$@ $(ldebug) $(mfcdlllflags) $(afslflags) $(mfclibsdll) $**

# DLL link macro for resource-only DLLs
# DLLRESLINK = $(link) /OUT:$@ $(dlllflags:-entry:_DllMainCRTStartup@12=-noentry) $(afslflags) $**
DLLRESLINK = $(link) /OUT:$@ -noentry $(afslflags) $**

# Library archive macro
LIBARCH = $(implib) /NOLOGO /OUT:$@ $**

# Language selection macro
NTLANG = $(DESTDIR)\bin\NTLang.bat


# EXE\DLL preparation macros
#     Rebase to avoid conflicts; strip symbols in free build.
!IF ("$(AFSDEV_BUILDTYPE)" == "FREE")
EXEPREP = rebase -b 0x00400000 -x $(@D) -q $@
DLLPREP = rebase -i $(DESTDIR)\NTDllmap.txt -x $(@D) -q $@
!ELSEIF ("$(AFSDEV_BUILDTYPE)" == "CHECKED")
EXEPREP = rebase -b 0x00400000 -q $@
DLLPREP = rebase -i $(DESTDIR)\NTDllmap.txt -q $@
!ENDIF

# C/C++ compilation macros

C2OBJ = $(cc) $(cflags) $(cdebug) $(cvarsdll) $(afscflags) $(afscdefs) /c
CPP2OBJ = $(cc) $(cflags) $(cdebug) $(cvarsdll) $(afscflags) $(afscdefs) $(afscppdefs) /c

# Resource compiler macro
RC = $(rc) $(rcvars) $(rcflags) $(AFSDEV_AUXRCFLAGS) /d "AFSPRODUCT_VERSION=\"$(AFSPRODUCT_VERSION)\""

# Lex/Yacc macros
LEX = flex -l
YACC = bison

# Inference rules for building and installing targets

# Compile .c files
.c.obj:
	$(C2OBJ) $*.c

# Compile .cpp files
.cpp.obj:
	$(CPP2OBJ) $*.cpp

# Compile .rc (resource) files
.rc.res:
	$(RC) $*.rc

# Install header files
.SUFFIXES: .h

.h.{$(DESTDIR)\include}.h:
	$(COPY) $(*B).h $(DESTDIR)\include

.h.{$(DESTDIR)\include\afs}.h:
	$(COPY) $(*B).h $(DESTDIR)\include\afs

.h.{$(DESTDIR)\include\rx}.h:
	$(COPY) $(*B).h $(DESTDIR)\include\rx

.h.{$(DESTDIR)\include\WINNT}.h:
	$(COPY) $(*B).h $(DESTDIR)\include\WINNT

