#
# my VI likes these :)
#
#errlist .PHONY :	# create an empty errlist
#	-+type nul >errlist

#	Don't use $& for ctags, because of limited command line length
tags refs .UPDATEALL : $(SRC) $(TAGSRC)
	ctags  *.c

#
# How to make the local message library
#
.IF $(MSGLIB)

COPYINCFILES := $(FDBIN)\DIFFCOPY $(LNG).ftr msgfeat.inc \n $(FDBIN)\DIFFCOPY $(LNG).dcl msgdecl.inc

# this goal has a local message file
$(MSGLIB) .GROUP : $(CFG) $(LNG).msg
# first: create message files
#	Note that $(MSGDCL) is *no* longer modified in any way!
.IF $(NO_GLOBAL_MESSAGE_FILE)
	$(FDBIN)\MsgComp2 /! /c=c.rsp /m=m.rsp /l=l.rsp . $(LNG) $(MSGDCL)
.ELSE
	$(FDBIN)\MsgComp2 /c=c.rsp /m=m.rsp /l=l.rsp $(FDINC)\MSGLIB $(LNG) $(MSGDCL)
.ENDIF
	$Y

	call $(mktmp,q.bat $(COPYINCFILES))

# second: compile message files
.IF $(_COMPILER) == MC
	Type $(mktmp %.obj : %.c ; cc $$< -lp _MICROC_=$(CFLAGS) \n\n) >Makefile.Msg
	Type m.rsp >>Makefile.msg
	$(MAKE) -f Makefile.msg
	$Y
.ELSE
	$(CC) $(CFLAGS) -c @c.rsp
	$Y
.ENDIF

#third: making library
# Built up from zero
	+-if exist $(MSGLIB) del $(MSGLIB) >nul
	$(AR) $(MSGLIB) $(ARFLAGS) @l.rsp, $(MSGLIB:db).lst
	$Y

#forth: cleaning up (rm processes its arguments from left to right!)
	-$(RM) /frsl=1 1c.rsp 1l.rsp c.rsp l.rsp Makefile.msg m.rsp

$(MSGLIBINC) .UPDATEALL : $(MSGLIB)

$(MSGINFO) .NOSTATE .NOINFER .UPDATEALL .GROUP : $(MSGLIBINC)
	call $(mktmp,$(TMPFILE).bat $(COPYINCFILES))

copyMsglibIncFiles .GROUP :
	if not exist $(LNG).ftr goto ende
	if not exist $(LNG).dcl goto ende
	call $(mktmp,$(TMPFILE).bat $(COPYINCFILES))

.ENDIF

# Default cleaning-up's

clean .NOSWAP .NOSTATE .PHONY ::
	-$(RM) /fsl=! !c.rsp !l.rsp 
	-$(RM) /fsl=1 <$(mktmp \
$(OBJ:t"\n") \n\
errlist $(CFG) tags refs c.rsp l.rsp Makefile.msg m.rsp msgLib.rsp \n\
obj1.rsp lib1.rsp \n\
$& \
)

clobber cleanall .NOSWAP .NOSTATE .NOINFER .PHONY :: clean
	-$(RM) /fsl=1 <$(mktmp lastmake.mk $(LNG).mk q*.asm q*.cp q*.co $$*.asm $$*.cp $$*.co *.csm *.ftr *.dcl $(MSGLIB) $(MSGLIB:db).lst $(PRG:t"\n") $(MSGINFO) $&\n)

.IF $(_HAVE_RCS)
.IF $(STATE)
_RCS_STATE := -s$(STATE)
.ELSE
_RCS_STATE :=
.ENDIF
ci .NOSTATE .NOINFER .PHONY : $(SRC) $(HDR) $(shell if exist *.msg dir /b *.msg)
	+@echo Using Macro NAME "$(NAME)" for symbolic revision number
	+@echo Using Macro STATE "$(STATE)" for state (optional)
.IF $(NAME)
	-$(FDBIN)\xargs /$(mktmp $(&:t"\n") \n) $(shell $(FDBIN)\WhichIs ci) -l -f $(_RCS_STATE) -N$(NAME)
	-$(FDBIN)\xargs /$(mktmp $(&:t"\n") \n) $(shell $(FDBIN)\WhichIs touch)
.ENDIF

.ENDIF

# Documentation related stuff
%.man : %.nro ; nro.com -man -b -u $< >$@

%.tx : %.man ; interprete.exe <$< >$@

# Let's leave the man pages
manpage : $(LNG).man

documentation doc .UPDATEALL : manpage $(LNG).tx

lastmakeclean .NOSTATE .NOINFER .SEQUENTIAL : clean mklastmake

mklastmake .GROUP .NOSTATE .NOINFER :
	Type $(mktmp \nLASTMAKE_MODEL = $(_MODEL) \n\
LASTMAKE_COMPILER = $(_COMPILER) \n\
LASTMAKE_NDEBUG = $(null,$(NDEBUG) $(NULL) Y) \n) > $(LNG).mk
	Echo LASTMAKE_LNG = $(LNG) >lastmake.mk
