#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#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/cynthiune.app

LDFLAGS += -Wl,-z,defs -Wl,--as-needed -Wl,-rpath,/usr/lib/cynthiune.app

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

build: build-stamp

build-stamp:
	dh_testdir
	$(MAKE) messages=yes $(optim) CPPFLAGS="$(CPPFLAGS)" \
	  ADDITIONAL_CFLAGS="$(CFLAGS)" CCFLAGS="$(CXXFLAGS)" \
	  OBJCFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" disable-arts=yes
	convert Images/Cynthiune.tiff -resize 32x32 Cynthiune.xpm
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(MAKE) distclean
	dh_clean Cynthiune.xpm

install: build
	dh_testdir
	dh_testroot
	dh_prep
# Cheat GNUstep Make to create the symlinks for the Cynthiune library
# in /usr/lib/cynthiune.app.
	dh_installdirs usr/lib/cynthiune.app
	$(MAKE) install disable-arts=yes GNUSTEP_INSTALLATION_DOMAIN=SYSTEM \
	  GNUSTEP_SYSTEM_LIBRARIES=/usr/lib/cynthiune.app DESTDIR=$(d_app)
	rm $(d_app)/usr/lib/GNUstep/Applications/Cynthiune.app/Resources/COPYING
	dh_install Cynthiune.xpm usr/share/pixmaps/
	dh_install debian/*.desktop usr/share/applications/
	rm $(d_app)/usr/lib/GNUstep/Applications/*.app/Resources/*.desktop

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installmenu
	dh_installman
	dh_link
	gsdh_gnustep
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/Cynthiune.app/Resources \
	  $(d_app)/usr/share/GNUstep/Cynthiune.app
	dh_link usr/share/GNUstep/Cynthiune.app \
	  $(GNUSTEP_SYSTEM_APPS)/Cynthiune.app/Resources
	dh_lintian
	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
