.SUFFIXES:	.dvi	.tex	.tfm	.pdr	.pfd	.evl	.ps	.aux	.anyway

# File extensions:
# LaTeX: .tex, .aux, .dvi, .log
# Fonts: .tfm, .pdr
# Encoding vector listings:		evl
# Force processing:	.anyway
#
# These programs are only needed for the long and complete version
# of the paper.
PFD2TFM =  ../pfd2tfm/src/pfd2tfm -p ../pfd2tfm/evs
PRINTPDR = ../printpdr/printpdr   -P.
DVITPS =   ../dvitps/src/$(DVITPS_BINARY_NAME)
DVITPS_OPT = -Fv -P../dvitps/pro -B../dvitps/capab

SRC =  prel.tex intro.tex posi.tex psfonts.tex\
	examples.tex examples2.tex examples3.tex\
	../psfig/psfig-doc.tex special.tex install.tex usage.tex\
	extensions.tex appendix.tex biblio.tex local.tex

# Same deal: all .dvi files.
DVI =	prel.dvi intro.dvi posi.dvi psfonts.dvi\
	examples.dvi examples2.dvi examples3.dvi\
	../psfig/psfig-doc.dvi special.dvi install.dvi usage.dvi\
	extensions.dvi appendix.dvi biblio.dvi local.dvi

# Same deal: all .ps files.
PS =	prel.ps intro.ps   posi.ps psfonts.ps\
	examples.ps  examples2.ps  examples3.ps\
	../psfig/psfig-doc.ps  special.ps  install.ps  usage.ps\
	extensions.ps appendix.ps  biblio.ps   local.ps

# Same deal: all .aux files.
AUX =	prel.aux intro.aux   posi.aux psfonts.aux\
	examples.aux  examples2.aux  examples3.aux\
	../psfig/psfig-doc.aux  special.aux  install.aux  usage.aux\
	extensions.aux appendix.aux  biblio.aux   local.aux

# Make all dvi and PostScript files. Starts from scratch: document
# is processed twice.
all:
	cd ../dvitps; make
	cd ../printpdr; make
	cd ../pfd2tfm/src; make
	make codoc

# Update dvi files.
all-dvi:	$(DVI)

# Update all auxiliary files.
all-aux:
	for file in $(AUX); do\
		make $$file;\
	done

# Update PostScript files.
all-ps:	$(DVI)
	make $(PS)

# Process the document twice, generate PS files.
codoc:
	$(RM) *.dvi
	make all-dvi
	$(RM) *.dvi
	make all-dvi
	$(RM) prel.dvi
	make all-ps

# Print the complete document.
print:	$(PS)
	for file in $(PS) ; do\
		lpr -P$(PS_PRINTER) $$file;\
	done

# Install some TeX macros.
install:
	-mkdir $(TEX_MACROS_DIR)
	cd ../psfig; make install

# Generate esself.dvi, esself.ps, which only contains the ``sales part'' of the
# document, i.e.~what is this software all about. "es.tex" is imported into "intro.tex,"
# and "esself.tex" is "es.tex" as an independent document which can be processed
# by LaTeX directly.
esself.tex:	es.tex
	$(RM) $@
	echo '\documentstyle{article}'			>> $@
	echo '\setlength{\textwidth}{6.5in}'		>> $@
	echo '\hoffset = -0.75in'			>> $@
	echo '\begin{document}'				>> $@
	cat es.tex					>> $@
	echo '\end{document}'				>> $@
clean::
	$(RM) esself.tex esself.dvi esself.aux esself.ps esself.log
esself.dvi:	esself.tex
	-$(LATEX) esself
	-$(LATEX) esself
esself.ps:	esself.dvi
	$(DVITPS) esself.dvi > $@

intro.dvi:	intro.tex CopyrightLong.tex CopyrightSources.tex es.tex\
	listofmac.tex CopyRightBook.tex
CopyrightLong.tex:	../CopyrightLong
		$(CP)   ../CopyrightLong $@
CopyrightSources.tex:	../CopyrightSources
		$(CP)   ../CopyrightSources $@
shortnote.dvi:	shortnote.tex
	$(LATEX) shortnote
	$(LATEX) shortnote
shortnote.tex:	Makefile shortnote-1.tex es.tex shortnote-2.tex
	cat shortnote-1.tex es.tex shortnote-2.tex > $@

posi.dvi:	posi.tex testtables.tex rules.psr
rules.psr:	../dvitps/psr/rules.psr
	$(CP) ../dvitps/psr/rules.psr $@

psfonts.dvi:	DefClasses.xxx EncDef-0.ev EncDef-1.ev EncDef-2.ev\
		EncDiff.tex

EncDef-0.ev:	../pfd2tfm/evs/$@
	sort ../pfd2tfm/evs/$@ > $@

EncDef-1.ev:	../pfd2tfm/evs/$@
	sort ../pfd2tfm/evs/$@ > $@

EncDef-2.ev:	../pfd2tfm/evs/$@
	sort ../pfd2tfm/evs/$@ > $@

