# --- title of the project and name of the text file ---
#
TITLE	= flyer
SRC	= flyer

# --- path and program names, file and suffix lists ---
# 
VPATH	= .:fig

LPR	= lpr
XDVI	= xdvi
XPDF	= xpdf -z 0
GV	= gv -watch -scale -2

TAR	= makefile *.tex
TIDY	= *.dvi *.eps *.pdf *.ps *.ps.gz
CLEAN	= *.aux *.bak *.bbl *.blg *.lof *.log *.lot *.toc core .smhist *~ \\\#*

TAR	+= *.eps.gz *.tiff
CLEAN	+= 

.SUFFIXES:	.aux .bbl .bib .dvi .pdf .ps .tex .toc
.SUFFIXES:	.awk .eps .fig .gif .gz .jpeg .pdf .sm .tga .tiff .tmp

# --- targets for typesetting and viewing the tex file ---
#
.PHONY:	type view print
type:	$(SRC).dvi
view:	xdvi
print:	lp

# list of input files and figures
flyer	= preamble.tex layout.tex english.tex deutsch.tex svenska.tex
fig	= credativ.eps swirl.eps debian.eps

# grinding data into temporary data

# --- dependencies for various auxiliary files ---
# 
# add aux file if there are reasons for re-running latex (e.g. references)
# add bbl file if there are citations
# add eps or pdf, respectively, if there are figures
# add tex, if there are input files
flyer.dvi:	$(flyer) $(fig)
flyer.pdf:	$(flyer) $(fig:.eps=.pdf)

# --- view and print the typeset file ---
#
.PHONY:	xdvi xpdf gv lp
xdvi:	$(SRC).dvi
	$(XDVI) $(SRC) &
xpdf:	$(SRC).pdf
	$(XPDF) $(SRC).pdf &
gv:	$(SRC).ps
	$(GV) $(SRC).ps &
lp:	$(SRC).ps
	$(LPR) $(SRC).ps

# --- suffix rules ---
#
# suffix rules for figures
%.eps:	%.jpeg
	jpeg2ps $< > $@
%.eps %.pdf:	%.gif
	convert $< $@
%.eps %.pdf:	%.fig
	fig2dev -L $(subst .,,$(suffix $@)) $< $@
%.eps:	%.gz
	gunzip < $< > $@
%.eps:	%.eps.gz
	gunzip < $< > $@
%.eps:	%.sm
	cd $(<D); sm -q -S -v0 -f Null.sm device psfile $@ \\n input $(<F) quit || true
	mv $(<D)/$@ .
%.eps %.pdf:	%.tga
	convert $< $@
%.eps %.pdf:	%.tiff
	convert $< $@
%.pdf:	%.eps
	epstopdf $< -outfile=$@

# suffix rules for text
%.aux:	%.tex
	latex $*
%.bbl:	%.tex
	-bibtex $*
	latex $*
%.dvi:	%.tex
	latex $*
%.pdf:	%.tex
	pdflatex $*
#KLEIN	= -x 707 | pstops "4:0L(28.7cm,-0.7cm)+1L(28.7cm,14.15cm),2R(-7.7cm,30.4cm)+3R(-7.7cm,15.55cm)"
%.ps:	%.dvi
	dvips -f $* $(KLEIN) > $@

# even more suffix rules
%.ps.gz: %.ps
	gzip --force $<
%.pdf.gz: %.pdf
	gzip --force $<

# --- make the viewable files and the source available ---
# 
.PHONY: install
HMTL	= klecker:public_html/flyer
install:	flyer.tex $(flyer) $(fig:=.gz) flyer.pdf.gz flyer.ps.gz makefile
	chmod 644 $^
	rsync -e ssh -vau $^ $(HMTL)

# --- cleanup ---
#
.PHONY:	tar clean tidy suicide
tar:	$(TITLE).tar.gz
	cp $< $(TITLE)-`date -u +%d-%B-%C%y`.tar.gz
$(TITLE).tar.gz:	$(TAR)
	tar zcvf $@ $(TAR)
clean:	
	rm -f $(CLEAN)
tidy:	clean
	rm -f $(TIDY)
suicide:	tidy tar
	rm -f $(TAR)
	rmdir fig
