SUPPLIER = public
BIBTEX = TEXMF=$(TEXMF) bibtex
LATEX = TEXMF=$(TEXMF) latex
PDFLATEX = TEXMF=$(TEXMF) pdflatex
TEX = TEXMF=$(TEXMF) tex
DVIPS = TEXMF=$(TEXMF) dvips
MKINDEX = mkindex
FORMAT		= latex
prefix		= /t/src/i
TEXMFMAIN	= /t/src/tetex-texmf
TEXMF		= {/t/src/tetex-texmf-runtime,$(TEXMFMAIN)}
FMTDIR		= $(TEXMFMAIN)/web2c
TEXDIR		= $(TEXMFMAIN)/tex/$(FORMAT)/$(PACKAGE)
MFDIR		= $(TEXMFMAIN)/fonts/source/$(SUPPLIER)/$(PACKAGE)
TEXMISC		= $(TEXMFMAIN)/tex/$(FORMAT)/misc
MFMISC		= $(TEXMFMAIN)/fonts/source/$(SUPPLIER)/misc
DOCDIR		= $(TEXMFMAIN)/doc/$(FORMAT)/$(PACKAGE)
BSTDIR		= $(TEXMFMAIN)/bibtex/bst/$(PACKAGE)
BSTMISC		= $(TEXMFMAIN)/bibtex/bst/misc
ISTDIR		= $(TEXMFMAIN)/makeindex
ISTMISC		= $(TEXMFMAIN)/makeindex
DOCMISC		= $(TEXMFMAIN)/doc/$(FORMAT)/styles
DIRS		= $(TEXDIR) $(DOCDIR) $(FMTDIR)
BIN		= $(prefix)/bin
MAN		= $(prefix)/man/man1
SRCDIR		= $(C)/macros/latex/contrib/$(PACKAGE)

DIRPERMS	= 755
INPUTS		= $(TMPINPUTS) $(EXTRAINPUTS)
MFINPUTS	= $(TMPMFINPUTS) $(EXTRAMFINPUTS)
DOC		= $(TMPDOC) $(EXTRADOC)
TMPFILES	= $(TMPINPUTS) $(TMPDOC) $(JUNK) $(TMPMFINPUTS)
JUNKDIRS	=
default: unpack

%.dvi:	%.tex
	$(LATEX) $<
	$(MKINDEX) $*
	$(LATEX) $<
	$(LATEX) $<

%.dvi:	%.drv
	$(LATEX) $<
	$(MKINDEX) $*
	$(LATEX) $<
	$(LATEX) $<

%.dvi:	%.dtx
	$(LATEX) $<
	$(MKINDEX) $*
	$(LATEX) $<
	$(LATEX) $<

%.ps:	%.dvi
	$(DVIPS) $< -o

$(INPUTS):
	$(LATEX) tetex.ins

clean:
	rm -rf $(JUNKDIRS)
	rm -f $(TMPFILES)
	rm -f *.log *.aux *.dvi *.idx *.lof *.lot
	rm -f *.toc *.ilg *.ind *.glo *.gls

install: unpack doc formats
	@../install-files $(TEXDIR) $(TEXMISC) $(INPUTS)
	@../install-files $(DOCDIR) $(DOCMISC) $(DOC)
	@../install-files $(FMTDIR) $(FMTDIR)  $(FORMATS)
	@../install-files $(BSTDIR) $(BSTMISC) $(BSTFILES)
	@../install-files $(ISTDIR) $(ISTMISC) $(ISTFILES)
	@../install-files $(MFDIR) $(MFMISC) $(MFINPUTS)

rehash:
	texhash

update:
	cp -auvf $(SRCDIR)/* .
	find . -name .listing -print0 | xargs --no-run-if-empty -0 rm -f
	find . -perm 664 -o -perm 775 -print0 | xargs --no-run-if-empty -0 chmod g-w

unpack: $(INPUTS)
doc:	unpack $(DOC)
formats:	$(FORMATS)

.PHONY: unpack install doc rehash formats

world: clean unpack doc install clean
