RST2HTML = rst2html
RST2LATEX = ../scripts/rst2latex.py
PDFLATEX = pdflatex
RM = rm -f

all: larpe-admin.pdf larpe-admin.html

%.html: %.rst
	$(RST2HTML) --stylesheet=default.css --link-stylesheet --language=en $? > $@

figures-no-alpha-stamp:
	-$(RM) -r figures-no-alpha/
	mkdir figures-no-alpha/
	for F in figures/*.png; do \
		../scripts/removealpha.sh $$F figures-no-alpha/`basename $$F`; \
	done
	touch figures-no-alpha-stamp

%.tex: %.rst #figures-no-alpha-stamp
	cat $? | sed -e 's/figures\//figures-no-alpha\//' \
			-e 's/ ::$$/ : ::/g' \
			-e 's/.. section-numbering:://' | $(RST2LATEX) --language=en > $@

%.pdf: %.tex custom.tex
	$(PDFLATEX) $?
	logfile=`echo "$@" |sed -r "s/(.*)....$$/\\1/"`.log; while [ -f "$$logfile" -a -n "`grep "Rerun to get cross-references right" $$logfile`" ]; do $(PDFLATEX) $< ; done

clean:
	-$(RM) *.aux *.toc *.log *.out
	-$(RM) larpe-admin.pdf
	-$(RM) larpe-admin.tex
	-$(RM) larpe-admin.html
	-$(RM) -r figures-no-alpha figures-no-alpha-stamp

.PHONY: all clean
