#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# All libraries are installed in a subdirectory as per Policy 10.2.
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--no-undefined \
				  -Wl,-rpath,/usr/lib/gworkspace
d_app := $(CURDIR)/debian/tmp
include /usr/share/GNUstep/debian/config.mk

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
	  --enable-gwmetadata \
	  --with-sh=/bin/sh \
	  --with-unzip=unzip

override_dh_auto_build:
	dh_auto_build -- $(optim) \
	  $(verbose) \
	  $(shell dpkg-buildflags --export=cmdline)

override_dh_auto_install:
# Cheat gnustep-make to install all libraries as private.
	dh_auto_install -- install \
	  GNUSTEP_SYSTEM_LIBRARIES=/usr/lib/gworkspace \
	  DESTDIR=$(d_app)
# Convert app icons to PNG format in order to avoid AppStream errors.
	convert GWorkspace/Resources/Icons/FileManager.tiff -resize 64x64 \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/GWorkspace.app/Resources/FileManager.png
	convert \
	  GWMetadata/MDFinder/Resources/Images/MDFinder.tiff -resize 64x64 \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/MDFinder.app/Resources/MDFinder.png
# Delete auto-generated *.desktop files.
	find $(d_app) -name "*.desktop" -delete

override_dh_installman:
	dh_installman
# Create symlinks for the manpages.  Deliberately do not derive the
# programs' list from /usr/bin -- if a tool is added upstream; the
# manpage has to be updated.
	for p in ddbd fswatcher lsfupdater searchtool wopen Recycler; do \
	  dh_link -pgworkspace.app \
	    usr/share/man/man1/GWorkspace.1 usr/share/man/man1/$$p.1; \
	done
	for p in gmds mdextractor; do \
	  dh_link -pmdfinder.app usr/share/man/man1/MDFinder.1 \
	    usr/share/man/man1/$$p.1; \
	done

override_dh_missing:
# Reminder to update .install/.links when a new extractor/inspector or
# a new tool is added.
	dh_missing -Xstamp.make --list-missing

override_dh_makeshlibs:
# Avoid lintian warnings for private libraries in /usr/lib/gworkspace.
	dh_makeshlibs -n
