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

SHELL := /bin/bash

include /usr/share/GNUstep/debian/config.mk
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

d_app    := $(CURDIR)/debian/tmp
d_com    := $(CURDIR)/debian/cenon.app-common
resdir   := $(GNUSTEP_SYSTEM_APPS)/Cenon.app/Resources
usrshare := /usr/share/GNUstep/Cenon.app

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- $(optim) messages=yes \
	  $(shell dpkg-buildflags --export=cmdline)
# Construct something that resembles a ChangeLog.
	cd ChangeLog; for f in $$(ls -r *.txt); do cat $$f >> ChangeLog; done

override_dh_clean:
	dh_clean ChangeLog/ChangeLog

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog/ChangeLog

override_dh_link-indep:
	dh_installdirs $(usrshare)
	rm $(d_app)$(resdir)/{*.desktop,InspectorPanel.nib/._*}
# The Resources directory of the main app bundle contains
# arch-dependent files, so it can't be moved as usual.
	for i in $(d_app)$(resdir)/*.{tiff,lproj,nib,xib,plist,prolog,trailer}; do \
	  mv $$i $(d_com)$(usrshare) \
	  && dh_link $(usrshare)/$${i##*/} $(resdir)/$${i##*/}; \
	done
	for i in CharConversion CropMarks ; do \
	  mv $(d_app)$(resdir)/$$i $(d_com)$(usrshare) \
	  && dh_link $(usrshare)/$$i $(resdir)/$$i; \
	done
# Now move the Resources of the arch-dependent modules.
	for i in $(d_app)$(resdir)/*.prefs; do \
	  mv $$i/Resources $(d_com)$(usrshare)/$${i##*/} \
	  && dh_link $(usrshare)/$${i##*/} $(resdir)/$${i##*/}/Resources; \
	done
# Finally, move the whole Cenon Library -- it is entirely
# arch-independent, as misleading that is.
	mv $(d_app)$(GNUSTEP_SYSTEM_LIBRARY)/Cenon $(d_com)$(usrshare)
	dh_link $(usrshare)/Cenon $(GNUSTEP_SYSTEM_LIBRARY)/Cenon
	rm $(d_com)$(usrshare)/Cenon/._*
