# Master Makefile for the ZMailer

# From  configure.in  !
VERSION   =  2.99.56
BUGREPORT = "zmhack@nic.funet.fi"


srcdir = .



DESTDIR=
prefix=

ZCONFIG = /opt/mail/zmailer.conf
ZCONF   = ./zmailer.Config
#ZDEPEND = Dependencies
CPPDEP  =  gcc -MM
MKDIR   =  mkdir -p
MAILBIN =  $(DESTDIR)/opt/mail/bin

SHELL = /bin/sh

DISTFILES = COPYING COPYING.LIB ChangeLog Makefile.in README INSTALL \
NEWS configure configure.in config.h.in mkinstalldirs install-sh \
stamp-h.in acconfig.h

# Redundant stuff for making only selected programs.
PROGS	= router/router scheduler/scheduler			\
	scheduler/mailq smtpserver/smtpserver transports/-ok	\
	compat/rmail/rmail compat/sendmail/sendmail		\
	utils/vacation/vacation utils/makedb/makedb

# Subdirectories to run make in for the primary targets.
SUBDIRS =  smtpserver router scheduler transports compat utils
# Subdirectories where to run 'make clean'
MOREDIRS = libs lib libc libsh libident libmalloc libresolv ssl \
	   proto doc man
MOREDIRS2 = sfio
# Files to remove in cleanup
CLEANFILES = include/rfc822.entry $(ZCONF) version.c

DISTCLEANFILES = include/mail.h SiteConfig bin/mklibdeb bin/mkdeb	\
		utils/zmailer.init.sh	proto/cf/SMTP+UUCP.cf	\
		proto/cf/TELE-FI.cf	proto/cf/UTdefault.cf	\
		proto/db/aliases				\
		man/Makefile		proto/db/Makefile	\
		bin/mkdep		bin/mklibdep

#.SUFFIXES:

all: config.h Makefile rfc822.entry $(ZCONF) SiteConfig \
     libs/libtag include/sfio.h
	#rm -f libs/libtag
	for subdir in $(SUBDIRS); do \
		echo making $@ in $$subdir; \
		(cd $$subdir && $(MAKE) $(MFLAGS) $@) || exit 1; \
	done

#	If need be, "make libs" at the top-level will remake all libraries

include/sfio.h libs/libtag libs: force
	cd libs && $(MAKE) $(MFLAGS) all


info dvi:
	cd doc && $(MAKE) $@

check:
installcheck:


rfc822.entry: include/rfc822.entry

include/rfc822.entry:
	cd router ; $(MAKE) $(MFLAGS) rfc822.entry

install-cf:	# all
	@if [ -n "${prefix}" -a -z "${DESTDIR}" ] ; then echo "INSTEAD OF  prefix=  PLEASE INSTALL WITH:  DESTDIR=.. parameter"; exit 1; fi
	@. $(ZCONF) ; if [ -f $$ZCONFIG ] ; then	\
	 cmp -s $(ZCONF) $(DESTDIR)$$ZCONFIG ||		\
	   echo "**" && echo "** Please consider copying $(ZCONF) to $$ZCONFIG !" && echo "**";\
	else						\
		cp $(ZCONF) $(DESTDIR)$$ZCONFIG; chmod 644 $(DESTDIR)$$ZCONFIG; \
	fi
	cd proto ;	$(MAKE) $(MFLAGS) cf

