GOPTS = -nop
VERBOSE = --verbose --verbose

%.ascii: %.txt
	@echo "genuinetoccing..." >&2
	@genuinetoc -width:70 -pipe "-chars:.   " $< > $@

%.latex: %.txt
	@echo "genuining..." >&2
	@cp $< temp.txt
	@genuine -v '$(GOPTS)' temp.txt
	@rm temp.txt
	@mv temp.latex $@

%.dvi: %.latex
	@echo "latexing..." >&2
	@latex $< || genuinefixwrapper `basename $< .latex`; echo $$?
	@c=0; \
	while grep "Rerun to get cross-references right" `basename $< .latex`.log; do \
		latex $< || genuinefixwrapper `basename $< .latex`; echo $$?; \
		: $$[c++]; \
		[ "$$c" = "10" ] && exit 0; \
	done; \
	exit 0

%.ps: %.dvi
	@echo "dvipsing..." >&2
	@dvips $< #-Pwww is better, but not available on all systems

%.pdf: %.ps
	@echo "pdfing..." >&2
	@ps2pdf $< $@

LOCAL = 0
ifeq ($(LOCAL),1)
BASE = file:///home/iblech/schule/klasse10/html
FASTPDF = --fastpdf
else
BASE = http://home.as-netz.de/gblech/klasse10
FASTPDF =
endif

htmlgen: *.html Makefile generate.pl
	mkdir .tmp || true
	cp latex-contrib/* .tmp
	./generate.pl \
	  --template="template.html" \
	     --mmark="MAIN" \
	      --name="Ingo Blechschmidt" \
	      --mail="iblech@web.de" \
	     --output="html" \
	       --temp=".tmp" \
	   --makefile="Makefile" \
	       --cols=80 \
	       --base="$(BASE)" \
	      --start="." \
			  --gopts='-config:leet:<==>,\ensuremath{\Longleftrightarrow},==>,\ensuremath{\Longrightarrow},,\euro\,,\ensuremath{^\circ},,\cdot{}' \
				  --add='[config: latex ==> allow]' \
	  --extrahtml="using.html,recent.html,HAs.html,failure.html" \
			  --secret="S3cr3t/" \
	      $(VERBOSE) --pdf $(FASTPDF)
	cp -a gnu* valid-* css-* template.html misc html
	touch htmlgen

upload: htmlgen
	sitecopy --update klasse10
	touch upload

all: html upload

clean:
	@echo "cleaning..." >&2
	@rm texput.log *.pdf *.dvi *.ascii *.toc *.ps *.aux *.tmp *.latex *.log 2>/dev/null || true
	@rm -r .cached html 2>/dev/null || true

rescue:
	@echo "rescuing..." >&2
	@cvs ci -m Yeah-R
	@~/schule/alles/sichere.sh
	@(cd ..; tar cvz klasse10) | ssh mars "cat > backup-klasse10-+`date +%V`"

.PHONY: clean upload htmlgen rescue
