#!/usr/bin/make -f

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

export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed
export QT_SELECT=5

# Value of the l10n:{Depends,Recommends,Suggests,Replaces,Breaks,Provides}
# substvars. Common relationships for each l10n package.
L10N_Depends := calligra-libs (>= 1:3.0)
L10N_Recommends :=
L10N_Suggests := calligra
L10N_Replaces :=
L10N_Breaks :=
L10N_Provides := calligra-l10n

L10N_PREFIX := calligra-l10n
L10N_PACKAGES_IN_CONTROL = $(shell dh_listpackages | grep '$(L10N_PREFIX)')

%:
	dh $@ --parallel --with kf5

override_dh_auto_configure:
	dh_auto_configure -Skf5 -- -DBUILD_TESTING=OFF -DBUILD_app_cstester=OFF -DBUILD_app_devtools=OFF -DCALLIGRA_SHOULD_BUILD_UNMAINTAINED=ON

override_dh_auto_install:
	dh_auto_install
	# Remove development symlinks of libraries
	find debian/tmp/usr/lib -name '*.so' -type l -print -delete
	# Remove mimetypes already provided by shared-mime-info
	rm -f debian/tmp/usr/share/mime/packages/msooxml-all.xml
	rm -f debian/tmp/usr/share/mime/packages/x-iwork-keynote-sffkey.xml
	# Remove fonts already in fonts-lyx package
	rm -f debian/tmp/usr/share/calligra_shape_formula/fonts/cmex10.ttf
	# Remove x-test "translations"
	rm -fr debian/tmp/usr/share/locale/x-test
	# Remove translations of stuff not shipped
	rm -f debian/tmp/usr/share/locale/*/LC_MESSAGES/calligra_semanticitem_*.mo
	rm -f debian/tmp/usr/share/locale/*/LC_MESSAGES/flow.mo
	rm -f debian/tmp/usr/share/locale/*/LC_MESSAGES/okularGenerator_odp.mo
	rm -f debian/tmp/usr/share/locale/*/LC_MESSAGES/okularGenerator_odt.mo

override_dh_install:
	dh_install --list-missing

override_dh_strip:
	dh_strip --dbgsym-migration='calligra-dbg (<< 1:2.9.11)'

override_dh_gencontrol:
	dh_gencontrol $(foreach p,$(L10N_PACKAGES_IN_CONTROL),-p$(p)) -- $(foreach rel,Depends Recommends Suggests Replaces Breaks Provides,-V'l10n:$(rel)=$(L10N_$(rel))')
	dh_gencontrol --remaining-packages

.PHONY: override_dh_auto_test
