
#
# Generic makefile for latex
#
# Author: Stefano Zacchiroli <zack@bononia.it>
#
# Created:       Sun, 29 Jun 2003 12:00:55 +0200 zack
# Last-Modified: Mon, 10 Oct 2005 15:37:12 +0200 zack
#

########################################################################

# list of .tex _main_ files
TEXS = main.tex

# number of runs of latex (for table of contents, list of figures, ...)
RUNS = 1

# do you need bibtex?
BIBTEX = no

# would you like to use pdflatex?
PDF_VIA_PDFLATEX = yes

# which formats generated by default ("all" target)?
# (others will be generated by "world" target)
# see AVAILABLE_FORMATS below 
BUILD_FORMATS = dvi

# which format to be shown on "make show"
SHOW_FORMAT = dvi

########################################################################

AVAILABLE_FORMATS = dvi ps ps.gz pdf html

ADVI = advi
BIBTEX = bibtex
BROWSER = galeon
DVIPDF = dvipdf
DVIPS = dvips
GV = gv
GZIP = gzip
HEVEA = hevea
ISPELL = ispell
LATEX = latex
PDFLATEX = pdflatex
PRINT = lpr
XDVI = xdvi
XPDF = xpdf

ALL_FORMATS = $(BUILD_FORMATS)
WORLD_FORMATS = $(AVAILABLE_FORMATS)

all: $(ALL_FORMATS)
world: $(WORLD_FORMATS)

DVIS = $(TEXS:.tex=.dvi)
PSS = $(TEXS:.tex=.ps)
PSGZS = $(TEXS:.tex=.ps.gz)
PDFS = $(TEXS:.tex=.pdf)
HTMLS = $(TEXS:.tex=.html)

dvi: $(DVIS)
ps: $(PSS)
ps.gz: $(PSGZS)
pdf: $(PDFS)
html: $(HTMLS)

show: show$(SHOW_FORMAT)
showdvi: $(DVIS)
	$(XDVI) $<
showps: $(PSS)
	$(GV) $<
showpdf: $(PDFS)
	$(XPDF) $<
showpsgz: $(PSGZS)
	$(GV) $<
showps.gz: showpsgz
showhtml: $(HTMLS)
	$(BROWSER) $<

print: $(PSS)
	$(PRINT) $^

clean:
	rm -f \
		$(TEXS:.tex=.dvi) $(TEXS:.tex=.ps) $(TEXS:.tex=.ps.gz) \
		$(TEXS:.tex=.pdf) $(TEXS:.tex=.aux) $(TEXS:.tex=.log) \
		$(TEXS:.tex=.html) $(TEXS:.tex=.out) $(TEXS:.tex=.haux) \
		$(TEXS:.tex=.htoc) $(TEXS:.tex=.tmp)

%.dvi: %.tex
	$(LATEX) $<
	if [ "$(BIBTEX)" = "yes" ]; then $(BIBTEX) $*; fi
	if [ "$(RUNS)" -gt 1 ]; then \
		for i in seq 1 `expr $(RUNS) - 1`; do \
			$(LATEX) $<; \
		done; \
	fi
ifeq ($(PDF_VIA_PDFLATEX),yes)
%.pdf: %.tex
	$(PDFLATEX) $<
	if [ "$(BIBTEX)" = "yes" ]; then $(BIBTEX) $*; fi
	if [ "$(RUNS)" -gt 1 ]; then \
		for i in seq 1 `expr $(RUNS) - 1`; do \
			$(PDFLATEX) $<; \
		done; \
	fi
else
%.pdf: %.dvi
	$(DVIPDF) $< $@
endif
%.ps: %.dvi
	$(DVIPS) $<
%.ps.gz: %.ps
	$(GZIP) -c $< > $@
%.html: %.tex
	$(HEVEA) -fix $<

.PHONY: all ps pdf html clean

########################################################################

