.PHONY: all all-pres all-notes4 clean reallyclean show 

BASENAME=cl08security-anon
DEST=presentation
DEFAULTDEPS=logo.pdf tor-logo.png tor-keys1.pdf tor-keys2.pdf tor-keys3.pdf \
	mix.pdf remailer.pdf

PUBLISHDIR=$(HOME)/public_html/talks
PUBLISHTARGET=template.pdf

GLOBAL=$(HOME)/local/presentation

TCPP=cpp -traditional-cpp -x c -P -C
LATEX=pdflatex

VIEWER=evince --presentation -p 1

all: all-pres all-notes4

tor-keys1.svg: tor-keys.svg
	./xmlreveal.py $< $@ "Base" "A"
tor-keys2.svg: tor-keys.svg
	./xmlreveal.py $< $@ "Base" "TLS" "TLS2" "A"
tor-keys3.svg: tor-keys.svg
	./xmlreveal.py $< $@ "Base" "TLS" "TLS2" "A" "B"

%.pdf: %.svg
	inkscape -A $@ $<

all-pres all-notes4: all-%: $(BASENAME)-%.pdf
	mkdir -p $(DEST)
	cp $^ $(DEST)

show: all-pres
	i810switch crt on || true
	$(VIEWER) $(DEST)/$(BASENAME)-pres.pdf

publish: $(BASENAME)-pres.pdf
	cp $(BASENAME)-pres.pdf $(PUBLISHDIR)/$(PUBLISHTARGET)
	chmod 644 $(PUBLISHDIR)/$(PUBLISHTARGET)

logo.pdf tor-logo.png:
	ln -s $(GLOBAL)/$@ .

$(BASENAME)-pres.pdf $(BASENAME)-notes.pdf: $(DEFAULTDEPS)

$(BASENAME)-notes4.pdf: $(BASENAME)-notes.pdf
	pdftops -paperw 363 -paperh 273 $(BASENAME)-notes.pdf
	psnup -w11cm -4 $(BASENAME)-notes.ps -W12.8cm -H9.6cm > $(BASENAME)-notes4.ps
	ps2pdf $(BASENAME)-notes4.ps

$(BASENAME)-notes.tex: $(BASENAME).tex
	$(TCPP) -DHANDOUT $(BASENAME).tex > $(BASENAME)-notes.tex

$(BASENAME)-pres.tex: $(BASENAME).tex
	$(TCPP) $(BASENAME).tex > $(BASENAME)-pres.tex

clean:
	rm -f *~ *.dvi *.log *.bak *.aux *.toc *.ps *.eps *.pdf *.blg *.bbl \
	      *.pstex *.pstex_t *.pdftex *.pdftex_t *.out *.png *.snm *.nav \
               $(BASENAME)-notes.tex $(BASENAME)-pres.tex

reallyclean: clean
	rm -rf $(DEST)

%.pdf: %.tex
	pdflatex $< || { rm -f $*.pdf $*.dvi $*.aux $*.idx && false ; }
	while grep 'Rerun to get cross-references right.' $*.log ; do \
	  pdflatex $< || { rm -f $*.pdf $*.dvi $*.aux $*.idx && false ; } ; done
