!include $(NTMAKEENV)\makefile.plt

PATH    = $(BASEDIR)\tools\tools16;$(PATH)

PLATFORM=$(TARGET_DIRECTORY)

!ifndef ALT_PROJECT
ALT_PROJECT=USA
ALT_PROJECT_TARGET=.
!endif

SRC     = .
DEST=$(ALT_PROJECT)\$(_OBJ_DIR)\$(PLATFORM)
INCLUDE = -I..\wow16\inc -I..\inc -I$(PROJECT_INC_PATH)

!if !$(FREEBUILD)
DBGOPTS = -DDBG=1
!else
DBGOPTS = -DDBG=0
!endif

##########

LINKCMD = $(DEST)\dosx.exe/far/map/cp:1,$(DEST)\dosx.map;


!IF $(386)
EXTRA_OPTIONS = -Di386 -DMD
OPTIONS = -DDEBUG=0 $(DBGOPTS) -DWOW -DWOW_x86 $(EXTRA_OPTIONS) -D?QUIET
!ELSE
OPTIONS = -DDEBUG=0 $(DBGOPTS) -DWOW -DWOW_$(PLATFORM) $(EXTRA_OPTIONS) -D?QUIET
!ENDIF

MFLAGS = -t

ASM     = masm386 $(INCLUDE) $(OPTIONS) $(MFLAGS) $(DBCS_FLAGS)

MAKE    = nmake


OBJS =  $(DEST)\dxstrt.obj   $(DEST)\dxmain.obj    $(DEST)\dxintr.obj  \
        $(DEST)\dxfunc.obj      $(DEST)\dxutil.obj \
        $(DEST)\dxend.obj \
        $(DEST)\dxboot.obj      $(DEST)\dxmsg.obj     $(DEST)\dxbug.obj   \
        $(DEST)\dxnetbio.obj    $(DEST)\dxdisk.obj  \
        $(DEST)\dxini.obj       $(DEST)\dxoem.obj     $(DEST)\dxemm.obj   \
        $(DEST)\dxendpm.obj     $(DEST)\dxfind.obj  \
!IF $(386)
        $(DEST)\ntnpxem.obj     \
!ENDIF
        $(DEST)\dxdma.obj       $(DEST)\dxemm2.obj

all: makedir oldobjs $(DEST)\dosx.exe
    binplace -o $(ALT_PROJECT_TARGET) $(DEST)\dosx.exe $(DEST)\dosx.map $(DEST)\dosx.sym

$(DEST)\dosx.exe: $(OBJS) dosx.def
    @echo $(DEST)\dxstrt.obj  +    >$(DEST)\tmp.lnk
    @echo $(DEST)\dxmain.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxintr.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxfunc.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxutil.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxdisk.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxemm2.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxdma.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxnetbio.obj+    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxoem.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxbug.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxend.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxmsg.obj+    >>$(DEST)\tmp.lnk
!IF $(386)
    @echo $(DEST)\ntnpxem.obj  +    >>$(DEST)\tmp.lnk
!ENDIF
    @echo $(DEST)\dxendpm.obj +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxemm.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxini.obj   +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxfind.obj  +    >>$(DEST)\tmp.lnk
    @echo $(DEST)\dxboot.obj,      >>$(DEST)\tmp.lnk
    @echo $(LINKCMD) >>$(DEST)\tmp.lnk
    link16 @$(DEST)\tmp.lnk
    del $(DEST)\tmp.lnk
    mapsym -o $(DEST)\dosx.sym $(DEST)\dosx.map

makedir:
    @-if not exist $(DEST) md $(DEST)
    @-if not exist $(DEST) md $(DEST)

oldobjs:
    @if exist dxmsg.asm del dxmsg.asm

clean: cleanup all

cleanup:
    -del $(DEST)\*.obj $(DEST)\*.obj $(DEST)\dosx.map $(DEST)\dosx.sym $(DEST)\dosx.exe 2>nul


$(DEST)\dxboot.obj dxboot.lst: dxboot.asm ./cmacros.inc \
        gendefs.inc pmdefs.inc segdefs.inc intmac.inc \
        $(PROJECT_INC_PATH)\vdmtib.inc ..\inc\bop.inc
        $(ASM) dxboot,$(DEST)\;

$(DEST)\dxbug.obj dxbug.lst: dxbug.asm ./cmacros.inc gendefs.inc pmdefs.inc \
        segdefs.inc
        $(ASM) dxbug,$(DEST)\;

$(DEST)\dxdisk.obj dxdisk.lst: dxdisk.asm ./cmacros.inc gendefs.inc \
        interupt.inc pmdefs.inc segdefs.inc intmac.inc
        $(ASM) dxdisk,$(DEST)\;

$(DEST)\dxdma.obj dxdma.lst: dxdma.asm ./cmacros.inc gendefs.inc \
        interupt.inc pmdefs.inc segdefs.inc
        $(ASM) dxdma,$(DEST)\;

$(DEST)\dxemm.obj dxemm.lst: dxemm.asm ./cmacros.inc gendefs.inc \
        segdefs.inc
        $(ASM) dxemm,$(DEST)\;

$(DEST)\dxemm2.obj dxemm2.lst: dxemm2.asm ./cmacros.inc gendefs.inc segdefs.inc
        $(ASM) dxemm2,$(DEST)\;

$(DEST)\dxend.obj dxend.lst: dxend.asm ./cmacros.inc gendefs.inc \
        pmdefs.inc segdefs.inc
        $(ASM) dxend,$(DEST)\;

$(DEST)\dxendpm.obj dxendpm.lst: dxendpm.asm ./cmacros.inc segdefs.inc
        $(ASM) dxendpm,$(DEST)\;

$(DEST)\dxfind.obj dxfind.lst: dxfind.asm ./cmacros.inc gendefs.inc segdefs.inc
        $(ASM) dxfind,$(DEST)\;

$(DEST)\dxfunc.obj dxfunc.lst: dxfunc.asm ../wow16/inc/dosx.inc ./cmacros.inc \
        gendefs.inc pmdefs.inc segdefs.inc intmac.inc \
        stackchk.inc ..\inc\bop.inc
        $(ASM) dxfunc,$(DEST)\;

$(DEST)\dxini.obj dxini.lst: dxini.asm ./cmacros.inc gendefs.inc segdefs.inc \
        intmac.inc
        $(ASM) dxini,$(DEST)\;

$(DEST)\dxintr.obj dxintr.lst: dxintr.asm ./cmacros.inc \
        gendefs.inc interupt.inc pmdefs.inc segdefs.inc intmac.inc \
        stackchk.inc $(PROJECT_INC_PATH)\vdmtib.inc ..\inc\bop.inc
        $(ASM) dxintr,$(DEST)\;

$(DEST)\dxmain.obj dxmain.lst: dxmain.asm ./cmacros.inc gendefs.inc \
        pmdefs.inc segdefs.inc ..\inc\bop.inc
        $(ASM) dxmain,$(DEST)\;

$(DEST)\dxmsg.obj dxmsg.lst: $(ALT_PROJECT)\dxmsg.asm ./cmacros.inc gendefs.inc segdefs.inc
        $(ASM) $(ALT_PROJECT)\dxmsg,$(DEST)\;

$(DEST)\dxnetbio.obj dxnetbio.lst: dxnetbio.asm ./cmacros.inc \
        gendefs.inc interupt.inc netbios.inc pmdefs.inc segdefs.inc intmac.inc \
        stackchk.inc ..\inc\bop.inc
        $(ASM) dxnetbio,$(DEST)\;

$(DEST)\dxoem.obj dxoem.lst: dxoem.asm ./cmacros.inc gendefs.inc pmdefs.inc \
        segdefs.inc
        $(ASM) dxoem,$(DEST)\;

$(DEST)\dxstrt.obj dxstrt.lst: dxstrt.asm ./cmacros.inc \
        gendefs.inc pmdefs.inc segdefs.inc intmac.inc ..\inc\bop.inc
        $(ASM) dxstrt,$(DEST)\;

$(DEST)\dxutil.obj dxutil.lst: dxutil.asm ../inc/bop.inc ../inc/dpmi.inc \
        ./cmacros.inc gendefs.inc pmdefs.inc intmac.inc ..\inc\bop.inc
        $(ASM) dxutil,$(DEST)\;

$(DEST)\ntnpxem.obj ntnpxem.lst: ntnpxem.asm  \
        segdefs.inc gendefs.inc pmdefs.inc intmac.inc
        $(ASM) -I$(_NTBINDIR)\public\sdk\inc ntnpxem,$(DEST)\;

..\inc\dpmi.inc : ..\inc\dpmi.h
        cd ..\inc
        nmake dpmi.inc
        cd ..\dpmi
