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

SHELL := /bin/bash

include /usr/share/dpkg/buildflags.mk
include /usr/share/GNUstep/debian/config.mk
export GNUSTEP_MAKEFILES := $(GS_MAKE_DIR)
d_app := $(CURDIR)/debian/batmon.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
	$(MAKE) $(optim) CPPFLAGS="$(CPPFLAGS)" OBJCFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)" messages=yes
	convert Resources/BatMon_icon.tif -resize 32x32 batmon.xpm
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(MAKE) distclean
	dh_clean build-stamp batmon.xpm

install: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) install GNUSTEP_INSTALLATION_DOMAIN=SYSTEM DESTDIR=$(d_app)
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/batmon.app/Resources/{LICENSE,README}
	dh_install debian/*.desktop usr/share/applications/
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/batmon.app/Resources/*.desktop
	chmod -x $(d_app)$(GNUSTEP_SYSTEM_APPS)/batmon.app/Resources/*.tif
	dh_install batmon.xpm usr/share/pixmaps/

# 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 
	dh_installdocs
	dh_installmenu
	dh_installman debian/batmon.1
	gsdh_gnustep
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/batmon.app/Resources \
	  $(d_app)/usr/share/GNUstep/batmon.app
	dh_link usr/share/GNUstep/batmon.app \
	  $(GNUSTEP_SYSTEM_APPS)/batmon.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
