
#
# Targets which don't generate files should be listed as dependencies
# of the special target .PHONY
#

.PHONY:	install install_dvi install_ps install_html
.PHONY:	clean

#
# This should be the first rule.  It will create a document without
# installing it.
#

default:: install

# Note that LaTeX should be run three times to resolve references
$(TARGET_DVI): $(TEX) $(SUBTEX)
	echo $(srcdir)
	TEXINPUTS=$(TEXINPUTS);  export TEXINPUTS; \
        $(LATEX) $<; $(LATEX) $<; $(LATEX) $<

$(TARGET_PS): $(DVI)
	$(DVIPS) -o $@ $<

$(TARGET_HTML): $(TEX) $(SUBTEX)
	TEXINPUTS=$(TEXINPUTS); export TEXINPUTS; \
$(LATEX2HTML) -tmp /tmp -dir $(currdir)/html -external_file $(currdir)/$(<F:%.tex=%) -mkdir -local_icons $< 

#
# do installations
#


install:: install_dvi install_ps install_html

ifdef TARGET_DVI
install_dvi:: $(TARGET_DVI)
	$(MKDIRS) $(dvidir)
	$(INSTALL_DATA) $(TARGET_DVI) $(dvidir)
endif

ifdef TARGET_PS
install_ps:: $(TARGET_PS)
	$(MKDIRS) $(psdir)
	$(INSTALL_DATA) $(TARGET_PS) $(psdir)
endif

ifdef TARGET_HTML
install_html:: $(TARGET_HTML)
	$(?F:%.html=$(MKDIRS) $(htmldir)/%;)
	$(?F:%.html= CDIR=%; $(INSTALL_DATA) $(currdir)/html/* $(htmldir)/$$CDIR;)
endif

#
# clean up
#

realclean:: dviclean psclean htmlclean
	-rm -f *.aux *.log *.toc *.bbl
	-rm -rf html

clean:: dviclean psclean htmlclean

dviclean:
	-rm -f *.dvi

psclean:
	-rm -f *.ps

htmlclean:
	-rm -rf $(TARGET_HTML:%.html=%)

#
# keep the configuration information and makefiles up-to-date
#

top_srcdir = @top_srcdir@
mysrcdir = @srcdir@
# this is checked from the documentation subdirs, so we need two-levels up
top_objdir = ../..

$(top_srcdir)/configure: $(top_srcdir)/configure.in $(top_srcdir)/aclocal.m4
	cd $(top_srcdir) && autoconf

$(top_objdir)/config.status: $(top_srcdir)/configure
	cd $(top_objdir) && ./config.status --recheck

Makefile: $(mysrcdir)/Makefile.in $(top_objdir)/config.status
	cd $(top_objdir) && CONFIG_FILES=doc/Makefile ./config.status

../MakeVars: $(top_srcdir)/doc/MakeVars.in $(top_objdir)/config.status
	cd $(top_objdir) && CONFIG_FILES=doc/MakeVars ./config.status

../MakeRules: $(top_srcdir)/doc/MakeRules.in $(top_objdir)/config.status
	cd $(top_objdir) && CONFIG_FILES=doc/MakeRules ./config.status
