###########################################################################
# LPRng - An Extended Print Spooler System
#
# Copyright 1988-1995 Patrick Powell, San Diego, CA
#     papowell@astart.com
# See LICENSE for conditions of use.
#
###########################################################################
# MODULE: Makefile.in
# PURPOSE: top level Makefile for LPD Software
# Makefile.in,v 3.23 1998/03/29 19:39:21 papowell Exp
########################################################################## 

#**************###########**************
# You must use ANSI C and GNU Make!
#***************************************

SRC=@srcdir@
@SET_MAKE@

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

DIRS= src man po
ALLDIRS= $(DIRS) ${SRC}/TESTSUPPORT ${SRC}/UTILS ${SRC}/HOWTO

all: $(DIRS)

# define default target
.PHONY: all warn \
	TAGS clean uninstall install \
	info dvi check \
	realclean mostlyclean distclean \
	dist ci cifiles FRC default newmake cifast
MAKETARGET=all


#force phony target to be made
# Note: all the lines to the next comment will be removed
# when generating the BSD version
$(ALLDIRS): FRC
	(cd $@; $(MAKE) -f Makefile.bsd $(MAKEFLAGS) $(MAKETARGET))

FRC:

#install default versions of the lpd.conf and lpd.perm files
default:
	cp ${SRC}/lpd.conf ${SRC}/lpd.perms /etc

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

TAGS clean uninstall install: 
	$(MAKE) -f Makefile.bsd MAKETARGET=$@ $(DIRS)

info dvi check:

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



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

cifast ci: cifiles
	for i in $(ALLDIRS); do \
		if test ! -d $$i/RCS ; then \
			mkdir $$i/RCS; \
		fi; \
	done; \
	$(MAKE) MAKETARGET=$@ $(ALLDIRS)

CI=
CO=-kv

cifiles: newmake
	if test ! -d RCS ; then mkdir RCS; fi;
	checkin() { \
		rcs -l $$1; \
		ci $(CI) -mUpdate -t-Initial $$1; \
		yes |co $(CO) $$1; \
	}; \
	for i in *; do \
		if test -f "$$i" ; then \
			case "$$i" in  \
			config.h.in ) checkin $$i;; \
			config.* ) ;; \
			configure ) ;; \
			* ) 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; \
		sed -e '/^#GNU/,/^#/d' -e 's/^#BSD.//' -e 's/$$>/$$>/' \
		 -e	's/^if/.if/' -e 's/^endif/.endif/' $$i >/tmp/Makefile.bsd.in; \
		if test -f $$c ; then rm -f $$c; fi; cp /tmp/Makefile.bsd.in $$c;\
		done

###############################################################################
# Update the patch level when you make a new version
# do this before you start changes
# Don't even think about making this configurable, it is for
# distribution and update purposes only!
#  Patrick Powell
###############################################################################

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

	DIR=`pwd | sed 's,.*/,,' `; \
		echo "#define PATCHLEVEL " \"$$DIR\" >./src/include/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 ;

	(cd man; $(MAKE) update)
	

###############################################################################
# Make a gnutar distribution
#   - note that not all the source tree is sent out
#
###############################################################################

shar:
	DIR=`pwd | sed 's,.*/,,' `; \
	cd ..; \
	ls -l $${DIR}.tgz ; \
	if [ ! -f $${DIR}.tgz ]; then \
		echo You must make TAR file first; \
		exit 1; \
	fi; \
	tar ztf $${DIR}.tgz | sed -e '/\/$$/d' | sort >/tmp/_a.list; \
	head /tmp/_a.list; \
	shar -S -n $${DIR} -a -s papowell@astart.com \
	   -c -o /tmp/$${DIR}-Part -l100 </tmp/_a.list; \
	cat $${DIR}/README /tmp/$${DIR}-Part.01 >/tmp/_a.list; \
	cat >/tmp/$${DIR}-Part.01 /tmp/_a.list; \
	rm /tmp/_a.list

dist_list:
	echo RCS >/tmp/X
	if [ -n "$$NO" ]; then \
		for i in $$NO ; do \
			echo "*/$$i"  >>/tmp/X; \
		done; \
	fi;
	for i in Makefile.old  Makefile.in.old \
		'*src/Makefile' '*man/Makefile' \
		'*TESTSUPPORT/Makefile' \
		Makefile.bsd '*src/Makefile.bsd' '*man/Makefile.bsd' \
		'*TESTSUPPORT/Makefile.bsd' ; do echo $$i >>/tmp/X; done;
	echo core >>/tmp/X
	echo '*core' >>/tmp/X
	echo '*.orig' >>/tmp/X
	echo '*.bak' >>/tmp/X
	echo '*.rej' >>/tmp/X
	echo '*.tex' >>/tmp/X
	echo '*.ps' >>/tmp/X
	echo '*.dvi' >>/tmp/X
	echo '*.log' >>/tmp/X
	echo '?' >>/tmp/X
	echo '*.o' >>/tmp/X
	echo '*.a' >>/tmp/X
	echo '*,v' >>/tmp/X
	echo '*intl/po2tbl.sed' >>/tmp/X
	echo '*po/POTFILES' >>/tmp/X
	for i in tags \
		authenticate_pgp readfilecount removeoneline setupauth \
		sserver sclient \
		liblpr.a checkpc lpr lpd lpq lprm lpc lpbanner \
		lpf lpraccnt monitor lp cancel lpstat \
			; do \
		echo "*/$$i"  >>/tmp/X; \
	done;
	echo config.cache >>/tmp/X
	echo config.status >>/tmp/X
	echo config.log >>/tmp/X
	echo config.h >>/tmp/X
	DIR=`pwd | sed 's,.*/,,' `; \
		cd ..; \
		echo $${DIR}/Makefile >>/tmp/X;
#	cat /tmp/X

dist: dist_list
	DIR=`pwd | sed 's,.*/,,' `; \
		cd ..; \
		tar zXcf /tmp/X $${DIR}.tgz $${DIR}; \
		md5 $${DIR}.tgz | pgp -fast -u papowell@astart > $${DIR}.tgz.md5

dist_doc: dist_list
	echo src >>/tmp/X
	echo LP_SIMULATION >>/tmp/X
	echo UTILS >>/tmp/X
	DIR=`pwd | sed 's,.*/,,' `; \
		cd ..; \
		tar zXcf /tmp/X $${DIR}_doc.tgz $${DIR}; \
		md5 $${DIR}_doc.tgz > $${DIR}_doc.md5
	
dist_src: dist_list
	echo man >>/tmp/X
	DIR=`pwd | sed 's,.*/,,' `; \
		cd ..; \
		tar zXcf /tmp/X $${DIR}_src.tgz $${DIR}; \
		md5 $${DIR}_src.tgz > $${DIR}_src.md5
