MKDIR=mkdir
COPY=cp
CHDIR=cd
RM=rm -f
INSTALLDIRVAR=TEXMFMAIN
SHELL=sh
all: hyperref test

hyperref: unpack documentation

unpack:
	latex hyperref.ins

hyperref.drv: unpack

documentation: hyperref.drv
	latex hyperref.dtx
	makeindex -s gind hyperref
	latex hyperref.dtx
	makeindex -s gind hyperref
	latex hyperref.dtx

test: test.nodir
test.nodir:
	$(CHDIR) test; latex test0
	$(CHDIR) test; makeindex test0
	$(CHDIR) test; latex test0

install: unpack
	( \
	TEXMF=`kpsewhich -expand-var '$$$(INSTALLDIRVAR)'`; \
	echo installing to $${TEXMF}/tex/latex/hyperref; \
	$(MKDIR) $${TEXMF}/tex/latex/hyperref; \
	$(COPY) *.sty *.def htex4ht.cfg $${TEXMF}/tex/latex/hyperref \
	)

clean:
	-$(RM) *.aux *.toc *.idx *.drv *.dvi *.log *.rep *.lof *.brf *.tmp *.ist *.ilg *.ind *.out *.css *.html
	-$(CHDIR) test; $(RM) *.dvi *.aux *.log *.toc *.lot *.lof *.idx *.ilg *.ind *.out *.brf
	-$(RM) nameref.sty backref.sty hyperref.sty hycheck.tex nohyperref.sty
	-$(RM) *.def htex4ht.cfg *.otc *.idv *.lg *.xref test.ps test.pdf
	-$(RM) hyperref.pdf

checks:
	cd test; for what in test*tex ;\
	do \
	 pdflatex $$what; pdflatex $$what; latex $$what; latex $$what ;\
	done
