#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/GNUstep/debian/config.mk
d_app := $(CURDIR)/debian/cynthiune.app
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND := -Wl,--no-undefined \
				     -Wl,-rpath,/usr/lib/cynthiune.app

# Don't build the deprecated Esound (#856078) and the broken
# WindowsMedia (#756184, #647783) bundles.
disabled := disable-esound=yes disable-windowsmedia=yes

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- $(disabled) $(verbose) $(optim) \
	  $(shell dpkg-buildflags --export=cmdline)
	icns2png --extract --size 128 --depth 32 Images/Cynthiune.icns

override_dh_clean:
	dh_clean -XChangeLog.orig -XPlaylistController.m.orig
	$(RM) Cynthiune_128x128x32.png

override_dh_auto_install:
# Cheat GNUstep Make to create the symlinks for the Cynthiune library
# in /usr/lib/cynthiune.app.
	dh_auto_install -- $(disabled) \
	  GNUSTEP_SYSTEM_LIBRARIES=/usr/lib/cynthiune.app
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/*.app/Resources/COPYING

execute_before_dh_link:
	gsdh_gnustep --app
# Convert translations to fix lintian W: national-encoding.
	for f in Armenian English French German Italian; do \
	  iconv -f UTF-16LE -t UTF-8 < $$f.lproj/Localizable.strings \
	    > $(d_app)/usr/share/GNUstep/Cynthiune.app/$$f.lproj/Localizable.strings; \
	done
	for f in Hungarian Slovak Spanish; do \
	  iconv -f UTF-16BE -t UTF-8 < $$f.lproj/Localizable.strings \
	    > $(d_app)/usr/share/GNUstep/Cynthiune.app/$$f.lproj/Localizable.strings; \
	done
	for f in English French; do \
	  iconv -f UTF-16LE -t UTF-8 \
	    < Bundles/OSS/$$f.lproj/Localizable.strings \
	    > $(d_app)$(GNUSTEP_SYSTEM_BUNDLES)/Cynthiune/OSS.output/Resources/$$f.lproj/Localizable.strings; \
	done

override_dh_makeshlibs:
# libCynthiune is installed as a private library; avoid lintian warnings.
	dh_makeshlibs --noscripts
