
DOC_TXT =            yes
DOC_HTML =           yes
DOC_MAN =            yes
DOC_INFO =           yes
DOC_PS =             yes
DOC_PDF =            yes
DOC_PHP3 =           no
DOC_UWC =            no

VERSION =            5.6.3

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

HTML_FILES = $(addprefix html/,$(addsuffix .html,$(FILES)))
PHP3_FILES = $(addprefix php3/,$(addsuffix .php3,$(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) php3_$(DOC_PHP3) 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 

php3_yes: $(PHP3_FILES)

uwc_yes: $(UWC_FILES)

txt_no:

html_no:

man_no:

info_no:

ps_no:

pdf_no:

php3_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')"

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

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) $(PHP3_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:



