
# nmake makefile, it will create DKRNL32.DLL

# to create a debug version use "nmake debug=1"

# there are several versions of the binary created:
# - RELEASE: std release version (no longer distributed)
# - SBEMU: SB emu compatible release version (supplied in HX\Bin)
# - DEBUG: std debug version
# - SBEMUD: SB emu compatible debug version

# the format of the object modules is COFF, zero-based flat memory model.
# to create non-zero-based modules, run "nmake /f TEXT.MAK"

# currently NTLFNHLP modules are linked into DKRNL32 statically.
# This means NTLfnHlp\Makefile must have been run before!

# two libraries are created as well:
# - dkrnl32s.lib: static lib, COFF format, all modules included
# - dkrnl32.lib: may be used instead of SDK's kernel32.lib, but you will
#   get linker errors if any win32 API not emulated is used.

!include <..\dirs>

!ifndef DEBUG
DEBUG=0
!endif

NAME=DKRNL32
LIBNAME=DKRNL32S

!if $(DEBUG)
AOPTD=-D_DEBUG
OUTDIR=DEBUG
SBOUTD=SBEMUD
!else
AOPTD=
OUTDIR=RELEASE
SBOUTD=SBEMU
!endif

SRCMODS = \
!include modules.inc

OBJMODS = $(SRCMODS:.ASM=.OBJ)
!if $(DEBUG)
OBJMODS = $(OBJMODS:.\=DEBUG\)
!else
OBJMODS = $(OBJMODS:.\=RELEASE\)
!endif

OTHERMODS=.\int21lfn.obj

ASMOPT= -c -nologo -Sg -D_KERNEL32_=1 $(AOPTD) -I$(INC32DIR)
ASM=ml.exe -coff $(ASMOPT) -D?FLAT=1 -Fl$* -Fo$* 
#ASMOPT= -D_KERNEL32_=1 $(AOPTD) -I..\..\Include
#ASM=c:\temp\poasm\poasm.exe $(ASMOPT) -D?FLAT=1 -Fo$* 

LOPTS= /NOLOGO /MAP /SUBSYSTEM:CONSOLE /DLL /NODEFAULTLIB

.SUFFIXES: .asm .obj


.asm{$(OUTDIR)}.obj:
    $(ASM) $<

ALL: $(OUTDIR)\$(NAME).DLL $(SBOUTD)\$(NAME).DLL

$(SBOUTD)\$(NAME).DLL: $(OUTDIR)\$(LIBNAME).lib $(OUTDIR)\$(NAME).obj $(NAME).def
	@if not exist $(SBOUTD) mkdir $(SBOUTD)
	@nmake /f sbemu.mak DEBUG=$(DEBUG)

$(OUTDIR)\$(NAME).DLL: $(OUTDIR)\$(LIBNAME).lib $(OUTDIR)\$(NAME).obj $(NAME).def
    @if exist $*.DLL erase $*.DLL
    $(LINKBIN) @<<
$(OUTDIR)\$(NAME).obj $(OUTDIR)\$(LIBNAME).lib
$(LOPTS) $(LOPTD)
/DEF:$(NAME).def /merge:.BASE=.data /OUT:$*.DLL /BASE:0xBFF00000
<<
!if $(DEBUG)==0
# now the version created by SBEMU.MAK is the one copied to HX\Bin
#    @copy $*.DLL ..\..\bin\*.* >NUL
#!ifdef DLL32DIR
#    @copy $*.DLL $(DLL32DIR)\*.* >NUL
#!endif
# usually these libs aren't used. Use Win32 KERNEL32.LIB instead    
#   @copy $*.lib $(LIBCOFF)\*.* >NUL
#   @copy $(OUTDIR)\$(LIBNAME).lib $(LIBCOFF)\*.*
!endif    

$(OUTDIR)\$(LIBNAME).lib: $(OBJMODS)
    @cd ..\NTLFNHLP
    @nmake DEBUG=$(DEBUG)
    @cd ..\DKRNL32\$(OUTDIR)
    @if exist $(NAME).DLL rename $(NAME).DLL $(NAME).DL_
    $(LIBBIN) @<<
$(SRCMODS:.ASM=.OBJ) $(OTHERMODS) /OUT:$(LIBNAME).lib
<<
    @if exist $(NAME).DL_ rename $(NAME).DL_ $(NAME).DLL
	@cd ..

$(OBJMODS): dkrnl32.inc

$(OUTDIR)\$(NAME).obj: version.inc dkrnl32.inc

clean:
    @del $(OUTDIR)\*.obj >NUL
    @del $(OUTDIR)\*.dll >NUL
    @del $(OUTDIR)\*.lib >NUL
    @del $(OUTDIR)\*.map >NUL
    @del $(OUTDIR)\*.lst >NUL
    @del $(OUTDIR)\*.exp >NUL
    @nmake /f sbemu.mak debug=$(DEBUG) clean 
