# Makefile for the PDCMAC package
# Template for configure

package		= @package@

#  directory source code is in:
srcdir		= @srcdir@

#  directory for TeX macro files:
texmf		= @texmf@
texdir		= @texdir@
docdir		= @docdir@

#  End of configuration section
########################################################################

TEX		= tex </dev/null
DVIPS		= dvips 
FIG2EPSF	= $(srcdir)/fig2epsf
ETAGS		= $(srcdir)/dtxtags
INSTALL		= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@
MKDIR		= $(srcdir)/pmkdir $(MKDIRFLAGS)
MKDIRFLAGS	= --mode=755

code_files	= pdccode.tex pdccode2.tex

#  The macro files are divided according to whether they have their own
#  DTX file, or come from pdcmisc.dtx or pdcsty.dtx
self_files	= pdcfmt2.dtx pdcfsel.dtx magrmac.dtx pdcoput5.dtx \
		pdcadobe.dtx pdcl1maa.dtx maamac.dtx
misc_files	= pdcmigr.tex pdcimth.tex pdchyex.tex pdccmsub.tex
sty_files	= ma55lft.tex ma55doc.tex pdccmlft.tex pdccmdoc.tex\
		pdcpsdoc.tex pdcpslft.tex pdcdoc.def pdclft.def
macro_files	= $(self_files:.dtx=.tex) $(misc_files) $(sty_files)

misc_dtx	= pdcmisc.dtx
sty_dtx		= pdcsty.dtx
dtxfiles	= $(self_files) $(sty_dtx) $(misc_dtx) pdccode.dtx
dvifiles	= $(dtxfiles:.dtx=.dvi) pdcguide.dvi

figures		= oput01.eps oput02.eps
documents	= pdcguide.tex magrman.tex copying.tex pdcmacvn.tex
config_files	= makefile.in configure
miscscript	= fig2epsf pmkdir pinstall dtxtags
miscdoc		= 00readme.txt install.txt copying.txt version.txt

distfiles	= $(miscdoc) pdcguide.dvi pdcmondo.tex \
		$(code_files) $(dtxfiles) $(documents) $(config_files) \
		$(figures) $(figures:.eps=.fig) \
		$(miscscript) $(miscscript:=.1)

########################################################################
#	Standard targets

all: 		pdcguide.dvi $(macro_files)

#  Note.  This target assumes either I can use GNU "install", or
#  an "install" compatible with it, or the "pinstall" shellscript supplied.
install:	all pdccode.dvi
	test -d $(texdir) || $(MKDIR) $(texdir)
	$(INSTALL_DATA) $(macro_files) $(texdir)
	-test -d $(docdir) || $(MKDIR) $(docdir)
	-$(INSTALL_DATA) $(dvifiles) $(figures) $(miscdoc) $(docdir)
	-test -r news.txt && $(INSTALL_DATA) news.txt $(docdir)

uninstall:
	cd $(texdir); rm -f $(macro_files) 
	cd $(docdir) && rm -f $(dvifiles) $(figures) $(miscdoc)

mostlyclean:
	rm -f *.log *.ilg *.toc *.bak
clean:		mostlyclean
	rm -f   *.dvi *.aux *.idx $(macro_files) .misc.flag .sty.flag
distclean:	clean
	rm -f makefile config.status TAGS
realclean:	distclean
	rm -f *.ind $(figures) version.txt

dist:		$(distfiles)
	sed -n '/pdcmacv/s/.*[^0-9.]\([0-9.]*\)[^0-9.].*$$/$(package)-\1/p' \
		pdcmacvn.tex > .fn
	rm -rf `cat .fn`
	mkdir `cat .fn`
	cp -p $(distfiles) `cat .fn`
	-cp -p ChangeLog `cat .fn`/changes.txt
	-cp -p news.txt `cat .fn`/news.txt
	cd `cat .fn`; ls -Rl > contents.txt
	tar -cf `cat .fn`.tar `cat .fn` && gzip -v9f `cat .fn`.tar
	cd `cat .fn`; zip -9qrl ../`cat ../.fn`.zip *
	rm -rf `cat .fn` .fn

version.txt: $(dtxfiles) $(miscscript) pdcmacvn.tex
	sed -e 's/\\def\\pdcmacversion{\([0-9]*\.[0-9]*\)}/* $(package) release \1 */' \
	  -e 's/\\def\\pdcmacversion{\([0-9]*\.[0-9]*\)\.\([0-9]*\)}/* $(package) release \1, patch level \2 */' \
	pdcmacvn.tex > version.txt
	date '+Version ID list generated %Y-%m-%d' >> version.txt
	echo >> version.txt
	( grep -h 'rcs\$$Id' $(dtxfiles) | \
	sed -e 's/^.*: \(.*\) \$$.*$$/\1/' -e 's/,v/ =/' | sort; echo; \
	grep version= $(miscscript) configure | \
	sed -e 's/:version=/ = /' -e 's/"//g' | sort ) | \
	align_equals >> version.txt

tagfiles	= $(dtxfiles)
TAGS:		$(tagfiles) $(srcdir)/dtxtags
	$(ETAGS) $(ETAGSFLAGS) $(tagfiles)

########################################################################
#	Individual targets

$(self_files) $(miscfiles): pdccode.tex
$(sty_files): 	pdccode2.tex

pdcguide.dvi magrman.dvi: $(macro_files)
pdcguide.dvi:	 copying.tex pdcmacvn.tex

pdcoput5.dvi pdcoput5.tex: $(figures)

$(misc_files): .misc.flag
.misc.flag:	$(misc_dtx)
	$(TEX) $(misc_dtx) && touch .misc.flag

$(sty_files): 	.sty.flag
.sty.flag:	$(sty_dtx)
	$(TEX) $(sty_dtx) && touch .sty.flag

pdccode.dvi pdccode.tex:   pdccode.dtx
	$(TEX) pdccode.dtx
	grep endinput tmp.tex && mv tmp.tex pdccode.tex

pdcguide.ps: pdcguide.tex copying.tex $(macro_files)
	echo '\let\usepsfonts! \input pdcguide' > tmp.tex
	$(TEX) tmp
	rm -f tmp.tex
	$(DVIPS) $(DVIPSFLAGS) -o $@ tmp

#  A scratch file for doing tests:
tryit.dvi:	tryit.tex ma55lft.tex pdcl1maa.tex
	$(TEX) tryit


# rules for the configuration itself
makefile: makefile.in config.status
	sh config.status makefile
config.status: $(srcdir)/configure
	sh config.status --recheck --nocreate

########################################################################
#	Implicit rules

.SUFFIXES:	.dtx .tex .dvi .ps .eps .fig
.dtx.tex:
	$(TEX) $<
.tex.dvi:
	$(TEX) $<
.dvi.ps:
	$(DVIPS) $(DVIPSFLAGS) $< -o $@
.fig.eps:
	$(FIG2EPSF) $< > $@
