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

include /usr/share/dpkg/buildflags.mk
include /usr/share/GNUstep/debian/config.mk
export GNUSTEP_MAKEFILES := $(GS_MAKE_DIR)

d_app := $(CURDIR)/debian/agenda.app
LDFLAGS += -Wl,-z,defs -Wl,--as-needed

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

build: build-stamp

build-stamp:
	dh_testdir
	./configure LDFLAGS=
	$(MAKE) $(optim) CPPFLAGS="$(CPPFLAGS)" OBJCFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)" messages=yes
	convert Resources/Calendar.tiff -resize 32x32 SimpleAgenda.xpm
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(RM) build-stamp 
	[ ! -f local.make ] || $(MAKE) distclean
	dh_clean SimpleAgenda.xpm

install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) install DESTDIR=$(d_app) GNUSTEP_INSTALLATION_DOMAIN=SYSTEM
# Remove invalid .desktop file and install ours.
	rm $(d_app)/usr/lib/GNUstep/Applications/*.app/Resources/*.desktop
	install -D -m 644 debian/SimpleAgenda.desktop \
	  $(d_app)/usr/share/applications/SimpleAgenda.desktop
# Install the XPM icon.
	install -D -m 644 SimpleAgenda.xpm \
	  $(d_app)/usr/share/pixmaps/SimpleAgenda.xpm

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs NEWS TODO
	dh_installmenu
	dh_installman debian/SimpleAgenda.1
	gsdh_gnustep
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/SimpleAgenda.app/Resources \
	  $(d_app)/usr/share/GNUstep/SimpleAgenda.app
	dh_link usr/share/GNUstep/SimpleAgenda.app \
	  $(GNUSTEP_SYSTEM_APPS)/SimpleAgenda.app/Resources
	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
