#
# Assumption here is GNU-make!
#

srcdir = @srcdir@
# VPATH = @srcdir@ ## NO VPATH HERE!
@SET_MAKE@

#prefix=	@prefix@
#DESTDIR=
MANDIR=		${DESTDIR}@mandir@
TOPDIR=		..
S=		$(srcdir)
INSTALL=	@INSTALL@
PERL=		@PERL@
Z=zm

# SGML/JADE catalog
OJCAT     = /usr/share/sgml/openjade-1.3/catalog
DB2HTML   = jw -c ${OJCAT} -b html -f docbook -o .
DB2MAN    = jw -c ${OJCAT} -b man -f docbook -o .
HTMLFIXUP = ${srcdir}/../doc/manual/html-post-fixup.sh

MAN2HTML  = sh $(srcdir)/man-to-html.sh
MAN2PS    = groff -t -man
PS2PDF	  = ps2pdf

GENMANS= zmailer.conf.5  mailq-m.5 ZMailer-mailq.3pm


MAN1=	mailq.1 mailrm.1 newaliases.1 rmail.1 ssl.1 vacation.1 zmailer.1 zmsh.1 mboxpath.1
MAN3=	zmailer.3 authuser.3
MAN5=	aliases.5 zdbases.conf.5 mailq-m.5 zmailer.conf.5
MAN8=	errormail.8 hold.8 router.8 scheduler.8 sendmail.8 sm.8 smtp.8 smtpserver.8 manual-expirer.8 expirer.8 mprobe.8 mailbox.8 makedb.8 newdb.8 reroute.8 manual-rerouter.8
MANe=	ZMailer-mailq.3pm  mailq-m.5

FRC:
	@echo "make install MANDIR=/your/choice"
	@echo "   default for MANDIR=${MANDIR}"
	@echo "make groff  (or: ps)"
	@echo "make pdf"
	@echo "make html"
	@echo "make clean"


# Set of GNU Make implicite pattern rules


%.1zm.html   : %.1   ; $(MAN2HTML) $< > $@
%.3zm.html   : %.3   ; $(MAN2HTML) $< > $@
%.3pmzm.html : %.3pm ; $(MAN2HTML) $< > $@
%.5zm.html   : %.5   ; $(MAN2HTML) $< > $@
%.8zm.html   : %.8   ; $(MAN2HTML) $< > $@

%.1zm.ps     : %.1   ; $(MAN2PS) $< > $@
%.3zm.ps     : %.3   ; $(MAN2PS) $< > $@
%.3pmzm.ps   : %.3pm ; $(MAN2PS) $< > $@
%.5zm.ps     : %.5   ; $(MAN2PS) $< > $@
%.8zm.ps     : %.8   ; $(MAN2PS) $< > $@

%.pdf : %.ps ; $(PS2PDF) $<


clean:
	rm -rf *~ *.3pm *.ps *.html *.pdf
	rm -f $(GENMANS)

distclean:
	rm -rf *~ *.?

mostlyclean depend:

groff: ps

ps:	$(patsubst %, %zm.ps,   $(MAN1) $(MAN3) $(MAN5) $(MAN8) $(MANe))
pdf:	$(patsubst %, %zm.pdf,  $(MAN1) $(MAN3) $(MAN5) $(MAN8) $(MANe))
html:	$(patsubst %, %zm.html, $(MAN1) $(MAN3) $(MAN5) $(MAN8) $(MANe))
	-rm -f index.html
	# Rename that perl file...
	-mv  ZMailer-mailq.3pmzm.html   ZMailer::mailq.3pm.html
	-mv  ZMailer-mailq.3pmzm.pdf    ZMailer::mailq.3pm.pdf
	sh $(srcdir)/man-index.sh

# Publish  is for Matti's use to publish these files at  zmailer.org
publish:
	# Make the files in correct order
	make ps pdf html
	# publish in  http://zmailer.org/man/
	cp -p *.html *.pdf /home/httpd/zmailer/html/man/

