##!dmake -f

# main goal of this Makefile:
# msgComp2: Message compiler
# msgDiff: Message definition file comparator

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

#
#Project related settings
#
_PRG = msgcomp2.com msgdiff.com msg2mgt.com
PRG := $(eq,$(_MODEL:u),T $(_PRG) $(_PRG:s/.com/.exe))
SRC = copyf.c fileio.c hashfile.c msg2mgt.c msgcomp2.c msgdiff.c msgids.c \
	savemem.c shstr.c tmpfile.c
OBJ = copyf.obj fileio.obj hashfile.obj msg2mgt.obj msgcomp2.obj \
	msglib.obj msgmake.obj savemem.obj shstr.obj \
	tmpfile.obj
HDR = fileio.h hashfile.h savemem.h tmpfile.h msgdecl.inc msgfeat.inc yerror.h msgids.h shstr.h copyf.h ..\msgconf2.h
MYCFLAGS = -DRCS_Version=1 # -DTEST=YES
# MSGLIB !:= $(MSGLIB)
MSGDCL !:= yerror.h
MSG2MGT_OBJS = SAVEMEM.obj copyF.obj fileIO.obj hashfile.obj \
	shStr.obj tmpFile.obj msgids.obj
MSGCOMP_OBJS = SAVEMEM.obj copyF.obj fileIO.obj hashfile.obj \
	tmpFile.obj msgids.obj shStr.obj

#
#First target
#
#	Note: A change in the $(LNG) only does *not* cause a change of the
#		lastmake information!
#

all .NOSTATE .SEQUENTIAL : $(PRG)

.IF $(LASTMAKE) != $(THISMAKE)
# Cause to remove all executables, OBJs and such; create the lastmake info
# and delete the directory cache
# Thus, a change in the last make parameters causes to recompile all files.
.INIT .NOSTATE .SEQUENTIAL : lastmakeclean
.ELSE
.IF $(LNG) != $(LASTMAKE_LNG)
# Cause to remove all executables and the $(MSGDCL); create the lastmake info
# and delete the directory cache
# Thus, a change in $(LNG) only causes to relink all executables.
.INIT .NOSTATE .SEQUENTIAL : removeExec mklastmake
.ENDIF
.ENDIF

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

# To remove $(MSGDCL) will force to copy the correct teh *.ftr and *.dcl
# to the files that are read by the local message header file.
removeExec : 
	-$(RM) $(RMFLAGS) $(PRG)
	-touch $(MSGLIBINC)

#
#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=msgTools.csm	\
-f-	\
-ff-	\
-N		\
-m$(_MODEL)

.IF $(USE31) == $(NULL)
CONFIGURATION += -RT-
.ENDIF

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

.ENDIF

#
# Prepare the distribution setup
#
dist distribution .PHONY .NOSTATE .GROUP : dist_clobber keywords.inc
	grep "Release Version $(VERSION)" history
	if not errorlevel 1 echo Version $(VERSION) already released!
	if not errorlevel 1 goto ende
	echo. >changed.111
	echo Release Version $(VERSION): >>changed.111
	echo. >>changed.111
	if exist changed type changed >>changed.111
	if exist changed del changed >nul
	ren changed.111 changed
	if not exist changed goto ende
	call cii
	type $(mktmp @echo off \n ..\\..\\..\\bin\\msgcomp2 /l=l /c=c ..\\..\\..\\include %__lng% $(MSGDCL) msgdecl.inc msgfeat.inc \n) >mkmsglib.bat
.IF $(CFG)
	type $(mktmp $(CONFIGURATION) \n) >$(CFG)
.ENDIF
	type readme.1 >file_id.diz
	type $(mktmp \t\tRelease Version $(VERSION)\n) >>file_id.diz
	type readme.2 >>file_id.diz
	echo VERSION_MAJOR := $(VERSION_MAJOR) >version.mk
	echo VERSION_MINOR := %@eval[$(VERSION_MINOR)+1] >>version.mk


