# TARGETS
# make           -- build PostScript version of paper
# make pdf       -- build PostScript and PDF version of paper
# make view      -- build PS version + show it using gv
# make print     -- build PS version and send to default printer
# make clean     -- remove all but PS and PDF files
# make veryclean -- removes all generated files
# make tar       -- removes all generated files and creates a tar ball

# Known Bugs
# If $(TARGET).fig changes, bbl file is rebuild unnecessarily


TARGET=atlas-minbias-mpi08

TEX=$(wildcard *.tex)
BIB=$(TARGET).bib
BBL=$(TARGET).bbl
DVI=$(TARGET).dvi
AUX=$(patsubst %.tex,%.aux,$(wildcard *.tex))
BLG=$(TARGET).blg
BACKUP=*~

GV=gv
LPR=lpr

PS=$(TARGET).ps
PDF=$(TARGET).pdf
TAR=$(TARGET)-$(shell date -I).tar.gz

paper: $(PS) 

pdf: $(PDF)

view: paper
	$(GV) $(PS)

print: paper
	$(LPR) $(PS)

tar: veryclean
	@echo "**"
	@echo "**"
	@echo "** Building TAR file"
	@echo "**"
	@echo "**"
	cd ../ && tar cfz $(TAR) $(TARGET)

$(DVI): $(AUX) $(BBL)
	@echo "**"
	@echo "**"
	@echo "** Building DVI file"
	@echo "**"
	@echo "**"
	latex $(TARGET)
	latex $(TARGET)
# This is a cheat to stop rebuilding the BBL just because we run LaTeX
	touch $(BBL)

$(BBL): $(AUX) $(BIB)
	@echo "**"
	@echo "**"
	@echo "** Building BBL file"
	@echo "**"
	@echo "**"
	bibtex $(TARGET)

%.aux: %.tex
	@echo "**"
	@echo "**"
	@echo "** TEX file -> AUX file"
	@echo "**"
	@echo "**"
	latex $(TARGET).tex

clean:
	@rm -f $(DVI) *.aux $(BBL) $(TARGET).log $(TARGET).toc $(BLG) $(BACKUP)

veryclean: clean
	@rm -f $(PS) $(PDF)

%.ps: %.dvi
	@echo "**"
	@echo "**"
	@echo "** DVI file -> PS file"
	@echo "**"
	@echo "**"
	dvips -ta4 -Ppdf $< -o

%.pdf: %.ps
	@echo "**" 
	@echo "**"
	@echo "** PS file -> PDF file"
	@echo "**"   
	@echo "**"
	ps2pdf $<

%.eps: %.fig
	@echo "**"
	@echo "**"
	@echo "** Building figure $@"
	@echo "**"
	@echo "**"
	fig2dev -L eps $< > $@
