#!/usr/bin/make -f
#export DH_VERBOSE=1
export QT_SELECT := qt5
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEBIAN_SPELLDIR := /usr/share/hunspell

ISOFILES = dictionaries/README_DIC_fr_FR.txt
ISOFILES += dictionaries/README_en_US.txt
ISOFILES += dictionaries/README_pt_PT.txt
ISOFILES += dictionaries/it_IT_README.txt
ISOFILES += dictionaries/cs_CZ.dic
ISOFILES += dictionaries/cs_CZ.aff
ISOFILES += dictionaries/de_DE.aff
ISOFILES += dictionaries/en_GB.aff
ISOFILES += dictionaries/en_GB.dic
ISOFILES += dictionaries/es_ES.aff
ISOFILES += dictionaries/es_ES.dic
ISOFILES += dictionaries/fr_FR.dic
ISOFILES += dictionaries/it_IT.aff
ISOFILES += dictionaries/it_IT.dic
ISOFILES += dictionaries/pl_PL.aff
ISOFILES += dictionaries/pl_PL.dic
ISOFILES += scripts/titlecase_selection.tms

pkg=texmaker
data=$(pkg)-data

%:
	dh $@

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) distclean
	$(RM) .obj/* .moc/* .ui/*
	dh_auto_clean

override_dh_auto_build:
	# convert a few ISO-8859-1 files to address national-encoding
	set -e \
	; for file in $(ISOFILES) \
	; do    iconv -f ISO-8859-1 -t UTF-8 < $${file} > "$${file}.new" \
	;	mv "$${file}.new" "$${file}" \
	; done
	dh_auto_build

override_dh_auto_test:
	# do not try testing

override_dh_installchangelogs:
	dh_installchangelogs utilities/CHANGELOG.txt

override_dh_installdocs:
	dh_installdocs
	# Setting symlinks from doc dir to /usr/share/texmaker
	for docfile in `ls $(CURDIR)/debian/$(data)/usr/share/$(pkg)/*.html $(CURDIR)/debian/$(data)/usr/share/$(pkg)/*.png` ; do \
	    dh_link -p $(data) `echo $${docfile} | sed 's#^.*/debian/[^/]\+/##'` /usr/share/doc/$(pkg)/html/`basename $${docfile}` ; \
	done

override_dh_install:
	dh_install
	find debian/*/usr/share \( -name COPYING -o -name CHANGELOG.txt \) -delete
