##  $Revision: 1.23 $
SHELL	= /bin/sh
MAKE	= make

CONF	= config.data
FILE	= files.list
LIST	= `grep -v '^;' <$(FILE)`

##  Pick your method of source control:  RCS, SCCS, or NONE
SRCCTL		= NONE
CHECKOUT	= $(SRCCTL)-checkout
CHECKIN		= $(SRCCTL)-checkin

##  If you use the script version of subst, and your version of sed chokes
##  then get FSF sed and edit the next line as appropriate.
#SED	= -e /usr/gnu/bin/sed


all:			substitutions

# Yes, we really want to do nothing here!
install:

clobber clean:
	rm -f subst.tmp config.new subst substitutions
	rm -f all install lint profiled

quiet:
	@$(MAKE) 'FILE=$(FILE)' substitutions | grep -v unchanged

tags ctags:
	cp /dev/null tags

lint profiled:
	cp /dev/null $@

substitutions:		$(CHECKOUT) subst files.list $(CONF)
	-@rm -f ../*/substtmp.new ../*/substtmp.old
	@sh ./checkconf.sh $(CONF)
	./subst $(SED) -f $(CONF) $(LIST)
	@sh ../iftrue.sh '$(SRCCTL) != NONE' '$(MAKE) $(CHECKIN)'

RCS-checkout:
	co -l $(LIST)
RCS-checkin:
	ci $(LIST)
SCCS-checkout:
	sccs get -e $(LIST)
SCCS-checkin:
	sccs delta $(LIST)
NONE-checkout:
	-chmod +w $(LIST)
NONE-checkin:

backup:
	@sh ../iftrue.sh '-d ORIG' 'echo ORIG exists! ; exit 1'
	mkdir ORIG
	@for I in $(LIST) ; do \
	    echo cp $$I ORIG ; \
	    cp $$I ORIG ; \
	done

restore:
	@sh ../iftrue.sh '! -d ORIG' 'echo No ORIG directory! ; exit 1'
	@for I in $(LIST) ; do \
	    echo cp ORIG/`basename $$I` $$I ; \
	    cp ORIG/`basename $$I` $$I ; \
	done

config.data:		config.dist
	@sh ../iftrue.sh '-f config.new' 'echo config.new exists! ; exit 1'
	@sh ../iftrue.sh '-f config.old' 'echo config.old exists! ; exit 1'
	@sh ../iftrue.sh '! -f config.data' '$(MAKE) CLOBBER=YES SCRATCH'
	cat config.data config.dist >subst.tmp
	cp config.dist config.new
	./subst $(SED) -f subst.tmp config.new
	-@rm -f subst.tmp
	@echo "Update config.old from config.new!"
	@sh ../iftrue.sh '-f config.data' \
	 'echo "Renaming config file to config.old"; mv config.data config.old'
	exit 1 ;
SCRATCH:
	@sh ../iftrue.sh '-z $(CLOBBER)' 'echo No way! ; exit 1'
	@echo 'You do not have a config.data file.'
	@echo 'Setting one up using the default file.'
	@echo 'You must edit this file, then remove config.new and config.old.'
	@echo 'Then restart the make.'
	cat config.dist >config.data

subst:		subst.c subst.sh
	-make c || make sh || rm -f subst
	@sh ../iftrue.sh '! -f subst' 'echo Cannot make subst ; exit 1'
c:
	@rm -f subst
	$(CC) -o subst subst.c
sh:
	@rm -f subst
	cp subst.sh subst
	chmod +x subst

.PRECIOUS:	$(CONF) files.list

##  Dependencies.  Default list, below, is probably good enough.
depend:		Makefile $(SOURCES)
	makedepend $(DEFS) $(SOURCES)

# DO NOT DELETE THIS LINE -- make depend depends on it.
