# $Id: Makefile,v 1.16 2006-01-16 01:11:40 eugene Exp $

PDFLATEX = env TEXINPUTS=.:../inputs: pdflatex
PSLATEX  = env TEXINPUTS=.:../inputs: latex
BIBTEX   = env BIBINPUTS=.:../inputs BSTINPUTS=.:../inputs bibtex

PS2PDF_OPTS = "-dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode"

ifeq ($(DO_PDFLATEX),1)
     MY_LATEX  = $(PDFLATEX)
else
     MY_LATEX  = $(PSLATEX)
endif

%.pdf: %.tex
	$(MY_LATEX) $*.tex 
	if [ $(DO_BIBTEX) -eq 1 ]; then $(BIBTEX) $*; fi
	$(MY_LATEX) $*.tex 
	if [ $(DO_BIBTEX) -eq 1  ]; then $(MY_LATEX) $*.tex; fi
#	thumbpdf --modes=dvips $*.pdf
#	$(MY_LATEX) $*.tex 
	if [ $(DO_PDFLATEX) -eq 0 ]; then dvips -z -t letter -o $*.ps $*.dvi; fi
	if [ $(DO_PDFLATEX) -eq 0 ]; then ps2pdf $(PS2PDF_OPTS) $*.ps $*.pdf; fi
#	@rm -f $*.ps $*.dvi $*.aux $*.log $*.tbr $*.tbd $*.toc $*.tpm $*.lof body.tmp head.tmp

%.tgz:
	tar --transform 's%inputs/%%' -zcf $@ $(FILES) $*.bbl
clean :
	$(RM) *.bib *.log *.dvi *.aux *.toc *.tbd *.tbr *.tpm *.lof *.out *~ core body.tmp head.tmp

dist : clean
	$(RM) *.pdf *.ps

empty: clean

foo:
	@echo all: $^
	@echo 1st: $<
	@echo file: $@
	@echo word: $*
