
DOC_TXT =            @DOC_TXT@
DOC_HTML =           @DOC_HTML@
DOC_MAN =            @DOC_MAN@
DOC_INFO =           @DOC_INFO@
DOC_PS =             @DOC_PS@
DOC_PDF =            @DOC_PDF@
DOC_PHP =           @DOC_PHP@
DOC_UWC =            @DOC_UWC@

VERSION =            @VERSION@

FILES = rules \
	authors \
	mailinglists \
	fanfic \
	options \
	network \
	parameters \
	platforms \
	userlevels \
	algorithm \
	source \
	bugs \
	todo \
	wip \
	copying

HTML_FILES = $(addprefix html/,$(addsuffix .html,$(FILES)))
PHP_FILES = $(addprefix php/,$(addsuffix .php,$(FILES)))
TEX_FILES = $(addprefix tex/,$(addsuffix .tex,$(FILES)))
MAN_FILES = $(addprefix man/,$(addsuffix .man,$(FILES)))
TXT_FILES = $(addprefix txt/,$(addsuffix .txt,$(FILES)))
TEXI_FILES = $(addprefix texi/,$(addsuffix .texi,$(FILES)))
UWC_FILES = $(addprefix uwc/,$(addsuffix .uwc,$(FILES)))


# To enable/disable documentation formats:
# - if format xxx must be built, then the ./configure
#   script has set $(XXX) to "yes" so we build target
#   xxx_yes which is the "real" target.
# - if format xxx must be skipped, then the ./configure
#   script has set $(XXX) to "no" so we build target
#   xxx_no, which is a "fake" empty target.
all: txt_$(DOC_TXT) html_$(DOC_HTML) man_$(DOC_MAN) info_$(DOC_INFO) ps_$(DOC_PS) pdf_$(DOC_PDF) php_$(DOC_PHP) uwc_$(DOC_UWC)

txt_yes: $(TXT_FILES)

html_yes: $(HTML_FILES) 

man_yes: man/liquidwar.6.gz

info_yes: info/liquidwar.info.gz

ps_yes: ps/liquidwar.ps

pdf_yes: pdf/liquidwar.pdf 

php_yes: $(PHP_FILES)

uwc_yes: $(UWC_FILES)

txt_no:

html_no:

man_no:

info_no:

ps_no:

pdf_no:

php_no:

uwc_no:

pdf/liquidwar.pdf : ps/liquidwar.ps
	@echo "Building $@..."
	@cd tex; pdflatex liquidwar.tex && cd .. || cd ..
	@cd tex; pdflatex liquidwar.tex && cd .. || cd ..
	@if [ -f tex/liquidwar.pdf ]; then mv tex/liquidwar.pdf $@; fi

ps/liquidwar.ps : tex/liquidwar.dvi
	@echo "Building $@..."
	@dvips -q -o $@ $<

tex/liquidwar.dvi : $(TEX_FILES) tex/liquidwar.tex
	@echo "Building $@..."
	@cd tex; latex liquidwar.tex && cd .. || cd ..
	@cd tex; latex liquidwar.tex && cd .. || cd ..

man/liquidwar.6 : man/liquidwar.man
	@cp $< $@

man/liquidwar.man : $(MAN_FILES) man/begin.man man/end.man
	@echo "Building $@..."
	@cat man/begin.man $(MAN_FILES) man/end.man > $@

info/liquidwar.info.gz : texi/liquidwar.texi
	@echo "Building $@..."
	@rm -f info/liquidwar.info*
	@makeinfo -o info/liquidwar.info $<
	@gzip -9 info/liquidwar.info*

texi/liquidwar.texi : $(TEXI_FILES) texi/begin.texi texi/end.texi
	@echo "Building $@..."
	@cat texi/begin.texi $(TEXI_FILES) texi/end.texi > $@

html/%.html: xml/%.xml makedoc.py html/header.inc html/footer.inc
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_html('$@','$<','html/header.inc','html/footer.inc')"

php/%.php: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_php('$@','$<')"

tex/%.tex: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_tex('$@','$<')"

man/%.man: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_man('$@','$<')"

txt/%.txt: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_txt('$@','$<','Liquid War (v$(VERSION))')"

texi/%.texi: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_texi('$@','$<')"

uwc/%.uwc: xml/%.xml makedoc.py
	@echo Creating $@ from $<
	@python -c "import makedoc; makedoc.make_uwc('$@','$<')"

%.gz: %
	@if [ -f $< ]; then echo "Compressing $@..."; gzip -c -9 $< > $@; fi

dummy:

clean:
	@rm -f *~ */*~ 
	@rm -f makedoc.pyc
	@rm -f $(HTML_FILES) $(PHP_FILES) $(TEX_FILES) $(MAN_FILES) $(TXT_FILES) $(TEXI_FILES) $(UWC_FILES)
	@rm -f tex/liquidwar.toc tex/liquidwar.log tex/liquidwar.dvi tex/liquidwar.aux ps/liquidwar.ps pdf/liquidwar.pdf man/liquidwar.6 man/liquidwar.6.gz man/liquidwar-server.6.gz man/liquidwar-mapgen.6.gz man/liquidwar.man info/liquidwar.info* texi/liquidwar.texi texi/liquidwar.info*

distclean: 
	@rm -f Makefile
	@rm -f tex/liquidwar.tex man/begin.man texi/begin.texi html/index.html

config:

check:
	@xmllint --valid --noout xml/*.xml

dep:



