#
# Build the PPR documenation.
#

# The release of PPR that this is the documention for:
RELEASE=1.30

# The directory this Makefile is in:
DIR=ppr-doc-$(RELEASE)

# The root of the man tree to install the PPR man pages in:
MANDIR=/usr/local/man

POD2MAN=pod2man
POD2HTML=pod2html
SGML2LATEX=sgml2latex
DVIPS=dvips
LATEX2E=latex
FIG2DEV=fig2dev

.SUFFIXES: .pod .html .man .ps .dvi .tex .sgml .fig

all: html man ps

# List of man pages in HTML format
html: ppr.1.html ppr2samba.8.html indexttf.8.html ppop.1.html ppad.8.html \
	pprd.8.html papsrv.8.html papsrv.conf.5.html xppr.1.html ppuser.8.html \
	lprsrv.8.html fontsub.conf.5.html mfmodes.conf.5.html \
	lw_errors.conf.5.html samba_submitter.8.html

# List of man pages in nroff format
man: ppr.1.man ppr2samba.8.man indexttf.8.man ppop.1.man ppad.8.man \
	pprd.8.man papsrv.8.man papsrv.conf.5.man xppr.1.man ppuser.8.man \
	lprsrv.8.man fontsub.conf.5.man mfmodes.conf.5.man \
	lw_errors.conf.5.man samba_submitter.8.man

# List of papers in PostScript format
ps: pprdoc.ps pprinst.ps

# This document requires a slew of figures
pprdoc.dvi: pprdoc.tex pprdoc_enter.ps pprdoc_printing1.ps pprdoc_printing2.ps

# This document has an include file
pprinst.tex: pprinst.sgml notices.sgml

# Rule to create an HTML file from a Perl POD file
.pod.html:
	$(POD2HTML) $*.pod

# Rule to convert POD to nroff format
.pod.man:
	$(POD2MAN) --center="PPR Documentation" --release=$(RELEASE) $*.pod >$*.man

# Convert SGML to Latex2e
.sgml.tex:
	$(SGML2LATEX) -2e $*.sgml

# Convert LateX to DVI, making multiple passes
# until all of the cross-references are stable
.tex.dvi:
	$(LATEX2E) $*; \
	while grep 'LaTeX Warning: Label(s) may have changed' $*.log >/dev/null; \
	do $(LATEX2E) $*; done

# Convert a DVI file to PostScript
.dvi.ps:
	$(DVIPS) -f $* >$*.ps

# Convert a FIG file to Encapsulated PostScript
.fig.ps:
	$(FIG2DEV) -L ps $*.fig >$*.ps

# Build everything and then create a tar archive 
# with all the files we want to distribute
dist: all
	(cd ..; tar zcvf $(DIR).tar.gz $(DIR)/Makefile $(DIR)/*.pod \
		$(DIR)/*.txt $(DIR)/*.sgml $(DIR)/*.fig \
		$(DIR)/*.man $(DIR)/*.html $(DIR)/pprinst.ps \
		$(DIR)/pprdoc.ps )

# Install the man pages in Nroff format
install-man:
	for i in *.1.man; do \
		NAME=`echo $$i | sed -e 's/\.man$$//'`; cp $$i $(MANDIR)/man1/$$NAME; done
	for i in *.5.man; do \
		NAME=`echo $$i | sed -e 's/\.man$$//'`; cp $$i $(MANDIR)/man5/$$NAME; done
	for i in *.8.man; do \
		NAME=`echo $$i | sed -e 's/\.man$$//'`; cp $$i $(MANDIR)/man8/$$NAME; done

# Remove everything which is automatically generated 
# and all editor backup files
clean:
	rm -f *.[1-8].html *~ *.bak *.bck *.man  *.dvi *.aux *.log *.ps *.tex

