#! /usr/bin/make -f

PACKAGE=localechooser
DATAPACKAGE=localechooser-data
OCPACKAGE=oem-config-locale

build: build-stamp
build-stamp:
	dh_testdir
	chmod u+x ./get-SUPPORTED ./mktemplates.country ./get-iso-codes ./mk_shortlist_templates
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) clean
	rm -rf debian/pobuild debian/iso-codes debian/short-tmp debian/locales debian/SUPPORTED-short
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -i
	dh_install -p$(PACKAGE) localechooser languagemap usr/bin
	mkdir -p debian/$(PACKAGE)/DEBIAN
	install -m0755 post-base-installer debian/$(PACKAGE)/usr/lib/post-base-installer.d/05localechooser
	install -m0755 prebaseconfig debian/$(PACKAGE)/usr/lib/prebaseconfig.d/05localechooser
	install -m644 languagelist debian/$(PACKAGE)/usr/share/languagelist
	dh_installdirs -p$(PACKAGE) etc
	# The following while we have no other way to get SUPPORTED
	# Should become useless when we will have it
	install -m644 debian/SUPPORTED-short debian/$(PACKAGE)/etc/SUPPORTED-short
	install -m644 debian/short-tmp/shortlists debian/$(PACKAGE)/etc/shortlists
	dh_install -p$(DATAPACKAGE) default-country languagelist regionmap debian/SUPPORTED-short debian/short-tmp/shortlists usr/share/localechooser
	dh_install -p$(OCPACKAGE) localechooser languagemap usr/lib/oem-config/locale/
	dh_install -p$(OCPACKAGE) oem-config/locale* usr/lib/oem-config/menu/

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs -p$(DATAPACKAGE) -p$(OCPACKAGE)
	dh_installchangelogs -p$(DATAPACKAGE) -p$(OCPACKAGE)
	dh_installdebconf -i
	sed -e 's,Template: debian-installer/localechooser/title,Template: oem-config/menu/locale,' \
		< debian/$(PACKAGE)/DEBIAN/templates \
		> debian/$(OCPACKAGE)/usr/lib/oem-config/menu/locale.templates
	dh_strip -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_shlibdeps -i
	dh_gencontrol -i
	dh_builddeb -i

binary-arch: build install

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