#!/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/terminal.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 Terminal.tiff -resize 32x32 Terminal.xpm
	touch $@

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

install: build
	dh_testdir
	dh_testroot
	dh_prep
	$(MAKE) install DESTDIR=$(d_app) GNUSTEP_INSTALLATION_DOMAIN=SYSTEM
	dh_install debian/Terminal.desktop usr/share/applications/
	dh_install Terminal.xpm usr/share/pixmaps/
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/Terminal.app/Resources/Terminal.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_installdocs
	dh_installmenu
	dh_installman debian/Terminal.1
	dh_installchangelogs
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/Terminal.app/Resources \
	  $(d_app)/usr/share/GNUstep/Terminal.app
	dh_link usr/share/GNUstep/Terminal.app \
	  $(GNUSTEP_SYSTEM_APPS)/Terminal.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
