# GNU Makefile for LaTeX.
# (c) 2005 Georg Zotti, Institute of Computer Graphics, TU Vienna
# <gzotti(at)cg.tuwien.ac.at>

# Replace this by the name of your main .tex file (without the .tex)
BASENAME=cescgsmpl

# Add all your sourcefile names here. If you only have one .tex file, leave it as is. 
SOURCES = $(BASENAME).tex
# Here come the .bib files. If you don't use BibTeX, delete all entries here!
BIBFILES= smplbib.bib

# If you use ``classic'' latex: Add image names (*.eps) which get automatically created from jpg, tiff, etc. 
# THESE WILL BE DELETED with "make pristine"!
TMP_EPS=

# If you use pdflatex: Add image names (*.pdf) which get automatically created from eps etc. 
# THESE WILL BE DELETED with "make pristine"!
TMP_PDF=



.SUFFIXES:
.SUFFIXES: .dtx .tex .aux .log .lot .lof .toc .glo .gls .ilg .dvi .ps .pdf .eps .jpg .png .tiff
.PHONY:  ins eps dvi ps pdf show clean pristine classdoc

help:
	@echo "Use targets: dvi, ps, pdf create documents"
	@echo "             show         use xdvi to show dvi"
	@echo "             clean        delete intermediate files, but leave auto-converted EPS images"
	@echo "             pristine     delete all intermediate and formatted files"
	@echo "             classdoc     make cescg.dvi"

dvi : $(BASENAME).dvi
ps  : $(BASENAME).ps
pdf : $(BASENAME).pdf

$(BASENAME).dvi:  $(SOURCES) $(TMP_EPS) $(BASENAME).bbl 
#	latex $(BASENAME).tex
#	bibtex $(BASENAME)
	latex $(BASENAME).tex
	latex $(BASENAME).tex

$(BASENAME).ps: $(BASENAME).dvi
	dvips  -Ppdf -ta4 -G0 -o $(BASENAME).ps $(BASENAME).dvi 

# The first variant is fine for GhostScript 7.x, the second is for GhostScript 8.x!
$(BASENAME).pdf: $(BASENAME).ps
#	ps2pdf -dCompatibilityLevel=1.3 -dMaxSubsetPct=100 \
#               -dSubsetFonts=true -dEmbedAllFonts=true \
#               -dAutoFilterColorImages=false -dAutoFilterGrayImages=false \
#               -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode \
#               -dMonoImageFilter=/FlateEncode $(BASENAME).ps $(BASENAME).pdf
	ps2pdf -dPDFSETTINGS=/prepress -dCompatibilityLevel=1.3  \
               -dAutoFilterColorImages=false -dAutoFilterGrayImages=false \
               -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode \
               -dMonoImageFilter=/FlateEncode $(BASENAME).ps $(BASENAME).pdf

eps: $(TMP_EPS)

# If you use pdflatex, you may acivate these lines and delete the lines above 
#pdf $(BASENAME).pdf: $(BASENAME).bbl $(SOURCES) $(TMP_PDF)
#	pdflatex $(BASENAME).tex
#	bibtex $(BASENAME)
#	pdflatex $(BASENAME).tex
#	pdflatex $(BASENAME).tex

show: $(BASENAME).dvi
	xdvi -s 7 $(BASENAME).dvi &
# intermediate steps

$(BASENAME).bbl: $(BIBFILES) $(BASENAME).aux $(SOURCES)
	bibtex $(BASENAME)

$(BASENAME).aux: $(TMP_EPS) $(SOURCES)
	latex $(BASENAME).tex

# removing intermediate files or also the printable documents

clean:
	rm -f *~ *.aux *.bbl *.blg *.idx *.ilg *.ind *.log *.toc *.glo *.gls *.ilg 

pristine: clean
	rm -f $(BASENAME).pdf $(BASENAME).ps $(BASENAME).dvi *.tfm *pk $(TMP_EPS) $(TMP_PDF) 

.tiff.eps:
	convert $< eps:$@

.jpg.eps:
	convert $< eps:$@

.png.eps:
	convert $< eps:$@

.eps.pdf:
	cat $< | tr \\015 \\012 | epstopdf --filter > $@

classdoc: cescg.dtx
	latex cescg.dtx
	makeindex -s gglo.ist -o cescg.gls cescg.glo
	latex cescg.dtx

ins: cescg.dtx
	latex cescg.ins

cescg.cls cescgsmpl.tex example.eps smplbib.bib: ins
