##!dmake -f

# main goal of this Makefile:
# $(_MODEL)_$(LNG): FreeDos message library
# This library is automatically copied into $(FDLIB)

# The make process is as following:
# 1. Create the "normal" message library $(LNG).LIB according $(LNG).MSG
#    but the path to the gloabl message file is ".",& the "/!" switch
#    is supplied to the message compiler
# 2. The local source code files are compiled
# 3. The message library $(LIB).LIB is copied to $(_MODEL)_$(LNG).LIB and
#    the newly make'ed object files are appended to this one
# 4. The library and the header fiels are copied into the $(FREEDOS) tree

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

#
#Project related settings
#
PRG = t_$(LNG).lib s_$(LNG).lib m_$(LNG).lib c_$(LNG).lib l_$(LNG).lib h_$(LNG).lib
XPRG = $(_MODEL)_$(LNG).lib
SRC = MSG2RTRV.C chkansi.c closefd.c cntry.c dupfd.c getoptx.c hp-cats.c \
	idntstr0.c msg0init.c msg1emit.c msg1gop1.c msg1gop2.c msg1gop3.c \
	msg1gopt.c msg1hlps.c msg1prnt.c msg2cat.c msg2cats.c msg2chg.c \
	msg2clng.c msg2code.c msg2cset.c msg2db.c msg2emit.c msg2free.c \
	msg2gcat.c msg2get.c msg2gop1.c msg2gop2.c msg2gop3.c msg2gopt.c \
	msg2hlps.c msg2icat.c msg2idnt.c msg2init.c msg2lmsg.c msg2lock.c \
	msg2mcat.c msg2prnt.c msg2read.c msg2sclr.c msg2ulck.c msg2ulks.c \
	msgapp.c msgexit.c mtch_cst.c scanlngs.c scanmsg1.c srch_str.c \
	valid_mn.c
OBJ = MSG2RTRV.obj chkansi.obj closefd.obj cntry.obj dupfd.obj getoptx.obj \
	hp-cats.obj idntstr0.obj msg0init.obj msg1emit.obj msg1gop1.obj \
	msg1gop2.obj msg1gop3.obj msg1gopt.obj msg1hlps.obj msg1prnt.obj \
	msg2cat.obj msg2cats.obj msg2chg.obj msg2clng.obj msg2code.obj \
	msg2cset.obj msg2db.obj msg2emit.obj msg2free.obj msg2gcat.obj \
	msg2get.obj msg2gop1.obj msg2gop2.obj msg2gop3.obj msg2gopt.obj \
	msg2hlps.obj msg2icat.obj msg2idnt.obj msg2init.obj msg2lmsg.obj \
	msg2lock.obj msg2mcat.obj msg2prnt.obj msg2read.obj msg2sclr.obj \
	msg2ulck.obj msg2ulks.obj msgapp.obj msgexit.obj mtch_cst.obj \
	scanlngs.obj scanmsg1.obj srch_str.obj valid_mn.obj
HDR = msglib.h msg2.h fileio.h cntry.h msg2_cfg.h msgdecl.inc msgconf2.h ..\suppl\getopt.c msg_cfg.h msgfeat.inc getopt.inc msgemit.inc nl_types.h msgprntf.inc yerror.h msghlpsc.inc
MYCFLAGS = # TEST=YES

MSGDCL !:= yerror.h

MODELS_MC = s
MODELS_BC = t s m c l h
MYCFLAGS = # TEST=YES


#
#First target
#
all : $(CFG) $(XPRG)

new .GROUP :
	+- del lastmake.mk
	+- del $(LNG).mk

copylib .GROUP : all	# copy library into Free-Dos library dir
	-+if not exist $(FDLIB)\NUL mkdir $(FDLIB)
	-+if not exist $(FDLIB)\NUL echo Cannot make LIB directory $(FDLIB)
	-+if not exist $(FDLIB)\NUL goto ende
	-+copy $(XPRG) $(FDLIB) >nul
	-+copy $(XPRG:db).lst $(FDLIB) >nul
	-+copy $(LNG).msg $(FDINC) >nul
	-+type $(mktmp >>>>>>I_features\n) >>$(FDINC)\$(LNG:u).msg
	-+type msgfeat.inc >>$(FDINC)\$(LNG:u).msg
	-+copy msglib.h $(FDINC) >nul
	-+copy msgdecl.inc $(FDINC)\Msglib.dcl >nul
	-+copy template.h $(FDINC) >nul
