#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export JAVA_HOME=/usr/lib/jvm/default-java

%:
	dh $@ --with tex,javahelper

override_dh_auto_clean:
	ant clean

override_dh_auto_build-indep:
	ant -DURE_CLASSES=/usr/lib/libreoffice/program/classes -DOFFICE_CLASSES=/usr/lib/libreoffice/program/classes jar
	ant javadoc
	ant oxt

execute_after_dh_install-indep:
	install -D -m755 debian/libreoffice-writer2latex.script.bug \
		debian/libreoffice-writer2latex/usr/share/bug/libreoffice-writer2latex/script

	# fix up user-manual.odt (#610312)
	t=`mktemp -q -d`; \
	cd $$t && unzip $(CURDIR)/source/distro/doc/user-manual.odt && \
		perl -pi -e 's#<config:config-item config:name="PrinterName" config:type="string">Generic Printer</config:config-item>##' settings.xml && \
		perl -pi -e 's#<config:config-item config:name="PrinterSetup" config:type="base64Binary">VAH+/0dlbmVyaWMgUHJpbnRlcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU0dFTlBSVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWAAMAmgAAAAAAAAABAAhSAAAEdAAASm9iRGF0YSAxCnByaW50ZXI9R2VuZXJpYyBQcmludGVyCm9yaWVudGF0aW9uPVBvcnRyYWl0CmNvcGllcz0xCm1hcmdpbmRhanVzdG1lbnQ9MCwwLDAsMApjb2xvcmRlcHRoPTI0CnBzbGV2ZWw9MApjb2xvcmRldmljZT0wClBQRENvbnRleERhdGEKUGFnZVNpemU6QTQAAA==</config:config-item>##' settings.xml && \
		zip -r $(CURDIR)/debian/writer2latex-manual/usr/share/doc/writer2latex/manual/user-manual.odt settings.xml

	mkdir -p debian/libreoffice-writer2latex/usr/lib/libreoffice/share/extensions/writer2latex
	cd debian/libreoffice-writer2latex/usr/lib/libreoffice/share/extensions/writer2latex && \
		unzip -o $(CURDIR)/target/lib/writer2latex.oxt
	mkdir -p debian/libreoffice-writer2xhtml/usr/lib/libreoffice/share/extensions/writer2xhtml
	cd debian/libreoffice-writer2xhtml/usr/lib/libreoffice/share/extensions/writer2xhtml && \
		unzip -o $(CURDIR)/target/lib/writer2xhtml.oxt

override_dh_installchangelogs:
	dh_installchangelogs source/distro/History.txt

override_dh_compress:
	dh_compress -X.odt

override_jh_depends:
	jh_depends -Xlibdtd-parser-java
