DEPTH = ../..
RELEASE_DIR = $(DEPTH)/release/FreeDoko_$(VERSION)/doc/en/

include $(DEPTH)/Makefile.os

#DOCUMENTS = freedoko_konzept freedoko_regeln kurzregeln

#include ../Makefile.latex

.PHONY: all
all: txt pdf

ifeq ($(OPERATING_SYSTEM), Linux)
.PHONY: release
release : all
	mkdir -p $(RELEASE_DIR)
	for f in introduction shortrules rules configuration FAQ; do \
	  cp $$f.txt $$f.pdf $(RELEASE_DIR); \
	done
	cp README* $(RELEASE_DIR)
endif

ifeq ($(OPERATING_SYSTEM), Linux)
.PHONY: txt
txt : README.txt introduction.txt shortrules.txt rules.txt configuration.txt FAQ.txt

README.txt : README.html
	w3m -dump $< > $@
	flip -mb $@

introduction.txt : ../manual/en/introduction.html
	w3m -dump $< > $@
	flip -mb $@

shortrules.txt : ../manual/en/shortrules.html
	w3m -dump $< > $@
	flip -mb $@

rules.txt : ../manual/en/rules.html
	w3m -dump $< > $@
	flip -mb $@

configuration.txt : ../manual/en/configuration.html
	w3m -dump $< > $@
	flip -mb $@

FAQ.txt : ../manual/en/faq.html
	w3m -dump $< > $@
	flip -mb $@
endif

ifeq ($(OPERATING_SYSTEM), Linux)
.PHONY: pdf
pdf : introduction.pdf shortrules.pdf rules.pdf configuration.pdf FAQ.pdf

introduction.pdf : ../manual/en/introduction.html
	htmldoc --webpage --color --numbered --quiet --format --truetype -f $@ $<

shortrules.pdf : shortrules.tex
	latex $(basename $@).tex \
	  && dvips $(basename $@).dvi -o - | ps2pdf - $@ \
	  && rm $(basename $@).dvi
	rm -f $(basename $@).{aux,dvi,log}

rules.pdf : ../manual/en/rules.html
	htmldoc --webpage --color --numbered --quiet --format --truetype -f $@ $<

configuration.pdf : ../manual/en/configuration.html
	htmldoc --webpage --color --numbered --quiet --format --truetype -f $@ $<

FAQ.pdf : ../manual/en/faq.html
	htmldoc --webpage --color --numbered --quiet --format --truetype -f $@ $<

endif

clean :
	for f in README introduction shortrules rules configuration FAQ; do \
	  rm -f $$f.txt $$f.pdf; \
	done