install: $(GENMANS)
	if [ ! -d ${MANDIR}/man1 ] ; then mkdir -p ${MANDIR}/man1 ; fi
	if [ ! -d ${MANDIR}/man3 ] ; then mkdir -p ${MANDIR}/man3 ; fi
	if [ ! -d ${MANDIR}/man5 ] ; then mkdir -p ${MANDIR}/man5 ; fi
	if [ ! -d ${MANDIR}/man8 ] ; then mkdir -p ${MANDIR}/man8 ; fi
	$(INSTALL) -m 644 aliases.5	${MANDIR}/man5/aliases.5$Z
	$(INSTALL) -m 644 errormail.8	${MANDIR}/man8/errormail.8$Z
	$(INSTALL) -m 644 expirer.8	${MANDIR}/man8/expirer.8$Z
	$(INSTALL) -m 644 hold.8	${MANDIR}/man8/hold.8$Z
	$(INSTALL) -m 644 mailbox.8	${MANDIR}/man8/mailbox.8$Z
	$(INSTALL) -m 644 mailq.1	${MANDIR}/man1/mailq.1$Z
	$(INSTALL) -m 644 mailq-m.5	${MANDIR}/man5/mailq-m.5$Z
	$(INSTALL) -m 644 mailrm.1	${MANDIR}/man1/mailrm.1$Z
	$(INSTALL) -m 644 manual-expirer.8  ${MANDIR}/man8/manual-expirer.8$Z
	$(INSTALL) -m 644 manual-rerouter.8 ${MANDIR}/man8/manual-rerouter.8$Z
	$(INSTALL) -m 644 mboxpath.1	${MANDIR}/man1/mboxpath.1$Z
	$(INSTALL) -m 644 mprobe.8	${MANDIR}/man8/mprobe.8$Z
	$(INSTALL) -m 644 newaliases.1	${MANDIR}/man1/newaliases.1$Z
	$(INSTALL) -m 644 reroute.8	${MANDIR}/man8/reroute.8$Z
	$(INSTALL) -m 644 rmail.1	${MANDIR}/man1/rmail.1$Z
	$(INSTALL) -m 644 router.8	${MANDIR}/man8/router.8$Z
	$(INSTALL) -m 644 scheduler.8	${MANDIR}/man8/scheduler.8$Z
	$(INSTALL) -m 644 sendmail.8	${MANDIR}/man8/sendmail.8$Z
	$(INSTALL) -m 644 sm.8		${MANDIR}/man8/sm.8$Z
	$(INSTALL) -m 644 smtp.8	${MANDIR}/man8/smtp.8$Z
	$(INSTALL) -m 644 smtpserver.8	${MANDIR}/man8/smtpserver.8$Z
	$(INSTALL) -m 644 vacation.1	${MANDIR}/man1/vacation.1$Z
	$(INSTALL) -m 644 zdbases.conf.5 ${MANDIR}/man5/zdbases.conf.5$Z
	$(INSTALL) -m 644 zmailer.conf.5 ${MANDIR}/man5/zmailer.conf.5$Z
	$(INSTALL) -m 644 zmailer.1	${MANDIR}/man1/zmailer.1$Z
	$(INSTALL) -m 644 zmailer.3	${MANDIR}/man3/zmailer.3$Z
	$(INSTALL) -m 644 zmsh.1	${MANDIR}/man1/zmsh.1$Z
	# $(INSTALL) -m 644 ssl.1 ${MANDIR}/man1



ZMailer-mailq.3pm: $(srcdir)/../utils/perl/mailq/mailq.pm
	pod2man $(srcdir)/../utils/perl/mailq/mailq.pm > ZMailer-mailq.3pm

mailq-m.5: $(srcdir)/mailq-m-generate.pl $(srcdir)/$(TOPDIR)/scheduler/mailq.inc
	$(PERL) $(srcdir)/mailq-m-generate.pl $(srcdir)/$(TOPDIR)/scheduler/mailq.inc > mailq-m.5

zmailer.conf.5: $(srcdir)/zmailer-conf-generate.pl ../SiteConfig
	$(PERL)  $(srcdir)/zmailer-conf-generate.pl ../SiteConfig > zmailer.conf.5


syntax highlighted by Code2HTML, v. 0.9.1