###########################################################################
# LPRng - An Extended Print Spooler System
#
# Copyright 1988-1995 Patrick Powell, San Diego State University
#     papowell@sdsu.edu
# See LICENSE for conditions of use.
#
###########################################################################
# MODULE: Makefile.in
# PURPOSE: top level Makefile for LPD Software
# $Id: Makefile.in,v 1.1 2004/07/08 05:03:36 jam Exp $
########################################################################## 

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
ALLDIRS= $(DIRS)
TARGET=monitor ifhp

# define default target
MAKETARGET=all

all: $(DIRS)

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

$(ALLDIRS):
	cd $@; $(MAKE) $(MAKETARGET) 

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

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

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

ci: cifiles
	if test ! -d RCS ; then mkdir RCS; fi;
	$(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; \
		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; \
		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 $(TARGET)
	$(MAKE) MAKETARGET=$@ $(DIRS)

realclean distclean: clean
	$(MAKE) MAKETARGET=distclean $(DIRS)
	-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@sdsu.edu \
		   -c -o /tmp/$${DIR}-Part -L100

dist: clean
	echo RCS >/tmp/L_X
	echo Makefile >>/tmp/L_X
	echo Makefile.bsd >>/tmp/L_X
	echo core >>/tmp/L_X
	echo '?' >>/tmp/L_X
	echo '*.o' >>/tmp/L_X
	echo '*.a' >>/tmp/L_X
	echo '*.sh' >>/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 src/version.h VERSION; do \
		chmod +w $$i; \
	done;
	pwd | sed -n -e 's,.*/,,' -e 's,.*,#define VERSION "&",p' > src/version.h
	pwd | sed -n -e 's,.*/,,' -e 's,.*,VERSION &,p' > VERSION
	(cd man; $(MAKE) update)
