## Include this file into Makefile.am that is used to generate documentation
##
## # $XORP: xorp/docs/mk/Makefile.doc.am,v 1.3 2005/01/19 19:23:19 pavlin Exp $
##


all: docs
docs: $(DOCS) $(TARGETS)

TARGETS=$(DOCS:%=%.ps) $(DOCS:%=%.pdf)

$(DOCS): %: %.dvi 

DOCS_LATEX=$(DOCS:%=%_LATEX)
DOCS_FIGURES=$(DOCS:%=%_FIGURES)
DOCS_BBL=$(DOCS:%=%_BBL)

PSANON=sed -f $(top_srcdir)/utils/fig2dev-ps-anon.sed

#
# The files to remove with ``gmake clean''
# TODO: don't remove *.foo; instead consider DOCS_LATEX to select the files
#  to remove.
#
CLEANFILES = *.aux *.bbl *.blg *.dvi *.lof *.log *.lot *.toc $(TARGETS)

#
# The path to any additional TeX input files
#
TEXINPUTS_PATH = $(top_srcdir)/docs/tex:

#
# If any of the *.bib *.tex or figures files is newer,
#  then run latex twice on the master *.tex file.
# If there is *.lof *.lot or *.toc file, then run latex three times instead.
# Note that we don't check whether the *.lof *.lot *.toc files are newer
#  than the *.dvi file because in practice the timestamps of those files
#  are same as the timestamp of the *.dvi file, and therefore the *.dvi file
#  is always regenerated.
#
$(DOCS:%=%.dvi): %.dvi: %_FIGURES %_BBL %_LATEX
	@is_newer=NO; \
	latex_files0="$($(subst -,_,$*)_LATEX)"; \
	latex_files=""; \
	for i in $$latex_files0 ; do \
		latex_files="$$latex_files $(srcdir)/$$i"; \
	done; \
	bbl_files="$*.bbl"; \
	figures_files0="$($(subst -,_,$*)_FIGURES)"; \
	figures_files=""; \
	for i in $$figures_files0 ; do \
		figures_files="$$figures_files $(srcdir)/$$i"; \
	done; \
	dep_files="$$latex_files $$bbl_files $$figures_files"; \
	for i in $$dep_files ; do \
		if [ $$i = $*.bbl -a ! -f $$i ] ; then continue; fi; \
		if [ ! -f $$i ] ; then \
			echo ERROR: cannot build $@: missing dependency file $$i; \
			exit 1; \
		fi; \
		if [ ! $$i -ot $@ ] ; then \
			is_newer="YES"; \
		fi; \
	done; \
	if [ $$is_newer = "YES" ] ; then \
		for i in $$dep_files ; do \
			file_prefix=`echo $$i | sed 's/\.tex$$//'`; \
			if [ -z $$file_prefix ] ; then continue; fi; \
			if [ $$file_prefix = $$i ] ; then continue; fi; \
			if [ $$file_prefix != $(srcdir)/$* ] ; then continue; fi; \
			(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $$i); \
			(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $$i); \
			if [ -f $*.lof -o -f $*.lot -o -f $*.toc ] ; then \
				(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $$i); \
			fi; \
		done; \
	fi;

#
# If any of the *.bib or *.tex files is newer than the *.bbl file,
#  then run latex and bibtex on the master *.tex file.
# Note that we need to run bibtex on the filename with stripped .tex suffix.
#
$(DOCS_BBL): %_BBL: %_LATEX
	@bbl_filename=$*.bbl; \
	is_newer=NO; \
	has_bib=NO; \
	latex_files0="$($(subst -,_,$<))"; \
	latex_files=""; \
	for i in $$latex_files0 ; do \
		latex_files="$$latex_files $(srcdir)/$$i"; \
	done; \
	dep_files="$$latex_files"; \
	for i in $$dep_files ; do \
		if [ ! $$i -ot $$bbl_filename ] ; then \
			is_newer="YES"; \
		fi; \
		file_prefix=`echo $$i | sed 's/\.bib$$//'`; \
		if [ -z $$file_prefix ] ; then continue; fi; \
		if [ $$file_prefix != $$i ] ; then \
			has_bib=YES; \
		fi; \
	done; \
	if [ $$is_newer = "YES" -a $$has_bib = "YES" ] ; then \
		for i in $$dep_files ; do \
			file_prefix=`echo $$i | sed 's/\.tex$$//'`; \
			if [ -z $$file_prefix ] ; then continue; fi; \
			if [ $$file_prefix = $$i ] ; then continue; fi; \
			if [ $$file_prefix != $(srcdir)/$* ] ; then continue; fi; \
			(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $$i); \
			bibtex $*; \
		done; \
	fi;

#
# If any of the *.fig files is newer than the corresponding *.ps or *.eps,
# then run fig2dev to (re)create that file.
#
$(DOCS_FIGURES):
	@figures_files0="$($(subst -,_,$@))"; \
	figures_files=""; \
	for i in $$figures_files0 ; do \
		figures_files="$$figures_files $(srcdir)/$$i"; \
	done; \
	dep_files="$$figures_files"; \
	for i in $$dep_files ; do \
		file_prefix=`echo $$i | sed 's/\.eps$$//'`; \
		if [ -z $$file_prefix ] ; then continue; fi; \
		if [ $$file_prefix = $$i ] ; then continue; fi; \
		fig_src=$$file_prefix.fig; \
		if [ -f $$fig_src ] ; then \
			if [ ! $$fig_src -ot $$i ] ; then \
				fig2dev -Leps $$fig_src | $(PSANON) > $$i; \
			fi; \
		fi; \
	done; \
	for i in $$dep_files ; do \
		file_prefix=`echo $$i | sed 's/\.ps$$//'`; \
		if [ -z $$file_prefix ] ; then continue; fi; \
		if [ $$file_prefix = $$i ] ; then continue; fi; \
		fig_src=$$file_prefix.fig; \
		if [ -f $$fig_src ] ; then \
			if [ ! $$fig_src -ot $$i ] ; then \
				fig2dev -z Letter -Lps $$fig_src | $(PSANON) >$$i; \
			fi; \
		fi; \
	done

$(DOCS_LATEX):
	@true

#
# The rules to generate files based on their suffixes
#
SUFFIXES = .tex .bbl .dvi .ps .pdf .fig .ps .eps
.tex.dvi:
	(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $< $@)
	(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $< $@)
.tex.bbl:
	(TEXINPUTS="${TEXINPUTS_PATH}"; export TEXINPUTS; latex $< $@)
	bibtex $*
.dvi.ps:
	dvips $< -o $@
.ps.pdf:
	ps2pdf $< $@
.fig.ps:
	fig2dev -z Letter -Lps $< | $(PSANON) > $@
.fig.eps:
	fig2dev -Leps $< | $(PSANON) > $@



syntax highlighted by Code2HTML, v. 0.9.1