#!/usr/bin/make -f
#export DH_VERBOSE = 1

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

%:
	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 -- GNUSTEP_SYSTEM_LIBRARIES=$(private_dir)
# Reinstall the Inspector framework to ship it as public library.
	$(RM) $(d_app)$(private_dir)/libInspector*
	dh_auto_install -- -C Inspector
# 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

execute_before_dh_link:
	gsdh_gnustep --no-move

override_dh_makeshlibs:
# Avoid lintian warnings for private libraries.
	dh_makeshlibs -pgworkspace-libs --no-scripts
	dh_makeshlibs --remaining-packages
