# Makefile for the Comp 150 text book
#
# ihewson@cs.otago.ac.nz 2008

DOC:=book
FIGURES:=$(shell echo figures/*.fig)
TEX_FILES:=$(shell echo *.tex)
PDF_FIGS:=$(FIGURES:.fig=-fig.pdf)

# Create the textbook
$(DOC).pdf : $(DOC).tex $(TEX_FILES) $(PDF_FIGS) $(DOC).ind
	pdflatex -halt-on-error $< && pdflatex -halt-on-error $<
	# pdflatex $< && pdflatex $<

# Create and view book
.PHONY : view
view : $(DOC).pdf
	acroread $< &

$(DOC).ind : $(DOC).idx
	makeindex $(DOC)

$(DOC).idx : 
	pdflatex -halt-on-error $(DOC).tex

# Generate a pdf from each fig and don't delete files when finished
.PRECIOUS : %-fig.pdf
%-fig.pdf : %.fig
	fig2dev -L pdf < $< > $@

# Remove all generated files
.PHONY : clean
clean :
	rm -f *.aux *~ *.log *.toc *.pdf figures/*-fig.pdf
