#
# configuration here:
#
url=http://wiki.debian.org/DebianEdu/Documentation/Manuals/Audacity/
name=audacity-manual
DEBIAN_EDU_DOC_TITLE="Debian Edu / Skolelinux Audacity manual"
path1=DebianEdu/Documentation/Manuals/Audacity
path2='\/DebianEdu\/Documentation\/Manuals\/'
export 
#
# no configuration below 
#
DESTDIR=
DESTPATH = /usr/share/doc
LANGUAGES = `find . -name "$(name).*.po" | sed -e "s/.\/$(name).//" -e "s/.po//"`

all: build

start_new_translation:
	../scripts/start_new_translation $(LANGUAGE)

update:
	../scripts/get_manual
	../scripts/update_translations

status:
	@for f in *.po ; do \
		echo -n "$$f: "; \
		LANG=C msgfmt --statistics $$f -o /dev/null ; \
	done
	@cat fixme-status.txt

build:
	# create localized xml files
	-for i in $(name).*.po ; do { \
	        po4a-translate -o tags="<listitem> <emphasis>" -M UTF-8 -k 5 -f docbook -m $(name).xml -p $$i -l $${i%.po}.xml ; \
	} done

	# Ignore errors because the docbook xml is broken
	#
	# build the english html version
	-openjade -t sgml -i html -E 1000 -d /usr/share/docbook-utils/docbook-utils.dsl\#html -V paper-type=A4 -V nochunks /usr/share/sgml/declaration/xml.dcl $(name).xml > $(name).en.html
	# Ignore errors because the docbook xml is broken
	#
	# build the other html versions
	-for f in $(LANGUAGES) ; do \
		openjade -t sgml -i html -E 1000 -d /usr/share/docbook-utils/docbook-utils.dsl\#html -V paper-type=A4 -V nochunks /usr/share/sgml/declaration/xml.dcl $(name).$$f.xml > $(name).$$f.html ; \
	done
	# add utf8 content-type header to html versions
	for f in $(name).*.html ; do \
		sed -i "s%><TITLE%><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><TITLE%" $$f ; \
	done

install: build
	# en needs to be first
	# FIXME: en is build twice...
	for f in en $(LANGUAGES) ; do \
		export LANGPATH=$(DESTDIR)/debian-edu-doc-$$f/$(DESTPATH)/debian-edu-doc-$$f ; \
		mkdir -p $$LANGPATH ; \
		if [ -e $(name).$$f.html ] ; then \
			cp $(name).$$f.html $$LANGPATH/$(name).html ; \
			if [ "$$f" = "en" ] ; then \
			  mkdir $$LANGPATH/images/ ; \
			  find images -maxdepth 1 -type f -exec cp \{\} $$LANGPATH/images/ \; ; \
			  dblatex -T db2latex -p $(name).xsl -o $$LANGPATH/$(name).pdf $(name).xml ; \
			else \
			  if [ -d images/$$f ] ; then \
			  	mkdir $$LANGPATH/images ; \
			  	cd images ; \
			  	for i in *.* ; do \
					if [ -e $$f/$$i ] ; then \
						cp -v $$f/$$i $$LANGPATH/images/ ; \
					else \
						ln -sf ../../debian-edu-doc-en/images/$$i $$LANGPATH/images/$$i ; \
					fi ; done ; \
			  	cd .. ; \
			  else \
			    ln -sf ../debian-edu-doc-en/images $$LANGPATH/images ; \
			  fi ; \
			  mv images images_tmp_away ; dblatex -I $$LANGPATH/ -I $(DESTDIR)/debian-edu-doc-en/$(DESTPATH)/debian-edu-doc-en/ -T db2latex -p $(name).xsl -o $$LANGPATH/$(name).pdf $(name).$$f.xml ; mv images_tmp_away images ; \
			fi ; \
		fi ; \
	done 		

clean:
	rm -f *.pdf
	rm -f *.html
	rm -f $(name).*.xml

dist-clean:	clean
