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

include /usr/share/GNUstep/debian/config.mk

export GNUSTEP_MAKEFILES := $(GS_MAKE_DIR)
d_app := $(CURDIR)/debian/dictionaryreader.app

# Make sure there are no undefined symbols and avoid unnecessary
# dependencies.
LDFLAGS := -Wl,-z,defs -Wl,--as-needed

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

build: build-stamp

build-stamp:
	dh_testdir
	$(MAKE) -C Etoile/Services/User/DictionaryReader $(optim) \
	  LDFLAGS="$(LDFLAGS)" messages=yes
	convert Etoile/Services/User/DictionaryReader/Resources/dict.png \
	  -resize 32x32 DictionaryReader.xpm
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(MAKE) -C Etoile/Services/User/DictionaryReader distclean
	dh_clean build-stamp DictionaryReader.xpm

install: build
	dh_testdir
	dh_testroot
	dh_prep
	cd Etoile/Services/User/DictionaryReader ; \
	  $(MAKE) install DESTDIR=$(d_app) GNUSTEP_INSTALLATION_DOMAIN=SYSTEM

# Remove invalid .desktop file and install ours.
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/*.app/Resources/*.desktop
	install -D -m 644 debian/DictionaryReader.desktop \
	  $(d_app)/usr/share/applications/DictionaryReader.desktop
# Install the XPM icon.
	install -D -m 644 DictionaryReader.xpm \
	  $(d_app)/usr/share/pixmaps/DictionaryReader.xpm

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs Etoile/ChangeLog
	dh_installdocs
	dh_installmenu
	dh_installman debian/DictionaryReader.1
	gsdh_gnustep
ifeq ($(GS_USE_FHS),yes)
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/DictionaryReader.app/Resources \
	  $(d_app)/usr/share/GNUstep/DictionaryReader.app
	dh_link usr/share/GNUstep/DictionaryReader.app \
	  $(GNUSTEP_SYSTEM_APPS)/DictionaryReader.app/Resources
endif
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
