###########################################################################
# ifhp Software
# copyright 1988-1998 Patrick Powell
#    papowell@astart.com 
# See LICENSE for conditions of use.
###########################################################################
# $Id: Makefile.in,v 1.1.1.2 1999/05/21 22:19:53 danw Exp $
########################################################################## 

SRC=@srcdir@
@SET_MAKE@
INSTALLCMD=@INSTALL@
ADMINDIR=@ADMINDIR@

#=============================================================================
# List the directories you want to generate:
# DIRS for all, clean, etc.
# ALLDIRS for other such as documentation
#=============================================================================

DIRS= src man
ALLDIRS= $(DIRS) fonts HOWTO
TARGET=

# define default target
MAKETARGET=all

all: $(DIRS)

.PHONY: all clean FRC install tar ci cifiles DIRS ALLDIRS warn
#force phony target to be made

$(ALLDIRS): FRC
#GNU
	$(MAKE) -C $@ $(MAKETARGET) 
#
#BSD 	(cd $@; $(MAKE) -f Makefile.bsd $(MAKEFLAGS) $(MAKETARGET))

FRC:
###############################################################################

install: all
	$(MAKE) MAKETARGET=$@ $(DIRS)

###############################################################################

init:
	if [ ! -d $(ADMINDIR) ] ; then \
		$(SRC)/mkinstalldir $(ADMINDIR); \
	fi;
	if [ ! -f $(ADMINDIR)/ifhp.conf ] ; then \
		$(INSTALLCMD) -m 755 $(SRC)/ifhp.conf $(ADMINDIR); \
	else \
		$(INSTALLCMD) -m 755 $(SRC)/ifhp.conf $(ADMINDIR)/ifhp.conf.sample; \
	fi;
		
ci: cifiles
	if test ! -d RCS ; then mkdir RCS; fi;
	$(MAKE) MAKETARGET=$@ $(ALLDIRS)

CI=
#CO=-kv
CO=-l

cifiles: newmake
	if test ! -d RCS ; then mkdir RCS; fi;
	checkin() { \
		rcs -l $$1 ; \
		ci $(CI) -mUpdate -t-Initial $$1; \
		co $(CO) $$1; \
	}; \
	for i in *; do \
		if test -f "$$i" ; then \
			case "$$i" in  \
			config.h.in ) checkin $$i;; \
			config.* ) ;; \
			* ) checkin $$i ;; \
			esac; \
		fi; \
	done;

newmake:
	for i in Makefile.in */Makefile.in ; do \
		d=`dirname $$i`; b=`basename $$i .in`; c=$${d}/$${b}.bsd.in; \
		echo $$i $$c; \
		sed -e '/^#GNU/,/^#/d' -e 's/^#BSD.//' -e 's/$$^/$$>/' \
		 -e	's/^if /.if /' -e 's/^endif/.endif/' $$i >/tmp/Makefile.bsd.in; \
		rm -f $$c ; cp /tmp/Makefile.bsd.in $$c;\
	done;

###############################################################################

clean:
	-rm -f *.o *.core core $(TARGET)
	$(MAKE) MAKETARGET=$@ $(DIRS)

realclean distclean: clean
	$(MAKE) MAKETARGET=distclean $(ALLDIRS)
	-rm -f Makefile Makefile.bsd \
		config.cache config.h config.log config.status

###############################################################################

shar:
	DIR=`pwd | sed 's,.*/,,' `; \
	if [ ! -f /tmp/$${DIR}.tgz ]; then \
		echo You must make TAR file first; \
		exit 1; \
	fi; \
	cd ..; tar ztf /tmp/$${DIR}.tgz | sed -e '/\/$$/d' |  \
		shar -S -n $${DIR} -a -s papowell@astart.com \
		   -c -o /tmp/$${DIR}-Part -L100

configure: configure.in
	autoconf
	autoheader

dist: configure
	$(MAKE) ci
	$(MAKE) update
	$(MAKE) newmake
	echo RCS >/tmp/L_X
	echo DOCS >>/tmp/L_X
	echo PPD >>/tmp/L_X
	echo Makefile >>/tmp/L_X
	echo core >>/tmp/L_X
	echo '?' >>/tmp/L_X
	echo '*.o' >>/tmp/L_X
	echo '*,v' >>/tmp/L_X
	echo '*.a' >>/tmp/L_X
	echo '*.orig' >>/tmp/L_X
	echo '*.rej' >>/tmp/L_X
	echo '*.sh' >>/tmp/L_X
	echo '*ifhp' >>/tmp/L_X
	echo '*status' >>/tmp/L_X
	echo '*monitor' >>/tmp/L_X
	echo '*textps' >>/tmp/L_X
	for i in $(TARGET) Makefile config.cache config.h config.log config.status; \
		 do echo \*/$$i >>/tmp/L_X; done
	cat /tmp/L_X
	DIR=`pwd | sed 's,.*/,,' `; \
	cd ..; \
		tar zXcfv /tmp/L_X $${DIR}.tgz $${DIR}; \
		md5 $${DIR}.tgz |pgp -fast > $$DIR.tgz.md5

cifast:
	find . -type f -newer VERSION -print \
		| sed \
			-e '/core$$/d' \
			-e '/RCS/d' \
			-e '/\.o$$/d'  \
			-e '/.*liblpr.a$$/d' \
			-e '/.*checkpc$$/d' \
			-e '/.*lpr$$/d' \
			-e '/.*lpd$$/d' \
			-e '/.*lpq$$/d' \
			-e '/.*lprm$$/d' \
			-e '/.*lpc$$/d' \
			-e '/.*lpbanner$$/d' \
			-e '/.*lpf$$/d' \
			-e '/.*lpraccnt$$/d' \
		 >/tmp/list
	echo README >>/tmp/list
	cat /tmp/list
	checkin() { \
		rcs -l $$1 ; \
		ci $(CI) -mUpdate -t-Initial $$1; \
		co $(CO) $$1; \
	}; \
	for i in ` cat /tmp/list `; do \
		checkin $$i; \
	done;

update:
	for i in VERSION ./src/patchlevel.h configure.in configure; do \
		rcs -l $$i; chmod +w $$i; \
	done;

	DIR=`pwd | sed 's,.*/,,' `; \
		echo "#define PATCHLEVEL " \"$$DIR\" >./src/patchlevel.h; \
		sleep 1; \
		echo $$DIR >VERSION ; \
		cp configure.in /tmp/configure.in; \
		D=`echo $$DIR | sed 's,.*-,,' ` ; \
		sed "s,VERSION=.*,VERSION=$$D," </tmp/configure.in >configure.in; \
		cp configure /tmp/configure; \
		sed "s,VERSION=.*,VERSION=$$D," </tmp/configure >configure ;

	$(MAKE) newmake
	$(MAKE) MAKETARGET=$@ HOWTO man
