###################################################################
# ifhp Software
# copyright 1988-2003 Patrick Powell
#    papowell@astart.com
# See LICENSE for conditions of use.
###########################################################################
# $Id: Makefile.in,v 1.116 2004/10/05 15:50:10 papowell Exp papowell $
###########################################################################

PACKAGE=@PACKAGE@
VERSION=3.5.20
SRC=@srcdir@
@SET_MAKE@
prefix=@prefix@
exec_prefix=@exec_prefix@
sysconfdir=@sysconfdir@
mandir=@mandir@
libexecdir=@libexecdir@
INSTALLCMD=@INSTALL@
FILTER_DIR=@FILTER_DIR@
IFHP_CONF=@IFHP_CONF@
LOCALEDIR=@LOCALEDIR@
USE_NLS=@USE_NLS@
SHELL=@SHELL@
CAT=@CAT@
top_builddir=.


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

DIRS= src po man
ALLDIRS= $(DIRS) fonts DOCS
TARGET= ./ifhp.conf

# define default target
MAKETARGET=all

FILES= ./ifhp.conf
all: ${FILES} ${DIRS}

.PHONY: \
	all install ci cifiles clean realclean distclean \
	configure dist tar update send supported FRC ${ALLDIRS}

# we use this to do recursion to specified directories
$(ALLDIRS):
	if [ "$@" = po ] ; then \
	    for i in po/Makefile* ; do \
		if [ -f "$$i" ] ; then \
		    if grep '^mkinstalldirs.*=.*case' $$i ; then \
			echo "fixing broken $$i which causes wrong path to mkinstalldirs to be used"; \
			perl -spi -e 's:^mkinstalldirs\s*=\s*.*:mkinstalldirs = \$$(SHELL) \$$(MKINSTALLDIRS):' $$i; \
		    fi \
		fi \
	    done \
	fi
	if [ "$@" != po -o "$(USE_NLS)" != "no" ] ; then \
		cd $@; $(MAKE) localedir=${LOCALEDIR} \
		DESTDIR=$(DESTDIR) $(MAKETARGET) ; \
	fi

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

install: all
	$(MAKE) MAKETARGET=$@ $(DIRS) DESTDIR=${DESTDIR}
	if [ -n "${VERBOSE_INSTALL}" ] ; then set -x; fi; if [ "${POSTINSTALL}" != "NO" ] ; then \
		if [ -f ${DESTDIR}${IFHP_CONF} ] ; then \
			date=`date | awk '{ print $$6 "_" $$2 "_" $$3 "_" $$4;}'`; \
			mv ${DESTDIR}${IFHP_CONF} ${DESTDIR}${IFHP_CONF}.$$date; \
		fi; \
		d=`dirname ${DESTDIR}${IFHP_CONF}`; \
		if [ ! -d $$d ] ; then ${SHELL} ${SRC}/mkinstalldirs $$d; fi; \
		${INSTALLCMD} -m 644 ./ifhp.conf ${DESTDIR}${IFHP_CONF}.sample; \
		${INSTALLCMD} -m 644 ./ifhp.conf ${DESTDIR}${IFHP_CONF}; \
	fi;
	if [ -n "${VERBOSE_INSTALL}" ] ; then set -x; fi; if [ "${POSTINSTALL}" != "NO" ] ; then \
		if [ ! -d ${DESTDIR}${FILTER_DIR}/UTILS ] ; then ${SHELL} ${SRC}/mkinstalldirs ${DESTDIR}${FILTER_DIR}/UTILS; fi; \
		for f in ${SRC}/UTILS UTILS ; do ( cd UTILS; \
			for i in * ; do \
			if [ -f $$i ] ; then ${INSTALLCMD} -m 644 $$i ${DESTDIR}${FILTER_DIR}/UTILS/$$i; fi; \
		 done; ); done; \
	fi;

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

./ifhp.conf: ${SRC}/ifhp.conf.in Makefile
	rm -f $@
	sed \
		-e "s,.CAT@,$(CAT),g" \
		-e "s,.FILTER_DIR@,$(FILTER_DIR),g" \
		-e "s,.A2PS@,@A2PS@,g" \
		-e "s,.GS@,@GS@,g" \
		-e "s,.GZIP@,@GZIP@,g" \
		-e "s,.FILEUTIL@,@FILEUTIL@,g" \
		-e "s,.PAGE_SIZE@,@PAGE_SIZE@,g" \
		-e "s,.FONT_DIR@,@FONT_DIR@,g" \
		-e "s,.DEVFD3@,@DEVFD3@,g" \
		-e "s,.FOOMATIC@,@FOOMATIC@,g" \
		-e "s,.FOOMATIC_RIP@,@FOOMATIC_RIP@,g" \
			${SRC}/ifhp.conf.in >$@

