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

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

pkg=texmaker
data=$(pkg)-data

%:
	dh $@ --buildsystem=cmake

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_installchangelogs:
	dh_installchangelogs datas/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
