BASENAME=pointprocesses

PYFILES=$(wildcard *.py)
PYPDFFILES=$(PYFILES:.py=.pdf)

GPTFILES=$(wildcard *.gpt)
GPTTEXFILES=$(GPTFILES:.gpt=.tex)


all: pdf slides thumbs

# script:
pdf : $(BASENAME)-chapter.pdf
$(BASENAME)-chapter.pdf : $(BASENAME)-chapter.tex $(BASENAME).tex $(GPTTEXFILES) $(PYPDFFILES)
	pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true


# slides:
slides: $(BASENAME)-slides.pdf
$(BASENAME)-slides.pdf : $(BASENAME)-slides.tex $(GPTTEXFILES) $(PYPDFFILES)
	pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true

# thumbnails:
thumbs: $(BASENAME)-handout.pdf
$(BASENAME)-handout.pdf: $(BASENAME)-slides.tex $(GPTTEXFILES)
	sed -e 's/setboolean{presentation}{true}/setboolean{presentation}{false}/; s/usepackage{crop}/usepackage[frame]{crop}/' $< > thumbsfoils.tex
	pdflatex thumbsfoils | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex thumbsfoils || true
	pdfnup --nup 2x4 --no-landscape --paper a4paper --trim "-1cm -1cm -1cm -1cm" --outfile $@ thumbsfoils.pdf # 1-19
	rm thumbsfoils.*

watchpdf :
	while true; do ! make -q pdf && make pdf; sleep 0.5; done

watchslides :
	while true; do ! make -q slides && make slides; sleep 0.5; done

# python plots:
$(PYPDFFILES) : %.pdf: %.py
	python $<

# gnuplot plots:
$(GPTTEXFILES) : %.tex: %.gpt whitestyles.gp
	gnuplot whitestyles.gp $<
	epstopdf $*.eps


clean :
	rm -f *~ 
	rm -f $(BASENAME).aux $(BASENAME).log
	rm -f $(BASENAME)-chapter.aux $(BASENAME)-chapter.log $(BASENAME)-chapter.out
	rm -f $(BASENAME)-slides.aux $(BASENAME)-slides.log $(BASENAME)-slides.out $(BASENAME)-slides.toc $(BASENAME)-slides.nav $(BASENAME)-slides.snm $(BASENAME)-slides.vrb
	rm -f $(PYPDFFILES) $(GPTTEXFILES)

cleanall : clean
	rm -f $(BASENAME)-chapter.pdf $(BASENAME)-slides.pdf $(BASENAME)-handout.pdf


help : 
	@echo -e \
	"make pdf:        make the pdf file of the script.\n"\
	"make slides:     make the pdf file of the slides.\n"\
	"make thumbs:     make color thumbnails of the talk.\n"\
	"make watchpdf:   make the pdf file of the script\n"\
        "                 whenever the tex file is modified.\n"\
	"make watchpdf:   make the pdf file of the slides\n"\
        "                 whenever the tex file is modified.\n"\
	"make clean:      remove all intermediate files,\n"\
        "                 just leave the source files and the final .pdf files.\n"\
	"make cleanup:    remove all intermediate files as well as\n"\
        "                 the final .pdf files.\n"\