EncDiff.tex:	EncDef-0.ev EncDef-1.ev
	-diff EncDef-0.ev EncDef-1.ev > $@

DefClasses.xxx:	../pfd2tfm/evs/DefClasses
	$(CP) ../pfd2tfm/evs/DefClasses  $@

# The examples have to be processed with the -z option of the driver in effect
# resetting the PostScript interpreter every PS_RESET_PAGES number of pages.
# See "../local-defs" for details.
examples.ps:	examples.dvi
	$(DVITPS) $(DVITPS_OPT) -z $(PS_RESET_PAGES) -O $@ examples.dvi

examples2.ps:	examples2.dvi
	$(RM) $@
	$(DVITPS) $(DVITPS_OPT) -z $(PS_RESET_PAGES) -O $@ examples2.dvi

examples3.ps:	examples3.dvi
	$(RM) $@
	$(DVITPS) $(DVITPS_OPT) -z $(PS_RESET_PAGES) -O $@ examples3.dvi

examples.dvi:\
	ex-mac.tex\
	PS-Helvetica.pfd 	PS-Helvetica.tfm	PS-Helvetica.evl\
	PS-Courier.pfd	 	PS-Courier.tfm		PS-Courier.evl\
	PS-Times-Roman.tfm	PS-Times-Roman.evl	PS-Times-Roman.pfd\
	PS-Times-Italic.tfm\
	PS-AvantGarde-Book.pfd	PS-AvantGarde-Book.tfm	PS-AvantGarde-Book.evl\
	PS-Bookman-Demi.pfd	PS-Bookman-Demi.tfm	PS-Bookman-Demi.evl\
	PS-NewCenturySchlbk-Roman.pfd	PS-NewCenturySchlbk-Roman.tfm\
			PS-NewCenturySchlbk-Roman.evl\
	PS-Palatino-Bold.pfd	PS-Palatino-Bold.tfm	PS-Palatino-Bold.evl\
	PS-ZapfChancery-MediumItalic.pfd	PS-ZapfChancery-MediumItalic.tfm\
			PS-ZapfChancery-MediumItalic.evl\
	PS-ZapfDingbats.pfd	PS-ZapfDingbats.tfm	PS-ZapfDingbats.evl\
	prcontrol.tex

# This way we import the information of whether the user has a
# PostScript printer with the standard fonts Helvetica, TimesRoman, Courier
# and Symbol, or a printer (like the Laser Writer Plus or Laser Writer II)
# with some additional fonts on top of the ones just mentioned.
prcontrol.tex:
	$(RM) $@
	echo '\def\PrinterClass{$(PS_PRINTER_CLASS)}'	>> $@

examples2.dvi:\
	PS-Courier.tfm\
	ex-mac.tex\
	PS-Helvetica.pfd 	PS-Helvetica.tfm    PS-Helvetica.evl\
	PS-Courier.pfd	 	PS-Courier.tfm	    PS-Courier.evl\
	PS-Helvetica-2.pfd	PS-Helvetica-2.tfm PS-Helvetica-2.evl\
	PS-ExecPs.pfd		PS-ExecPs.tfm\
	PS-Helvetica-2-mac.tex\
	PS-Times-Roman.tfm PS-Times-Roman.evl PS-Times-Roman.pfd\
	PS-Times-Italic.tfm\
	PS-Symbol.pfd		PS-Symbol.tfm	    PS-Symbol.evl

#if (COND_SLITEX_CONTROL == 0)
slitex-control.tex:	Makefile
	echo '\def\SliTeXControl{0}' > $@
examples3.dvi:\
	PS-Courier.tfm	ex-mac.tex\
	PS-Helvetica.pfd 	PS-Helvetica.tfm    PS-Helvetica.evl\
	PS-IHelvetica.pfd	PS-IHelvetica.tfm  PS-IHelvetica.pdr\
	PS-E1-cmr10.tfm PS-E1-cmr10.pfd\
	PS-E2-cmr10.tfm PS-E2-cmr10.pfd\
	PS-E3-cmr10.tfm PS-E3-cmr10.pfd\
	tpic-example.tex tpic-control.tex font-tab.tex slitex-control.tex
#else
slitex-control.tex:	Makefile
	echo '\def\SliTeXControl{1}' > $@
examples3.dvi:\
	PS-Courier.tfm	ex-mac.tex\
	PS-Helvetica.pfd 	PS-Helvetica.tfm    PS-Helvetica.evl\
	PS-IHelvetica.pfd	PS-IHelvetica.tfm  PS-IHelvetica.pdr\
	PS-E1-cmr10.tfm PS-E1-cmr10.pfd\
	PS-E2-cmr10.tfm PS-E2-cmr10.pfd\
	PS-E3-cmr10.tfm PS-E3-cmr10.pfd\
	tpic-example.tex tpic-control.tex font-tab.tex slitex-control.tex\
	SliTeX/root.tex SliTeX/slidefile.tex\
	SliTeX/root-1.ps SliTeX/root-2.ps SliTeX/root-3.ps SliTeX/root-4.ps\
	SliTeX/root-ps.tex SliTeX/slidefile-ps.tex\
	SliTeX/root-ps-1.ps SliTeX/root-ps-2.ps SliTeX/root-ps-3.ps SliTeX/root-ps-4.ps