MYLDLIBS2 != $(MSGLIB) $(FDLIB)\SUPPL_$(_MODEL).LIB $(FDLIB)\$(_MODEL:u)_$(LNG).LIB
MYLDLIBS != $(FDLIB)\SUPPL_$(_MODEL).LIB
msglib.com : msglib.obj
msgmake.com : msgmake.obj

msgcomp2.com ?= MYLDLIBS != $(MYLDLIBS2)
msgdiff.com ?= MYLDLIBS != $(MYLDLIBS2)
msg2mgt.com ?= MYLDLIBS != $(MYLDLIBS2)

msgcomp2.exe ?= MYLDLIBS != $(MYLDLIBS2)
msgdiff.exe ?= MYLDLIBS != $(MYLDLIBS2)
msg2mgt.exe ?= MYLDLIBS != $(MYLDLIBS2)

msgcomp2.com : $(MSGLIB) $(MSGINFO) msgcomp2.obj
msgdiff.com : $(MSGLIB) $(MSGINFO) msgdiff.obj
msg2mgt.com : $(MSGLIB) $(MSGINFO) msg2mgt.obj SAVEMEM.obj copyF.obj fileIO.obj shStr.obj tmpFile.obj

msgcomp2.exe : $(MSGLIB) $(MSGINFO) msgcomp2.obj $(MSGCOMP_OBJS)
	$(CC) $(CCLDFLAGS) -e$@ @$(mktmp msgcomp2.obj $(MSGCOMP_OBJS) $(LDLIBS)\n)

msgdiff.exe : $(MSGLIB) $(MSGINFO) msgdiff.obj
msg2mgt.exe : $(MSGLIB) $(MSGINFO) msg2mgt.obj $(MSG2MGT_OBJS)
	$(CC) $(CCLDFLAGS) -e$@ @$(mktmp msg2mgt.obj $(MSG2MGT_OBJS) $(LDLIBS)\n)


keywords.inc .PRECIOUS : $(FDINC:l)\english.msg
	perl -n $(mktmp print "#define $$2 $$1\\n" if /^(\\d+) (IN_[a-zA-Z]+)/;\n) $& > $@

#MAKEDEP START
copyf.obj : copyf.c \
	 copyf.h fileio.h savemem.h
fileio.obj : fileio.c \
	 fileio.h msgdecl.inc msgfeat.inc yerror.h
msg2mgt.obj : msg2mgt.c \
	 ../msgconf2.h copyf.h fileio.h hashfile.h msgdecl.inc msgfeat.inc \
	msgids.h savemem.h shstr.h tmpfile.h yerror.h
msgdiff.obj : msgdiff.c \
	 msgdecl.inc msgfeat.inc yerror.h
msgcomp2.obj : msgcomp2.c \
	 ../msgconf2.h fileio.h hashfile.h keywords.inc msgdecl.inc \
	msgfeat.inc msgids.h savemem.h tmpfile.h yerror.h
shstr.obj : shstr.c \
	 msgdecl.inc msgfeat.inc savemem.h shstr.h yerror.h
tmpfile.obj : tmpfile.c \
	 fileio.h msgdecl.inc msgfeat.inc savemem.h shstr.h tmpfile.h yerror.h
msgmake.obj : msgmake.c
msgids.obj : msgids.c \
	 ../msgconf2.h fileio.h hashfile.h msgdecl.inc msgfeat.inc msgids.h \
	savemem.h tmpfile.h yerror.h
savemem.obj : savemem.c \
	 msgdecl.inc msgfeat.inc savemem.h yerror.h
msglib.obj : msglib.c
hashfile.obj : hashfile.c \
	 fileio.h hashfile.h msgdecl.inc msgfeat.inc savemem.h shstr.h \
	tmpfile.h yerror.h
#MAKEDEP STOP

clean ::
	-$(RM) $(RMFLAGS) $(MSGINFO)

dist_clobber ::
	-$(RM) /fsl=1 errlist changed.bak history.bak 1$(mktmp $(OBJ:t"\n")\n)

clobber :: dist_clobber
	-$(RM) $(RMFLAGS) keywords.inc

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