ci: cifiles
	for i in $(ALLDIRS); do \
	    case $$i in \
	    po ) ;; \
	    * ) $(MAKE) MAKETARGET=$@ $$i ;; \
	    esac; \
	done;
	chmod 755 `find . -name install-sh -print`
	chmod 755 `find . -name mkinstalldirs -print`

#CI=
#CO=-kv
CO=-l

# rcs -l $$1; 
cifiles:
	for i in . $(ALLDIRS); do \
	    if test ! -d $$i/RCS ; then \
	        mkdir $$i/RCS; \
	    fi; \
	done;
	checkin() { \
		ci $(CI) -mUpdate -t-Initial $$1; \
		yes |co $(CO) $$1; \
	}; \
	for i in * po/* UTILS/* ; do \
		if test -f "$$i" ; then \
			case "$$i" in  \
			*.mo ) ;; \
			*.in ) checkin $$i;; \
			config.* ) ;; \
			configure ) ;; \
			* ) checkin $$i ;; \
			esac; \
		fi; \
	done;

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

clean:
	$(MAKE) MAKETARGET=$@ $(DIRS)
	-rm -f *.o *.a ? ?.* *core $(TARGET) po/POTFILES
	-rm -f header *.bak $(SCRIPTS) po/*~

realclean: clean
	$(MAKE) MAKETARGET=$@ $(ALLDIRS)

distclean: clean
	rm -rf DISTRIBUTIONS/FreeBSD*/work DISTRIBUTIONS/FreeBSD*/*.tgz ;
	$(MAKE) MAKETARGET=$@ DESTDIR=$(DESTDIR) $(ALLDIRS)
	-rm -f config.cache config.h config.log config.status
	-rm -f Makefile */Makefile */*core* ltmain
	-rm -f UTILS/*.sh
	rm -f `find . -type f -name '*.old' -print` \
	 `find . -type f -name '*.bak' -print` \
	 `find . -type f -name '*.orig' -print` \
	  Makefile */Makefile po/POTFILES
	rm -f `find . -type f -name '*.in' -print | sed -e 's/\.in$$//' -e /configure/d `

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

configure: configure.in
	autoconf
	autoheader

dist: update ci tar send
redist: ci tar send

send:
	if [ -f ../SENDTO ] ; then cd ..; sh SENDTO; fi

tar: distclean
	DIR=`pwd | sed 's,.*/,,'`; \
	cd ..; \
		tar --exclude '*RCS' -zcf $${DIR}.tgz $${DIR}; \
		md5 $${DIR}.tgz |pgp -fast > $${DIR}.tgz.md5
	@echo "";

update:
	for i in VERSION ./src/patchlevel.h configure.in ; do \
		rcs -l $$i; chmod +w $$i; \
	done;
	DIR=`pwd | sed 's,.*/,,'`; \
	DIRVER=` echo $${DIR} | sed 's,.*-,,'`; \
	echo DIR $${DIR}, DIRVER $${DIRVER}; \
	echo "#define PATCHLEVEL \"$${DIR}\"" >./src/patchlevel.h; \
	echo $${DIR} >VERSION; \
	S=`echo *.sh | sed -e 's/\.sh//g'`; \
	perl -spi -e "s,=.*,=$${DIRVER}, if(/^VERSION=/ or /^#.* VERSION=/); \
		s,^IFHP_VER=.*,IFHP_VER=$${DIRVER},; \
		s,^DISTNAME=.*,DISTNAME=	$${DIR},; \
		s,^PORTNAME=.*,PORTNAME=	$(PACKAGE),; \
		s,^PORTVERSION=.*,PORTVERSION=	$${DIRVER},; \
		s,^Version: .*,Version: $${DIRVER},; \
		s,^Release: .*,Release: 1,; \
		s,package name \".*\",package name \"$${DIR}\",; \
		s,^SCRIPTS=.*,SCRIPTS=$$S,;" \
		Makefile.in configure.in src/Makefile.in ifhp.conf.in \
		DISTRIBUTIONS/*/Makefile \
		DISTRIBUTIONS/*/*.spec \
		po/Makefile.in.in; \
	perl -spi -e 's,.*,"Project-Id-Version: $(PACKAGE) '$${DIRVER}'\\n", if(/^"Project-Id/);' \
		po/*.po
	sh CREATE_CONFIGURE
	sh STANDARD_configuration
	ci -l -mUpdate -t-Initial Makefile
	for i in DOCS man ; do \
		(cd $$i ; $(MAKE) $@; $(MAKE) ); \
	done;
	-for i in po ; do \
		(cd $$i ; $(MAKE) update-po ); \
	done
	$(MAKE) supported

supported:
	perl -i.bak UTILS/supported ifhp.conf.in
