TEXFILES=$(wildcard *.tex)
PDFFILES=$(TEXFILES:.tex=.pdf)
BASENAMES=$(TEXFILES:.tex=.)

all: talk again watchtalk clean cleanup help

talk: $(PDFFILES)
talks: $(PDFFILES)
$(PDFFILES): %.pdf : %.tex beamer*.sty
	pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true

again :
	for FILE in $(TEXFILES); do \
	    pdflatex $(FILE) \
	done


watchtalks : watchtalk
watchtalk :
	while true; do ! make -q talk && make talk; sleep 0.5; done

install :
	./install.sh


clean :
	rm -f *~
	rmtex $(BASENAMES)

cleanup : clean
	rm -f $(PDFFILES)

help : 
	@echo -e \
	"make talk:       make the pdf file of the talk.\n"\
	"make again:      run latex and make the pdf file of the talk,\n"\
        "                 no matter whether you changed the .tex file or not.\n\n"\
	"make watchtalk:  make the pdf file of the talk\n"\
        "                 whenever the tex file or the plots are modified.\n"\
	"make install:    install the style files.\n"\
	"make clean:      remove all intermediate files,\n"\
        "                 just leave the source files and the final pdf file.\n"\
	"make cleanup:    remove all intermediate files as well as\n"\
        "                 the final pdf file.\n"
