#
#       constructs timer.drv
#
#   Defines:
#       DEBUG   - Enable debug code
#       STRICT  - Build a version with STRICT enabled
#

NAME    =timer
EXT     =drv
!include ..\makefile.inc
OBJFIRST=$(DEST)\libinit.obj
OBJ1    =$(DEST)\timer.obj $(DEST)\local.obj $(DEST)\startend.obj $(DEST)\api.obj $(DEST)\math.obj

OBJ     =$(OBJ1)
LIBS    =..\lib\$(ALT_PROJECT)\libw ..\lib\mdllcew ..\lib\$(DEST)\mmsystem
INCS    = -I. -I..\inc -I..\..\inc

OPT     = -Oxws

#
#   build a retail build
#

INCLUDES=..\inc;.\rinc;..\..\inc;$(SDK_INC_PATH)

!if $(FREEBUILD)

CLOPT   =
MASMOPT =-I..\inc -I..\..\inc
LINKOPT =
RC      =rc16 -i..\inc
OBJD    =
MMDEBUG =

#
#   build a full debug build
#
!else
CDEBUG  =-Zd -Odi
ADEBUG  =-Zd
LDEBUG  =/LI

CLOPT   =$(CDEBUG) -DDEBUG
MASMOPT =$(ADEBUG) -DDEBUG -I..\inc -I..\..\inc
LINKOPT =$(LDEBUG)
RC      =rc16 -DDEBUG -i..\inc -i..\mmsystem\rinc
OBJD    =
MMDEBUG = DEBUG=1

!endif

Z=$(ALT_PROJECT)\$(O)^\
.SUFFIXES: .asm

!if "$(STRICT)" == "YES"
TYPES   =-DSTRICT
!else
TYPES   =
!endif

CLOPT  =$(CLOPT) $(DBCS_FLAGS)
MASMOPT=$(MASMOPT) $(DBCS_FLAGS)

ASM     = masm -Mx -t -D?QUIET $(MASMOPT)
LINK    = $(LINK16) /NOD/NOE/MAP/ALIGN:16 $(LINKOPT)

all:  $(DEST)\$(NAME).$(EXT) $(DEST)\$(NAME).sym

$(DEST)\libinit.obj : libinit.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

$(DEST)\timer.obj : timer.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

$(DEST)\local.obj : local.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

$(DEST)\startend.obj : startend.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

$(DEST)\api.obj : api.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

$(DEST)\math.obj : math.asm
   $(ASM) -DSEGNAME=_TEXT $(@B).asm, $*.obj;

###################################


$(DEST)\$(NAME).$(EXT): $(OBJFIRST) $(OBJ) $(NAME).def $(DEST)\$(NAME).res
        $(LINK) @<<
$(OBJFIRST) +
$(OBJ1),
$(DEST)\$(NAME).$(EXT),
$(DEST)\$(NAME),
$(LIBS),
$(NAME).def
<<
        $(RC) -t $(DEST)\$(NAME).res $(DEST)\$(NAME).$(EXT)
        @mapsym /n -o $*.sym $*.map
        -binplace -o $(ALT_PROJECT_TARGET) $(DEST)\timer.drv $(DEST)\timer.map $(DEST)\timer.sym

RES_DIR =.\messages\usa

$(DEST)\$(NAME).rc: $(RES_DIR)\$(NAME).rc
        @copy $(RES_DIR)\$(NAME).rc $@

$(DEST)\$(NAME).rcv:  $(RES_DIR)\$(NAME).rcv
        @copy $(RES_DIR)\$(NAME).rcv $@

$(DEST)\$(NAME).res: $(DEST)\$(NAME).rc $(DEST)\$(NAME).rcv ..\inc\common.ver
        set INCLUDE=$(INCLUDES)
        $(RC) -r -fo$@ $(DEST)\$(NAME).rc



############## clean ##############
clean: cleanup all

cleanup:
!IF "$(NEC_98)" == "1"
        if exist $Z$(NAME).$(EXT) del $Z$(NAME).$(EXT)
        if exist $Z$(NAME).res    del $Z$(NAME).res
        if exist $Z*.sym          del $Z*.sym
        if exist $Z*.map          del $Z*.map
        if exist $Z*.lib          del $Z*.lib
        if exist $Z*.cod          del $Z*.cod
        if exist $Z*.obj          del $Z*.obj
        if exist $Z*.rcv          del $Z*.rcv
        if exist $Z*.rc           del $Z*.rc
!ELSE
        if exist $(NAME).$(EXT) del $(NAME).$(EXT)
        if exist $(NAME).res    del $(NAME).res
        if exist *.sym          del *.sym
        if exist *.map          del *.map
        if exist *.lib          del *.lib
        if exist $Z*.cod        del $Z*.cod
        if exist $Z*.obj        del $Z*.obj
        if exist *.rcv          del *.rcv
        if exist *.rc           del *.rc
!ENDIF

# START Dependencies
$(DEST)\api.obj: api.asm timer.inc

$(DEST)\libinit.obj: libinit.asm timer.inc

$(DEST)\local.obj: local.asm timer.inc

$(DEST)\startend.obj: startend.asm timer.inc

$(DEST)\timer.obj: timer.asm timer.inc

# END Dependencies
