
# this will create DUSER32.DLL
# adjust paths in file "..\dirs" first!
# to create a debug version use "nmake debug=1"
# output will be in subdir RELEASE or DEBUG, format
# of object modules is COFF format, true flat

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

!include <..\dirs>

!ifndef DEBUG
DEBUG=0
!endif

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

SRCMODS = \
!include modules.inc

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

!ifndef MASM
MASM=0
!endif
MSLINK=0

ASMOPT= -c -coff -nologo -Cp -Sg -D?FLAT=1 -D_USER32_=1 $(AOPTD) -I$(INC32DIR) -Fl$* -Fo$*
!if $(MASM)
ASM=@ml.exe $(ASMOPT)
!else
ASM=@jwasm.exe $(ASMOPT)
!endif

LOPTS= /NOLOGO /MAP /DLL /NODEFAULTLIB /LIBPATH:$(LIBCOFF) /OPT:NOWIN98

NAME=DUSER32
LIBNAME=DUSER32S
LIBS=dkrnl32.lib dgdi32.lib

.SUFFIXES: .asm .obj

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

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

$(OUTDIR):
	@mkdir $(OUTDIR)

$(OUTDIR)\$(NAME).DLL: $(OUTDIR)\$(LIBNAME).lib $(OUTDIR)\$(NAME).obj $(NAME).def $(OUTDIR)\$(NAME).res Makefile
!if $(MSLINK)
	@link @<<
$(OUTDIR)\$(NAME).obj $(OUTDIR)\$(NAME).RES $(OUTDIR)\$(LIBNAME).LIB $(LIBS)
$(LOPTS) $(LOPTD)
/DEF:$(NAME).DEF /OUT:$*.DLL
<<
!else
	@$(LINKBIN) format win pe dll name $*.DLL @<<
f $(OUTDIR)\$(NAME).obj
res $(OUTDIR)\$(NAME).RES
libpath $(LIBCOFF)
lib { $(OUTDIR)\$(LIBNAME).LIB $(LIBS) }
op q, map=$*, implib=$*.lib @$(NAME).rsp
<<
!endif
!if $(DEBUG)==0
	@copy $*.DLL ..\..\bin\*.* >NUL
!ifdef DLL32DIR
	@copy $*.DLL $(DLL32DIR)\*.* >NUL
!endif
	@copy $*.lib $(LIBCOFF)\*.* >NUL
	@copy $(OUTDIR)\$(LIBNAME).lib $(LIBCOFF)\*.* >NUL
!endif

WLIBMODS=$(SRCMODS:.\=+)

$(OUTDIR)\$(LIBNAME).LIB: $(OBJMODS) Makefile
	@cd $(OUTDIR)
	@$(LIBBIN) @<<
$(LIBNAME).LIB $(WLIBMODS:.ASM=.OBJ) +..\LIBCOFF\libc32u.lib 
<<
	@cd ..

$(OBJMODS): duser32.inc

$(OUTDIR)\$(NAME).RES: $(NAME).rc
	@$(RCBIN) -q -r -bt=nt -zm -fo=$(OUTDIR)\$(NAME).RES $(NAME).rc

clean:
	@del $(OUTDIR)\*.obj
	@del $(OUTDIR)\*.dll
	@del $(OUTDIR)\*.lib
	@del $(OUTDIR)\*.lst
	@del $(OUTDIR)\*.map
	@del $(OUTDIR)\*.res
	@del $(OUTDIR)\*.exp
