#############################################################################
#
# VDialog: A VxD that Demonstrates How to Serialize I/O to a Device.
#           
# 
# Important note: 
# This makefile differs from the DDK samples in four ways:
#
#       1.  It uses Microsoft MASM 6.0 or 6.1 (or later). 
#           (The DDK includes a customized MASM 5.10b).
#
#       2.  It uses the INCLUDE environment variable to locate
#           include files, which allows you to place this sample code
#           in any directory you want to; the DDK samples list explicit 
#           pathnames to the include files, which requires that the sample 
#           code be located in a subdirectory parallel to the include 
#           directory.
#
#       3.  It uses an updated version of the VMM.INC include file and
#           assumes MASM 6's CMACROS.INC.
#
#       4.  It does not build a .386 file.  It only builds a .EXE
#           which must be run from the DOS prompt before loading
#           Windows Enhanced Mode.  This eliminates the need for 
#           adding a "device=" line to the [386Enh] section of 
#           SYSTEM.INI.  
#       
# A note to MASM 6.0 users:
#   If you run out of far heap during assembly, switch 
#   from ML.EXE to MLX.EXE by setting MASM60=1 in the makefile
#   or in the environment.
#       
#############################################################################

##### Define name of project #####
NAME = vdialog
WINAPP=winacc
DOSAPP=dosacc

##### Define debug build #####
DEBUG=-DDEBUG

##### Specify MASM 6.1 as default #####
# Switch to MASM 6.0 by setting MASM60=1 in the environment or here.
!ifndef MASM60 
MASM60=0
!endif

##### Tool macros #####
CC  = cl -c -AS -Gsw -Od -W3 -Zip 
# -Zm tells MASM 6 to be compatible with MASM 5.1
!if $(MASM60)
ASM = mlx -c -W3 -Zm $(DEBUG)
!else
ASM = ml -c -W3 -Zm $(DEBUG)
!endif

##### Define target(s) #####
all: $(NAME).exe $(WINAPP).EXE $(DOSAPP).EXE

##### Build the Windows application #####
# Update the resource if necessary
$(WINAPP).res: $(WINAPP).rc $(WINAPP).h
    rc -r $(WINAPP).rc

# Update the object file if necessary
$(WINAPP).obj: $(WINAPP).c $(WINAPP).h
    $(CC) $(WINAPP).c

# Update the executable file if necessary, and if so, add the resource back in.
$(WINAPP).exe: $(WINAPP).obj $(WINAPP).def
    link /CO/NOD $(WINAPP),,, libw slibcew, $(WINAPP).def
    rc $(WINAPP).res

# If the .res file is new and the .exe file is not, update the resource.
$(WINAPP).exe: $(WINAPP).res
    rc $(WINAPP).res

##### Build the DOS application #####
$(DOSAPP).obj: $(DOSAPP).asm vdevice.inc
    $(ASM) $(DOSAPP).asm

$(DOSAPP).exe: $(DOSAPP).obj
    link $(DOSAPP).obj;

##### Build the stub #####
vxdstub.obj: vxdstub.asm
    $(ASM) vxdstub.asm

vxdstub.exe: vxdstub.obj
    link vxdstub.obj;

##### Build the VxD #####
$(NAME).obj : $(NAME).asm
    $(ASM) $(NAME).asm

# Link the VxD then delete the stub loader.
$(NAME).exe: $(NAME).def $(NAME).obj vxdstub.exe
        link386 /NOI/NOD/NOP/MAP $(NAME),$(NAME).exe,,,$(NAME).def
        addhdr $(NAME).exe
        mapsym32 $(NAME)
        del vxdstub.exe

##### Clean Directory #####
clean:
    -del *.obj
    -del *.exe
    -del *.map
    -del *.sym