install-bin:	# all
	@if [ -n "${prefix}" -a -z "${DESTDIR}" ] ; then echo "INSTEAD OF  prefix=  PLEASE INSTALL WITH:  DESTDIR=.. parameter"; exit 1; fi
	. $(ZCONF) ; zdir=`echo $$ZCONFIG|sed -e 's!\(.*\)/\([^/]*\)!\1/!'`; $(MKDIR) $(DESTDIR)$$zdir
	@. $(ZCONF) ; if [ -f $$ZCONFIG ] ; then	\
	 cmp -s $(ZCONF) $(DESTDIR)$$ZCONFIG ||		\
	   echo "**" && echo "** Please consider copying $(ZCONF) to $$ZCONFIG !" && echo "**";\
	else						\
		cp $(ZCONF) $(DESTDIR)$$ZCONFIG; chmod 644 $(DESTDIR)$$ZCONFIG; \
	fi
	@. $(ZCONF) ; cp $(srcdir)/ChangeLog $(DESTDIR)$$MAILSHARE/ChangeLog ; chmod 644 $(DESTDIR)$$MAILSHARE/ChangeLog
	@. $(ZCONF) ; cp ./config.status $(DESTDIR)$$MAILSHARE/config.status ; chmod 644 $(DESTDIR)$$MAILSHARE/config.status
	cd proto ;      $(MAKE) $(MFLAGS) install-bin  PZCONFIG="../$(ZCONF)"
	cd compat ;     $(MAKE) $(MFLAGS) install
	cd router ;     $(MAKE) $(MFLAGS) install
	cd scheduler ;  $(MAKE) $(MFLAGS) install
	cd smtpserver ; $(MAKE) $(MFLAGS) install
	cd transports ; $(MAKE) $(MFLAGS) install
	cd libc ;       $(MAKE) $(MFLAGS) install
	cd utils ;      $(MAKE) $(MFLAGS) install
	@. $(ZCONF) ; if [ -f $$ZCONFIG ] ; then	\
	 cmp -s $(ZCONF) $(DESTDIR)$$ZCONFIG ||		\
	   echo "**" && echo "** Please consider copying $(ZCONF) to $$ZCONFIG !" && echo "**";\
	else						\
		cp $(ZCONF) $(DESTDIR)$$ZCONFIG; chmod 644 $(DESTDIR)$$ZCONFIG; \
	fi
	$(MAKE) $(MFLAGS) post-install-note

dirs:
	@cd proto ; $(MAKE) $(MFLAGS) dirs PZCONFIG="../$(ZCONF)"

install:
	@if [ -n "${prefix}" -a -z "${DESTDIR}" ] ; then echo "INSTEAD OF  prefix=  PLEASE INSTALL WITH:  DESTDIR=.. parameter"; exit 1; fi
	$(MAKE) $(MFLAGS) dirs # all
	@. $(ZCONF) ; zdir=`echo $$ZCONFIG|sed -e 's!\(.*\)/\([^/]*\)!\1/!'`; $(MKDIR) $(DESTDIR)$$zdir
	@. $(ZCONF) ; cp $(ZCONF) $(DESTDIR)$$ZCONFIG ; chmod 644 $(DESTDIR)$$ZCONFIG
	@. $(ZCONF) ; cp $(srcdir)/ChangeLog $(DESTDIR)$$MAILSHARE/ChangeLog ; chmod 644 $(DESTDIR)$$MAILSHARE/ChangeLog
	@. $(ZCONF) ; cp ./config.status $(DESTDIR)$$MAILSHARE/config.status ; chmod 644 $(DESTDIR)$$MAILSHARE/config.status
	@cd proto ;      $(MAKE) $(MFLAGS) install  PZCONFIG="../$(ZCONF)"
	@cd compat ;     $(MAKE) $(MFLAGS) install
	@cd router ;     $(MAKE) $(MFLAGS) install
	@cd scheduler ;  $(MAKE) $(MFLAGS) install
	@cd smtpserver ; $(MAKE) $(MFLAGS) install
	@cd transports ; $(MAKE) $(MFLAGS) install
	@cd libc  ;      $(MAKE) $(MFLAGS) install
	@cd utils ;      $(MAKE) $(MFLAGS) install
	$(MAKE) $(MFLAGS) post-install-note

post-install-note:
	if test "$(DESTDIR)" = "" ; then $(MAKE) $(MFLAGS) post-install-text ; fi
	if test "$(DESTDIR)" != "" ; then $(MAKE) $(MFLAGS) post-install-text-dd ; fi

post-install-text:
	@echo ">>>> "
	@echo ">>>> Please do run $(MAILBIN)/post-install"
	@echo ">>>> "
post-install-text-dd:
	@echo ">>>> "
	@echo ">>>> Please do run $(MAILBIN)/post-install --destdir $(DESTDIR)"
	@echo ">>>> "

router/router:
	cd router ; $(MAKE) $(MFLAGS) router-a

scheduler/scheduler:
	cd scheduler ; $(MAKE) $(MFLAGS) all

scheduler-old/scheduler-old:
	cd scheduler-old ; $(MAKE) $(MFLAGS) all

scheduler/mailq:
	cd scheduler ; $(MAKE) $(MFLAGS) all

smtpserver/smtpserver:
	cd smtpserver ; $(MAKE) $(MFLAGS) smtpserver-a

compat/rmail/rmail:
	cd compat ; $(MAKE) $(MFLAGS) rmail/rmail-always

compat/sendmail/sendmail:
	cd compat ; $(MAKE) $(MFLAGS) sendmail/sendmail-always

utils/vacation/vacation:
	cd utils/vacation ; $(MAKE) $(MFLAGS) vacation