.IF $(MCDIR)
	-+copy msglib.h $(MCDIR) >nul
	-+copy template.h $(MCDIR) >nul
.ENDIF

#
# Create the distribution ZIP
#
binDist .SETDIR=bin :
	dmake distribution

dist distribution .PHONY .NOSTATE .GROUP : clobber binDist
	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 $(SRC:t"\n")\n) >compile.ccc
	type $(mktmp $(SRC:db:+".obj":t"\n")\n) >compile.lll
# As this Makefile is prepared only for Micro-C and Borland C
	type $(mktmp $(SRC_ADD:t"\n")\n) >dyn_src
	type $(mktmp $(SRC_ADD:db:+".obj":t"\n")\n) >dyn_obj
	type $(mktmp $(SRC_ADD_MC:t"\n")\n) >mc_compile.ccc
	type $(mktmp $(SRC_ADD_MC:db:+".obj":t"\n")\n) >mc_compile.lll
	type $(mktmp $(SRC_ADD_BC:t"\n")\n) >bc_compile.ccc
	type $(mktmp $(SRC_ADD_BC:db:+".obj":t"\n")\n) >bc_compile.lll
	type $(mktmp @echo off \n ..\\..\\bin\\msgcomp2 /! /l=dyn_obj /c=dyn_src . %__lng% $(MSGDCL) msgdecl.inc msgfeat.inc \n) >mkdynsrc.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
	mk_dist
	$Y
	cd dist
	zip -9 -r -m ..\MSGLB$(VERSION:s/.//) fdos file_id.diz
	cd ..
	rmdir dist
	$Y
	echo VERSION_MAJOR := $(VERSION_MAJOR) >version.mk
	echo VERSION_MINOR := %@eval[$(VERSION_MINOR)+1] >>version.mk

# Check, if this will compile under other circumstances
.IF $(THISMAKE) != $(LASTMAKE)

bark_ :
	+-@echo Change in Make parameters detected, local files invalid!

.INIT .NOINFER .NOSTATE : bark_ libclobber mklastmake $(CFG) errlist # Will make the utilizing files
	
.ELSE

.INIT .NOINFER .NOSTATE : $(CFG) errlist # Will make the utilizing files
.ENDIF


#
#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-	\
-m$(_MODEL) \
-w

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

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

.ENDIF


t_$(LNG) : 
	$(MAKE) MODEL!:=t all
s_$(LNG) : 
	$(MAKE) MODEL!:=s all
m_$(LNG) : 
	$(MAKE) MODEL!:=m all
c_$(LNG) : 
	$(MAKE) MODEL!:=c all
l_$(LNG) : 
	$(MAKE) MODEL!:=l all
h_$(LNG) : 
	$(MAKE) MODEL!:=h all

.IF $(_COMPTYPE) == MC
alllibs : t_$(LNG) s_$(LNG)
.ELSE
alllibs : $(PRG)
.ENDIF

# Just copy the library
$(XPRG) :: $(MSGLIB) ; -+copy83 $< $@

$(XPRG) .GROUP :: $(OBJ_ADD) $(OBJ)
	$(AR) $@ $(ARFLAGS) @$(mktmp +- $(<:t" &\n+- ") \n), $(@:db).lst
	$Y
#	-$(RM) /fl=1 <$(mktmp $(OBJ:t"\n") \n)



test.exe : $(XPRG) test.c

#MAKEDEP START
msg2db.obj : msg2db.c \
	 msg2.h msg2_cfg.h msgconf2.h msglib.h
msg1gop2.obj : msg1gop2.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
mtch_cst.obj : mtch_cst.c \
	 msg2.h msg2_cfg.h msgconf2.h
cntry.obj : cntry.c \
	 cntry.h
dupfd.obj : dupfd.c \
	 msg2.h msg2_cfg.h msgconf2.h
msgapp.obj : msgapp.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msglib.h yerror.h
msg2emit.obj : msg2emit.c \
	 msg_cfg.h msgdecl.inc msgemit.inc msgfeat.inc msglib.h yerror.h
msg2prnt.obj : msg2prnt.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msglib.h msgprntf.inc yerror.h
msg2gop2.obj : msg2gop2.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
valid_mn.obj : valid_mn.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2clng.obj : msg2clng.c \
	 msg2.h msg2_cfg.h msgconf2.h
hp-cats.obj : hp-cats.c \
	 msg2.h msg2_cfg.h msgconf2.h nl_types.h
msg0init.obj : msg0init.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msglib.h yerror.h
msg2code.obj : msg2code.c \
	 msg2.h msg2_cfg.h msgconf2.h
msgexit.obj : msgexit.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msglib.h yerror.h
msg2read.obj : msg2read.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2get.obj : msg2get.c \
	 fileio.h msg2.h msg2_cfg.h msgconf2.h
msg2cat.obj : msg2cat.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg1gop1.obj : msg1gop1.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
msg2idnt.obj : msg2idnt.c \
	 fileio.h msg2.h msg2_cfg.h msgconf2.h
msg1gopt.obj : msg1gopt.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
msg2chg.obj : msg2chg.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg1hlps.obj : msg1hlps.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msghlpsc.inc msglib.h yerror.h
msg2cats.obj : msg2cats.c \
	 msg2.h msg2_cfg.h msgconf2.h
idntstr0.obj : idntstr0.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2sclr.obj : msg2sclr.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2gop1.obj : msg2gop1.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
closefd.obj : closefd.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2gopt.obj : msg2gopt.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
msg2free.obj : msg2free.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2hlps.obj : msg2hlps.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msghlpsc.inc msglib.h yerror.h
msg2gcat.obj : msg2gcat.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2mcat.obj : msg2mcat.c \
	 msg2.h msg2_cfg.h msgconf2.h
scanmsg1.obj : scanmsg1.c \
	 fileio.h msg2.h msg2_cfg.h msgconf2.h
msg2lmsg.obj : msg2lmsg.c \
	 msg2.h msg2_cfg.h msgconf2.h
scanlngs.obj : scanlngs.c \
	 cntry.h fileio.h msg2.h msg2_cfg.h msgconf2.h
msg2init.obj : msg2init.c \
	 cntry.h msg2.h msg2_cfg.h msgconf2.h
getoptx.obj : getoptx.c \
	 ../suppl/getopt.c getopt.inc
msg1gop3.obj : msg1gop3.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
msg2lock.obj : msg2lock.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2ulks.obj : msg2ulks.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2ulck.obj : msg2ulck.c \
	 msg2.h msg2_cfg.h msgconf2.h
chkansi.obj : chkansi.c
MSG2RTRV.obj : MSG2RTRV.C \
	 msg2.h msg2_cfg.h msgconf2.h
msg2gop3.obj : msg2gop3.c \
	 ../suppl/getopt.c getopt.inc msg_cfg.h msgdecl.inc msgfeat.inc \
	msglib.h yerror.h
srch_str.obj : srch_str.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2icat.obj : msg2icat.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg2cset.obj : msg2cset.c \
	 msg2.h msg2_cfg.h msgconf2.h
msg1emit.obj : msg1emit.c \
	 msg_cfg.h msgdecl.inc msgemit.inc msgfeat.inc msglib.h yerror.h
msg1prnt.obj : msg1prnt.c \
	 msg_cfg.h msgdecl.inc msgfeat.inc msglib.h msgprntf.inc yerror.h
#MAKEDEP STOP

# LIB_CLEAN holds files that must not been clobbered while a LASTMAKE change
#LIB_CLEAN := 
#libclobber ?= LIB_CLEAN := 
libclobber : clobber
#.IF $(CFG)
#	+Type $(mktmp $(CONFIGURATION)) >$(CFG)
#.ENDIF

clean ::
	-$(RM) /sfl=1 1$(mktmp $(LIB_CLEAN) $(LIB_CLEAN:db:+".obj"))
	-$(RM) /sf ?_*.bak ?_*.lst
	-$(RM) /sf *.xcc *.xll *.ccc *.lll

clobber ::
	-$(RM) /sfl=1 1$(mktmp ?_*.lib $(OBJ) q*.asm q*.cp $$*.asm $$*.cp)

# source in the Free-Dos standard targets 
NO_GLOBAL_MESSAGE_FILE := yes

.INCLUDE .FIRST .IGNORE : fd_exit.mk ../fd_exit.mk ../../fd_exit.mk
