# ALaTeX makefile for Unix
#
# WARNING:  some things in this makefile may be specific to the web2c TeX
#           distribution, specifically the setting of TEXINPUTS.
#
# If you use A4 paper, setting ARTICLEOPTS to 
#    a4paper
# may save about 30 pages.  The variable is an argument list that is
# passed to the article class.
ARTICLEOPTS = 

# Where should metaclass.cfg go?
CFGDIR = /usr/local/lib/texmf/tex/latex/config

# Where should the ALaTeX format go?
FMTDIR = /usr/local/lib/texmf/ini

# Where should the DVI documentation for ALaTeX go?
DOCDIR = /usr/local/lib/texmf/doc/alatex

# Where should the ALaTeX executable (link) go?
BINDIR = /usr/local/bin

# Where are the LaTeX base distribution files?
BASEDIR = /usr/local/src/texmf/macros/latex-95-12/base

# What options should be passed to install for installing
# everything except the executable?
INSTALLOPTS = -c -m 644

# END OF USER-CONFIGURABLE OPTIONS, except for experts of course.

home        = alatex
version     = 1.0
versionfile = VERSION-$(version)
archname    = alatex-$(version)

files = $(versionfile) COPYING \
	Makefile aunpack.ins aunpcked.txt amanifst.txt \
	0areadme.txt README abugs.txt ainstall.txt \
	alatex.dtx alatex.tex

doc-files = alatex.dvi

.PHONY: all install
.PHONY: alatex doc install-alatex install-doc
.PHONY: clean help default
.PHONY: distribution

default help:
	@echo ; \
	echo "Look over the variables at the top of the Makefile and adjust them if"; \
	echo "you want.  You probably want to try these targets in this order:"; \
	echo ""; \
	echo "  all              makes alatex.fmt and metaclas.cfg"; \
	echo "  install          installs them and creates a link from alatex to virtex"; \
	echo "  check            runs alatex ltxcheck.tex"; \
	echo "  clean            removes auxiliary and rebuildable files"; \
	echo ""; \
	echo "Other targets you might want to use are:"; \
	echo ""; \
	echo "  doc              makes the ALaTeX documentation"; \
	echo "  install-doc      installs it"; \
	echo

all: alatex

alatex: alatex.fmt metaclas.cfg

doc: alatex.dvi

$(versionfile):
	touch $@

README:
	ln -s 0areadme.txt $@

alatex.ltx metaclas.cfg: alatex.dtx aunpack.ins \
			 README $(versionfile)
	TEXINPUTS=.:$(BASEDIR):; export TEXINPUTS; \
	tex aunpack.ins

alatex.fmt: alatex.ltx
	initex \&latex alatex.ltx

alatex.dvi: %.dvi: %.tex %.dtx
	echo "\PassOptionsToClass{$(ARTICLEOPTS)}{article}" > ltxdoc.cfg
	latex $*.tex
	INDEXSTYLE=.:$(BASEDIR); export INDEXSTYLE; \
	makeindex -s gind.ist $*.idx
	latex $*.tex
	latex $*.tex

install: install-alatex

install-alatex: alatex
	mkdir -p $(BINDIR) $(FMTDIR) $(CFGDIR)
	rm -f $(BINDIR)/alatex
	ln -f -s `type virtex | cut -d' ' -f 3` $(BINDIR)/alatex
	install $(INSTALLOPTS) alatex.fmt $(FMTDIR)
	install $(INSTALLOPTS) metaclas.cfg $(CFGDIR)

install-doc: doc
	mkdir -p $(DOCDIR)
	install $(INSTALLOPTS) $(doc-files) $(DOCDIR)

check: install
	TEXINPUTS=.:$(BASEDIR):; export TEXINPUTS; \
	$(BINDIR)/alatex ltxcheck.tex

distribution: $(files)
	rm -f $(archname).tar.gz
	cd ..; \
	ln -s $(home) $(archname); \
	tar czf $(archname).tar.gz \
		$(addprefix $(archname)/, $(files)); \
	rm $(archname); \
	mv $(archname).tar.gz $(home)

clean:
	rm -f   aunpack.log \
		metaclas.cfg \
		alatex.{log,ltx,ind,idx,ilg,log,aux,toc} \
		ltxcheck.{log,aux} \
		ltxdoc.cfg

realclean veryclean: clean
	rm -f   $(doc-files) \
	        alatex.fmt \
	        README $(versionfile) \
	        $(archname).tar.gz