# Directions for adding a new language:
# 1. Add the two-letter code to LANGS below.
# 2. Add a new "%.html.es: es/%.wml en/%.wml" clause below.
# 3. Add a new ".deps/%.html.es.d: es/%.wml .deps/.stamp" clause below.
# 4. mkdir a new two-letter directory. Make sure there's a foot.wmi
#    and navigation.wmi.
# 5. Edit include/perl-globals.wmi, add to @LANGUAGES and %LANGUAGES.
#    You might find useful %LANGUAGES strings at the bottom of
#    http://debian.org/
# 6. Add a new images/es.png flag image.

WMLOPT  = \
          -I $(WMLBASE)/include \
          -D DOCROOT=$(WMLBASE) \
          -D IMGROOT=$(WMLBASE)/images \
          -D TORSVNSTABLE=$(TORSVNSTABLE) \
          -D TORGIT=$(TORGIT) \
          -D DEVTAG=$(DEVTAG) \
          -D STABLETAG=$(STABLETAG)

LANGS=bms de en es et fa fi fr it lv nl no pl pt ru se sk uk zh-cn

WMLFILES=$(wildcard $(patsubst %, %/*.wml, $(LANGS)))
WMIFILES=$(wildcard $(patsubst %, %/*.wmi, $(LANGS)) $(WMLBASE)/include/*.wmi )

HTMLFILES = $(shell perl -le 's,  (.*)/(.*).wml  ,        $$2.html.$$1    ,x, print $$_ for @ARGV' $(WMLFILES))
DEPFILES  = $(shell perl -le 's,  (.*)/(.*).wml  ,  .deps/$$2.html.$$1.d  ,x, print $$_ for @ARGV' $(WMLFILES))


all: $(HTMLFILES)

%.html.en: en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.ar: ar/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.bms: bms/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.es: es/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.et: et/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.de: de/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.fa: fa/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.it: it/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.fi: fi/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.fr: fr/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.ja: ja/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.ko: ko/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.lv: lv/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.nl: nl/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.no: no/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.pl: pl/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.pt: pt/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.ru: ru/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.se: se/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.sk: sk/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.tr: tr/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.uk: uk/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

%.html.zh-cn: zh-cn/%.wml en/%.wml
	lang=`dirname $<` && wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $@

.deps/%.html.en.d: en/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.ar.d: es/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.bms.d: bms/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.es.d: es/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.et.d: et/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.de.d: de/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.it.d: it/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.fa.d: fa/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.fi.d: fi/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.fr.d: fr/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.ja.d: ja/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.ko.d: ko/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.lv.d: lv/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.nl.d: nl/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.no.d: no/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.pl.d: pl/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.pt.d: pt/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.ru.d: ru/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.se.d: se/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.sk.d: sk/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.tr.d: tr/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.uk.d: uk/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/%.html.zh-cn.d: zh-cn/%.wml .deps/.stamp
	tmpfile=`mktemp -t tmp.XXXXXXX` \
	lang=`dirname $<` && \
	OUT=`echo $@ | sed -e 's,\.deps/\(.*\)\.d$$,\1,'` && \
	wml $(WMLOPT) -I $$lang -I $(WMLBASE)/$$lang -D LANG=$$lang $< -o $$OUT --depend | tee $$tmpfile > $@ && \
	sed -e s',\(^[^ ]*\):,.deps/\1.d:,' < $$tmpfile >> $@ && \
	rm -f $$tmpfile
.deps/.stamp:
	[ -d .deps ] || mkdir .deps
	touch "$@"

dep: $(DEPFILES)
clean:
	rm -f $(HTMLFILES) $(DEPFILES)
	for sub in $(SUBDIRS); do \
		$(MAKE) -C "$$sub" WMLBASE=../$(WMLBASE) clean; \
	done

include $(DEPFILES)