REST2HTML = rst2html
RST2LATEX = ../scripts/rst2latex.py
PDFLATEX = pdflatex

all: wcs-admin.pdf wcs-admin.html

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

figures-no-alpha-stamp:
	-rm -rf 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=fr > $@

%.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 wcs-admin.pdf
	-rm wcs-admin.tex
	-rm wcs-admin.html
	-rm -rf figures-no-alpha figures-no-alpha-stamp

.PHONY: all clean