SliTeX/root-1.ps:	SliTeX/Makefile
	cd SliTeX; make root-1.ps
SliTeX/root-2.ps:	SliTeX/Makefile
	cd SliTeX; make root-2.ps
SliTeX/root-3.ps:	SliTeX/Makefile
	cd SliTeX; make root-3.ps
SliTeX/root-4.ps:	SliTeX/Makefile
	cd SliTeX; make root-4.ps
SliTeX/root-ps-1.ps:	SliTeX/Makefile
	cd SliTeX; make root-ps-1.ps
SliTeX/root-ps-2.ps:	SliTeX/Makefile
	cd SliTeX; make root-ps-2.ps
SliTeX/root-ps-3.ps:	SliTeX/Makefile
	cd SliTeX; make root-ps-3.ps
SliTeX/root-ps-4.ps:	SliTeX/Makefile
	cd SliTeX; make root-ps-4.ps
#endif

# In case tpic is not available "tpic-example.tex" contains
# a sentence to this effect because the "tpic" command fails.
#if (COND_TPIC == 1)
tpic-example.tex:	tpic-example.pic Makefile
	$(RM) $@
	tpic tpic-example.pic
tpic-control.tex:	Makefile
	echo '\def\TpicControl{$(TPIC)}' > $@
#else
tpic-example.tex:	Makefile
	echo 'tpic not available, no tpic example included here.' > $@
tpic-control.tex:	Makefile
	echo '\def\TpicControl{$(TPIC)}' > $@
#endif

../psfig/psfig-doc.dvi:	../psfig/psfig.tex ../psfig/xwindows.tex
../psfig/xwindows.tex:
	cd ../psfig; make xwindows.tex

PS-Times-Italic.tfm:
	$(PFD2TFM) Times-Italic.afm

usage.dvi:	usage.tex ../man/docman.tex
../man/docman.tex:	../man/Makefile
	cd ../man; make docman.tex

install.dvi:	local-defs.tex makefile.top makefile.setup\
	../setup/setup-ld.awk ../setup/setup-1.awk ../setup/setup-2.awk ../setup/closing.defs\
	../setup/local-defs.xx
local-defs.tex:	../setup/local-defs
	$(CP) ../setup/local-defs $@
makefile.top:	../makefile
	$(CP) ../makefile $@
makefile.setup:	../setup/makefile
	$(CP) ../setup/makefile $@

# If you want to clean up this directory but leave the auxiliary files around,
# then use this goal.
clean-all-but-aux:
	$(RM) *.tfm *.pdr *.tab *.evl includes.tex\
		PS-Helvetica-2-mac.tex includeonly.latex tpic-example.tex\
		EncDef-?.ev DefClasses.xxx EncDiff.tex\
		$(PS1) $(PS2) $(PS_L) prcontrol.tex CopyrightLong.tex\
		CopyrightSources.tex rules.psr tpic-control.tex slitex-control.tex\
		makefile.top makefile.setup\
		shortnote.tex main.tex
	$(RM) *.log *.dvi *~ $(PS)
	cd SliTeX; make clean
clean::
	make clean-all-but-aux

# The sed script adds an \\appendix instruction!
includes.tex:	Makefile
	$(RM) includes.tex
	for file in $(SRC) ; do\
	    echo "    \\include{$$file}" |\
		sed -e 's/\.tex//' -e 's/.extensions./& \\appendix/' >>\
			includes.tex;\
	done

main.tex:	MAIN.tex Makefile
	$(RM) $@
	echo '%% DO NOT CHANGE THIS FILE, change MAIN.tex instead." >> $@
	echo '\documentstyle{book}'		>> $@
	cat MAIN.tex				>> $@

texspell.out:	$(SRC)
	$(RM) $@
	texspell $(SRC)

install:
lint:
depend:
relink:

# General rules
.tex.dvi:
	$(RM) main.dvi $*.dvi $*.log $*.ps
	make includes.tex
	make main.tex
	echo "\includeonly{$*}" > includeonly.latex
	@echo "*********** NOW MAKING $*.dvi *********"
	-$(LATEX) main.tex
	-mv main.dvi $*.dvi
	-mv main.log $*.log
	$(RM) main.ver

.tex.aux:
	make  $*.dvi
	$(RM) $*.dvi

.dvi.ps:
	$(RM) $*.ps
	$(DVITPS) $(DVITPS_OPT) -O $*.ps $*.dvi

.pfd.tfm:
	$(PFD2TFM) $*.pfd

.pfd.evl:
	$(RM) $*.evl
	$(PRINTPDR) -i -w 4 $*.pdr		>> $*.evl
