!ifdef NTMAKEENV
#
# DO NOT EDIT THIS SECTION!!!  Edit .\sources. if you want to add a new source
# file to this component.  This section merely indirects to the real make file
# that is shared by all the components of WINDOWS NT
#

!include $(NTMAKEENV)\makefile.def

!else

!include makefile.mak

!endif  # NTMAKEENV

!if 0

#
# Defaults ... can be modified on the command line
#

        # Yes/No Macros
DEBUG  = 1
BROWSE = 1
DBIDLL = 0
OPT    = 1
        # String Macros
TARGET = intel                  # other possibilities: mips


#
# Target Specific macros
#

!if "$(TARGET)" == "intel"
        # Intel specfic stuff
CDEFS = -D_X86_
DEBUG_OPT = -Z7
LIBRARIAN = lib
MACHINE = i386
PCH_OPT = -Fp$(OBJDIR)\ -YX
! if $(DBIDLL)
OTHER_OPT = -MD
! endif
!else if "$(TARGET)" == "mips"
        # MIPS specfic stuff
CC = mcl
CDEFS = -D_MIPS_
CPP = mcl
DEBUG_OPT = -Z7
LIBRARIAN = link32 -lib
MACHINE = mips
PCH_OPT = -Fp$(OBJDIR)\ -YX
!else
        # Unknown target specific stuff; Restrict to 5 letters
! error '$(TARGET)' is an unknown target use one of (intel|mips).
!endif


#
# Setup and Create Object and Library Directory
#

        # Setup Directories
OBJDIR = $(TARGET)
LIBDIR = $(TARGET).lib
!if $(DEBUG)
OBJDIR = $(OBJDIR)_d
!endif
!if $(DBIDLL)
OBJDIR = $(OBJDIR).dll
!endif

        # Create Object Directory
!if [cd $(OBJDIR)]
! if [mkdir $(OBJDIR)]
!  error Unable to create OBJ directory '$(OBJDIR)'
! endif
!else
        # Already exists so CD back ...
! if [cd $(MAKEDIR)]
! endif
!endif
        # Create Library Directory
!if [cd $(LIBDIR)]
! if [mkdir $(LIBDIR)]
!  error Unable to create OBJ directory '$(LIBDIR)'
! endif
!else
        # Already exists so CD back ...
! if [cd $(MAKEDIR)]
! endif
!endif


#
# Environment specific Macros
#

        # Include Env var
INCLUDE=$(INCLUDE)
EXIST_STDIO_H = (exist("$(INCLUDE:;=\stdio.h"^) || exist(")\stdio.h"))
!if ! $(EXIST_STDIO_H)
! error {$(INCLUDE)}stdio.h missing ... check INCLUDE env variable
!endif

        # LANGAPI Env var
!ifndef LANGAPI
LANGAPI = \langapi
!endif
!if !exist("$(LANGAPI)\include\pdb.h")
! error '$(LANGAPI)\include\pdb.h' missing ... check LANGAPI env variable
!endif


#
# Compile Flags
#

CDEFS = $(CDEFS) -D_WIN32 -D_WINDOWS
COPTS = $(DEBUG_OPT) $(OTHER_OPT) $(PCH_OPT)
INCS  = -I. -I$(LANGAPI)\include -I$(INCLUDE:;= -I)

!if $(OPT)
COPTS = $(COPTS) -Ox
!else
COPTS = $(COPTS) -Od
!endif

!if $(BROWSE)
COPTS = -FR$(OBJDIR)\ $(COPTS)
!endif

!if $(DEBUG)
CDEFS = $(CDEFS) -D_DEBUG
!else
CDEFS = $(CDEFS) -DNDEBUG
!endif

CFLAGS = $(CDEFS) $(INCS) $(COPTS) -Fo$(OBJDIR)\ -W3
CPPFLAGS = $(CFLAGS)


#
# Important Macros
#

        # Library to build
!if $(DBIDLL)
LIBNAME = dbidll
!else
LIBNAME = dbi
!endif
!if $(DEBUG)
LIBNAME = $(LIBNAME)d.lib
!else
LIBNAME = $(LIBNAME).lib
!endif
        # Browser to build
!if $(BROWSE)
BROWSER = $(LIBDIR)\$(LIBNAME:.lib=.bsc)
!endif


#
# Inference Rules
#
.cpp{$(OBJDIR)}.obj:
        $(CPP) $(CPPFLAGS) -c $<
.c{$(OBJDIR)}.obj:
        $(CC) $(CFLAGS) -c $<


#
# File list macros
#

OBJS= $(OBJDIR)\cbind.obj $(OBJDIR)\dbi.obj $(OBJDIR)\gsi.obj\
        $(OBJDIR)\mod.obj $(OBJDIR)\mli.obj $(OBJDIR)\pdb.obj $(OBJDIR)\tm.obj\
        $(OBJDIR)\tpi.obj

HDRS= buffer.h dbi.h dbiimpl.h gsi.h mli.h mod.h pdb1.h pool.h tm.h\
        tpi.h util.h version.h


#
# Default Target
#

all: $(LIBDIR)\$(LIBNAME) $(BROWSER)


#
# Building the default target
#

# Library
$(LIBDIR)\$(LIBNAME): $(OBJS)
        @if exist $@ del $@
        $(LIBRARIAN) @<<
-debugtype:cv
-machine:$(MACHINE)
-out:$@
$(OBJS: =^
)
<<
!if "$(TARGET)" == "intel"
        copy $@ ..\lib\$LIBNAME)
        copy $@ $(LANGAPI)\lib\$(LIBNAME)
!endif

# Browser
$(BROWSER): $(OBJS:.obj=.sbr)
        bscmake -v -o $@ $(OBJS:.obj=.sbr)


#
# Dependencies for the build
#

$(OBJS): $(HDRS)


#
# Non-default Targets
#

clean:
        @-echo y | del $(OBJDIR)\*.*
        @-del $(LIBDIR)\$(LIBNAME) $(BROWSER)
        @-del *.pch *.pdb

cleanall:
        nmake DBIDLL=0 DEBUG=0 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET) clean
        nmake DBIDLL=1 DEBUG=0 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET) clean
        nmake DBIDLL=0 DEBUG=1 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET) clean
        nmake DBIDLL=1 DEBUG=1 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET) clean

each:
        nmake DBIDLL=0 DEBUG=0 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET)
        nmake DBIDLL=1 DEBUG=0 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET)
        nmake DBIDLL=0 DEBUG=1 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET)
        nmake DBIDLL=1 DEBUG=1 BROWSE=$(BROWSE) OPT=$(OPT) TARGET=$(TARGET)

eachclean: cleanall each


#
# Help and Usage Message
#

help usage:
        @type <<
This makefile builds dbi[d].lib dbidll[d].lib

Usage:

nmake help|usage                # This message
nmake clean                     # Cleanup Object and Library directories
nmake cleanall                  # Cleanup all 4 Object and Library directories
nmake each                      # Build all 4 libs for given target
nmake eachclean                 # Clean build all 4 libs for given target
nmake [<options>]
        where, <options> are
DEBUG=0|1       (default 1)
BROWSE=0|1      (default 1)
DBIDLL=0|1      (default 0)
OPT=0|1         (default 1)
TARGET=intel|mips       (default intel)
<<

!endif  # if 0
