# Makefile for LaTeX documents

# $Id: texMakefile,v 1.1 2005/11/06 19:03:11 aoliva Exp $

# Copyright 1997,1998 Alexandre Oliva <oliva@dcc.unicamp.br>

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# How to use: name this file texMakefile, then create a Makefile like this:

# DOCSET = sample
# AUTHOR_EMAIL = oliva@dcc.unicamp.br
# include texMakefile

# It will build %.dvi, %.ps, %.ps.gz files and a %-html directory.

ifndef DVILIST
DVILIST = $(DOCSET:%=%.dvi)
endif
ifndef PSLIST
PSLIST = $(DVILIST:%.dvi=%.ps)
endif
ifndef PSGZLIST
PSGZLIST = $(PSLIST:%.ps=%.ps.gz)
endif
ifndef HTMLLIST
HTMLLIST = $(DOCSET:%=%-html)
endif
ifndef PDFLIST
PDFLIST = $(PSLIST:%.ps=%.pdf)
endif
ifndef LATEX2HTML
LATEX2HTML = latex2html
endif
ifndef PS2PDF
PS2PDF = ps2pdf
endif
ifndef DVIPS
DVIPS = dvips -Ppdf
endif

.PHONY: all clean distclean dvi ps ps.gz html $(DOCSET)

all: dvi ps ps.gz html

clean:
	rm -f $(EXTRACLEAN) \
	      $(DVILIST:%.dvi=%.aux) $(DVILIST:%.dvi=.%-stmp) \
	      $(DVILIST:%.dvi=%.log) $(DVILIST:%.dvi=%.blg)

distclean: clean
	rm -f $(DVILIST) $(PSLIST) $(PSGZLIST) $(EXTRADISTCLEAN)
	rm -rf $(HTMLLIST) $(EXTRADISTCLEANDIR)

dvi: $(DVILIST)
ps: $(PSLIST)
ps.gz: $(PSGZLIST)
html: $(HTMLLIST)
pdf: $(PDFLIST)

$(DOCSET): % : %.dvi %.ps %.ps.gz %-html

%.dvi: %.tex
%.dvi: %.tex .%-stmp
	latex $*
	if test -f .$*-stmp && cmp .$*-stmp $*.aux; then :; else \
	cp $*.aux .$*-stmp && rm -f $@ && $(MAKE) $@; fi

.PRECIOUS: .%-stmp
.%-stmp: %.tex
	if test -f $*.aux; then cp $*.aux $@; else touch $@; fi

%.ps: %.dvi
	$(DVIPS) -o $@ $*

%.ps.gz: %.ps
	gzip -c $*.ps >$@

%-html: %.tex
	if test ! -z "$(AUTHOR_EMAIL)"; then addr="$(AUTHOR_EMAIL)"; fi; \
	rm -rf $@ && mkdir $@ && \
	$(LATEX2HTML) $(LATEX2HTML_FLAGS) -local_icons -dir $*-html $${addr+-address} $${addr+'<A HREF="mailto:$(AUTHOR_EMAIL)">contact the authors</A>'} $*.tex

ifdef PDFLATEX
%.pdf: %.dvi
	$(PDFLATEX) $*.tex
else
%.pdf: %.ps
	$(PS2PDF) $*.ps
endif
