#!/usr/bin/make -f

#export DH_VERBOSE=1


build: build-stamp
build-stamp:
	dh_testdir
	mkdir build

	sed -e 's/^# //g' -e 's/\r//g' \
	    -e '/^USAGE:/,/^IMPORTANT NOTE:/{d}' \
	    < README.TXT > build/README
	cat -s TODO.TXT > build/TODO

	cp -f khmerconverter.py khmerconverter

	# copy __version__ to modules
	cp __version__.py modules/
	help2man -n 'convert between legacy Khmer encodings and Unicode' \
	         -s 1 -N -o build/khmerconverter.1 'python khmerconverter'

	convert converter.ico build/a.xpm	
	convert converter.ico +set date:create +set date:modify -define png:exclude-chunk=time build/a.png
	mv build/a-1.xpm build/khmerconverter.xpm
	mv build/a-2.png build/khmerconverter.png
	rm -f build/a-*.*

	# Perform tests (ignored ones fail)
	python modules/FontDataXML.py
	python modules/test_fontdata.py
	python modules/legacyReorder.py
	python modules/legacyConverter.py
	-python modules/legacyConvertOdt.py
	python modules/legacyConvertHTML.py
	python modules/legacyConvertText.py
	python modules/unicodeReorder.py
	python modules/unicodeProcess.py
	-python modules/unicodeConvertOdt.py
	python modules/unicodeConvertHTML.py
	python modules/unicodeConvertText.py

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf khmerconverter build build-stamp modules/*.pyc modules/__version__.py
	dh_clean
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	dh_install
	rm -f debian/khmerconverter/usr/share/khmerconverter/modules/test_fontdata.py
	chmod a-x debian/khmerconverter/usr/share/khmerconverter/modules/*
	chmod a+x \
	  debian/khmerconverter/usr/share/khmerconverter/modules/FontDataXML.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/legacyReorder.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/legacyConverter.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/legacyConvertOdt.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/legacyConvertHTML.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/legacyConvertText.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/unicodeReorder.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/unicodeProcess.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/unicodeConvertHTML.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/unicodeConvertText.py \
	  debian/khmerconverter/usr/share/khmerconverter/modules/unicodeConvertOdt.py

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGELOG.TXT
	dh_installdocs
	dh_installman
	dh_installmenu
	dh_python2
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
