##!dmake -f

# main goal of this Makefile:
# CDP

# source in the Free-Dos initialization 
.INCLUDE .FIRST .IGNORE : fd_init.mk ../fd_init.mk ../../fd_init.mk

#
#Project related settings
#
.IF $(_COMPILER) == MC
.IF $(NDEBUG)
PRG = cdp.com
.ELSE
PRG = cdp.exe
.ENDIF
.ELSE
PRG = cdp.exe
.ENDIF
SRC = cdp.c
OBJ = cdp.obj
HDR =
MYCFLAGS = # TEST=YES
MSGLIB !:= msg.lib
MSGDCL !:= yerror.h
LDLIBS = $(MSGLIB) $(FDLIB)\$(_MODEL)_$(LNG).lib $(FDLIB)\SUPPL_$(_MODEL).lib

#
#First target
#
all : $(PRG)	# copy library into Free-Dos library dir

everything :: all cdp_inst.com documentation
	+copy $(LNG).man cdp.man
	+copy $(LNG).tx cdp.txt

everything .SETDIR=INST .SWAP ::
	$(MAKE) documentation
	+copy $(LNG).man ..\Cdp_inst.man
	+copy $(LNG).tx ..\Cdp_inst.txt

mk_zip : everything
	+copy $(LNG).fil files
	+copy $(LNG).chg changes
	+if exist $(LNG).zip del $(LNG).zip >nul
	zip -9 $(LNG).zip @$(mktmp files changes cdp_inst.com $(PRG) {cdp cdp_inst}{.man .txt} \n)

cdp_inst.com .SWAP :: $(PRG)

cdp_inst.com .SETDIR=inst .SWAP ::
	$(MAKE) all
	+copy cdp_inst.com ..

.INIT : $(CFG) tags refs errlist # Will make the utilizing files

#
#C initialization file
#
.IF $(CFG)
# Compiler configuration file, for Borland C only
# options: no Windows, no RTTI, use pre-compiled headers, no floating point

CONFIGURATION = -W-	\
-X-	\
-H	\
-I.;$(INCDIR)	\
-L.;$(LIBDIR)	\
-H=assign.csm	\
-f-	\
-ff-	\
-m$(_MODEL)

.IF $(_COMPILER) != BC45
CONFIGURATION += -RT-
.ENDIF

$(CFG) : $(MAKEFILE:s/-f//)
	Cat $(mktmp $(CONFIGURATION:t"\n")\n) >$@

.ENDIF

$(PRG) .SWAP : $(MSGLIB) $(OBJ)
.IF $(_COMPILER) == MC
.IF $(NDEBUG)
	$(LD) $(LDCOMFLAG) $(LDFLAGS) $(MCDIR)\Pc86rl_t @$(mktmp $(OBJ:t" ") \n), $@, NUL,@$(mktmp $(LDLIBS:t" ") $(MCDIR)\Mclib\n)
.ELSE
	$(LD) $(LDFLAGS) $(MCDIR)\Pc86rl_s @$(mktmp $(OBJ:t" ") \n), $@, NUL,@$(mktmp $(LDLIBS:t" ") $(MCDIR)\Mclib\n)
.ENDIF
.ELSE
	$(CC) -e$@ @$(mktmp $(OBJ:t"\n") $(LDLIBS:t"\n")\n)
.ENDIF

cdp.h .GROUP : skaus
	emit #define 0x20 SKAUS 0x20 >$@
	gawk ' { print "\"" $$1 "\""; exit 0 } ' $< >> $@
	emit #define 0x20 GSKAUS 0x20 >>$@
	gawk ' { n=$$1;while(n~/[0-9]$$/)n=substr(n,0,length(n)-1);print "\"" n "\""; exit 0 } ' $< >> $@
	emit #define 0x20 CSKAUS 0x20 >>$@
	keygen <$< >>$@
	emit #define 0x20 GRSKAUS 0x20 >>$@
	grpgen <$< >>$@
	emit #define 0x20 PRGNAME 0x20 >>$@
	gawk ' FNR == 2 { print "\"" $$0 "\""; exit 0 } ' $< >> $@

#MAKEDEP START
cdp.obj : cdp.c cdp.h
#MAKEDEP STOP

clean ::
	$(RM) $(RMFLAGS) cdp.h q*.cp q*.co q*.asm deutsch.zip english.zip

clobber ::
	$(RM) $(RMFLAGS) *.man *.tx cdp_inst.com $(PRG) files cdp.txt cdp_inst.txt files changes

clean .SETDIR=INST ::
	$(MAKE) clean

clobber .SETDIR=INST ::
	$(MAKE) clobber

# source in the Free-Dos standard targets 
.INCLUDE .FIRST .IGNORE : fd_exit.mk ../fd_exit.mk ../../fd_exit.mk