utils/makedb/makedb:
	cd utils/makedb ; $(MAKE) $(MFLAGS)

lib/libz.a: lib/*.c
	cd lib ; $(MAKE) $(MFLAGS)

libc/libzc.a: libc/*.c
	cd libc ; $(MAKE) $(MFLAGS)

libauth/libauth.a: libauth/authuser.c libauth/authuser.h
	cd libauth; $(MAKE) $(MFLAGS)

libresolv/libresolv.a: libresolv/*.c
	cd libresolv; $(MAKE) $(MFLAGS)

transports/libta/libta.a: transports/libta/*.c
	cd transports/libta ; $(MAKE) $(MFLAGS)

transports/-ok:
	cd transports ; $(MAKE) $(MFLAGS)

mostlyclean: mostlyclean-recursive mostlyclean-local

clean: clean-recursive clean-local

distclean: distclean-recursive distclean-local
	: rm config.status

realclean: realclean-recursive realclean-local
	: rm config.status

TAGS clean-recursive distclean-recursive realclean-recursive mostlyclean-recursive:
	for subdir in $(SUBDIRS) $(MOREDIRS) $(MOREDIRS2); do \
	  target=`echo $@|sed 's/-recursive//'`; \
	  echo making $$target in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MFLAGS) $$target) || exit 1; \
	done
	rm -f $(CLEANFILES)

mostlyclean-local:

clean-local: mostlyclean-local
	-tt=`find . "(" -name "*~" -o -name "*.log" -o -name "*.orig" ")" -print` && \
		rm -f clean.state $$tt

clean-version:
	-rm -f `find . -name version.c -print | egrep -v libmalloc` dummy.name
	-rm -f `find . -name revision -print ` dummy.name

distclean-local: clean-local clean-version
	rm -f config.cache config.h config.log stamp-h distname
	rm -rf autom4te.cache
	rm -f $(DISTCLEANFILES)

realclean-local: distclean-local

neat:
	-rm -f $(ZCONF) $(CONF).sed eddep makedep Makefile.bak *.tar

scrub:	distclean
	-rm -f make.log make.out make.err* errs

scrub-obsolete-tail:
	# No null entry at all, let it be generated into proper form
	# when real processing goes thru..
	# @echo 'typedef enum { nilHeaderSemantics = -1 } HeaderSemantics;' > include/rfc822.entry

dist:
	@echo 'Did you run "make scrub" first?' ; sleep 2
	chmod -R a+rX .
	find . -type l -o -type d -o -type f -print | \
	  egrep -v -e '/(private[/$$]|config.cache|config.status|CVS[/$$]|RCS[/$$]|ID$$|.*\.o$$|fc[/$$]|.*\.a$$|stamp)' | \
	  CWD=`pwd` sed -e '/\.tar.*/d' -e "s/^\./`sh -c 'basename \`pwd\`'`/" | \
	  sort -t/ > MANIFEST
	cp MANIFEST /tmp
	(cd .. ; tar cvf - `cat /tmp/MANIFEST` ) > `basename \`pwd\``.tar
	rm -f /tmp/MANIFEST #MANIFEST

distprivate:
	@echo 'Did you run "make scrub" first?' ; sleep 2
	chmod -R a+rX .
	find . -type l -o -type d -o -type f -print | \
	  egrep -v -e '/(config.cache|config.status|CVS[/$$]|RCS[/$$]|ID$$|.*\.o$$|fc[/$$]|.*\.a$$|stamp)' | \
	  CWD=`pwd` sed -e '/\.tar.*/d' -e "s/^\./`sh -c 'basename \`pwd\`'`/" | \
	  sort -t/ > MANIFEST
	cp MANIFEST /tmp
	(cd .. ; tar cvf - `cat /tmp/MANIFEST` ) > `basename \`pwd\``.tar
	rm -f /tmp/MANIFEST #MANIFEST

dist-usa:
	@echo 'Did you run "make scrub" first?' ; sleep 2
	chmod -R a+rX .
	./bin/usa-itar-stripper.sh
	find . -type d -o -type f -print | \
	  egrep -v -e '/(private[/$$]|config.cache|crypto|config.status|CVS[/$$]|RCS[/$$]|ID$$|.*\.o$$|fc[/$$]|.*\.a$$|stamp)' | \
	  CWD=`pwd` sed -e '/\.tar.*/d' -e "s/^\./`sh -c 'basename \`pwd\`'`/" | \
	  sort -t/ > MANIFEST
	cp MANIFEST /tmp
	(cd .. ; tar cvf - `cat /tmp/MANIFEST` ) > `basename \`pwd\``-usa.tar
	./bin/usa-itar-stripper.sh reverse
	mv crypto.diff crypto-`basename \`pwd\``.diff
	rm -f /tmp/MANIFEST #MANIFEST


