#!/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

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

LDFLAGS += -Wl,--as-needed

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
optim := debug=yes
endif

%:
	dh $@

override_dh_auto_build:
	$(MAKE) $(optim) messages=yes CPPFLAGS="$(CPPFLAGS)" \
	  CFLAGS="$(CFLAGS)" OBJCFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	convert Icons/Cenon.tiff -resize 32x32 Cenon.xpm
# Construct something that resembles a ChangeLog.
	cd ChangeLog; for f in $$(ls -r *.txt); do cat $$f >> ChangeLog; done

override_dh_clean:
	dh_clean Cenon.xpm ChangeLog/ChangeLog

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog/ChangeLog

override_dh_link:
	dh_gnustep
	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}; do \
	  mv $$i $(d_app)$(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_app)$(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_app)$(usrshare)
	dh_link $(usrshare)/Cenon $(GNUSTEP_SYSTEM_LIBRARY)/Cenon
	rm $(d_app)$(usrshare)/Cenon/._*