# For the justification of the following Makefile rules, see node
# `Automatic Remaking' in GNU Autoconf documentation.

SiteConfig Makefile: config.status Makefile.in
	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status

config.h: stamp-h
stamp-h: config.status $(srcdir)/config.h.in
	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status

config.status: configure
	./config.status --recheck
#
# The GNU autoconf guide says: have following condition, however
# not all systems have "autoconf", and thus people pulling this
# package from CVS are getting serious problems -- or have to
# "touch configure" after the CVS pull.
#
#configure: configure.in
#	cd $(srcdir) && autoconf


#
# Doing all parts of multistage autoconf process:
#
autoconf:
	aclocal -I m4/
	autoconf
	autoheader

config.h.in: stamp-h.in
stamp-h.in: configure.in
# 	cd $(srcdir) && autoheader
# # Use echo instead of date to avoid spurious conflicts for
# # people who use CVS, since stamp-h.in is distributed.
# 	echo > $(srcdir)/$@

$(ZCONF):	SiteConfig
	(echo '# Do not edit this file, instead edit '`pwd`'/SiteConfig.in file'; \
	cat SiteConfig | \
	sed -n	-e '/^\([a-zA-Z][^ 	]*\)[ 	]*=[ 	]*\(.*\)[ 	]*$$/!d' \
		-e 's/^\([^ 	]*\)[ 	]*=[ 	]*\(.*\)[ 	]*$$/\1="\2"/' \
		-e 's/^\([^=]*\)=""\(.*\)""$$/\1="\2"/'	\
		-e 's/^\([^=]*\)="\([^ 	]*\)"$$/\1=\2/'			\
		-e p	) > $@
# The sed-patterns above do:
#  - match sh-variable set expression, discard all else
#  - pick the variable name, and the parameter string and form up
#    an expression:   VAR="DATA"
#  - if the newly made expression has double quotes (because the input
#    was quoted), remove the extra quotes
#  - if a value is quoted, and it does not have white-space in it, strip
#    the quotes away
#  - and as always with sed, "p" in the end to output the result

#OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
# $(ZCONF):	SiteConfig
# 	(echo '# Do not edit this file, instead edit '`pwd`'/SiteConfig.in file'; \
# 	cat SiteConfig | \
# 	sed -n  -e '/^[^ 	]*=[ 	]*[^#].*/!d' \
# 		-e 's:^\([^ 	]*\)=[ 	]*\([^#].*\):\1=\2:' \
# 		-e 's:=\([^# 	]*[ 	][^#]*\)\(.*\):="\1"\2:' \
# 		-e 's:\([ 	][ 	]*\)":"\1:' \
# 		-e 's:"\([^ 	]*\)":\1:' -e 's:""::' -e p   ) > $@

force:

version.c: force # Makefile
	@sh -c ': $${USER=$${LOGNAME-root}} ; \
	REVISION=`cat revision 2>/dev/null || (echo 0 | tee revision)` ; \
	HOSTNAME=`(/bin/hostname || /bin/uname) 2>/dev/null` ; \
	case "$$REVISION" in \
	[0-9]|[0-9][0-9]|[0-9][0-9][0-9]) \
		REVISION=`expr $$REVISION + 1` ;; \
	*)	REVISION=0 ;; \
	esac ; \
	echo $$REVISION > revision ; \
	exec > version.c ; \
	echo "const char *Version = \"${VERSION} #$${REVISION}: `date`\";"; \
	echo "const char *VersionNumb = \"${VERSION} #$${REVISION}\";"; \
	echo "const char *Bugreport = \"${BUGREPORT}\";"; \
	echo "const char *CC_user = \"$${USER}@$${HOSTNAME}\";"; \
	echo "const char *CC_pwd = \"`pwd`\";" '

depend:
	for x in $(SUBDIRS) $(MOREDIRS); do		\
	    if [ -f $$x/Makefile ]; then		\
		( cd $$x; ${MAKE} ${MFLAGS} depend CPPDEP="${CPPDEP}" ); \
	    fi ;					\
	done


# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

# DO NOT DELETE THIS LINE -- It is used by 'make depend' to update this file


syntax highlighted by Code2HTML, v. 0.9.1