#!/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/grr.app

LDFLAGS += -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/Icons/Application/Grr-Icon.tiff -resize 32x32 Grr.xpm
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(MAKE) distclean
	dh_clean Grr.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/Grr.desktop \
	  $(d_app)/usr/share/applications/Grr.desktop
# Install the XPM icon.
	install -D -m 644 Grr.xpm $(d_app)/usr/share/pixmaps/Grr.xpm

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installchangelogs ChangeLog 
	dh_installdocs
	dh_installmenu
	dh_installman 
	gsdh_gnustep
	dh_installdirs usr/share/GNUstep/Grr.app
# Move only the images as Resources contains arch-dependent plugins.
	for i in \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/Grr.app/Resources/{,Fonts.grrc/Resources/}*.tiff; do \
	  mv $$i $(d_app)/usr/share/GNUstep/Grr.app \
	  && dh_link usr/share/GNUstep/Grr.app/`basename $$i` \
	    $(GNUSTEP_SYSTEM_APPS)/Grr.app/Resources/`basename $$i`; \
	done
	for i in \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/Grr.app/Resources/ArticleView.grrc/Resources/{English,German}.lproj/ArticleTextViewPlugin.gorm/bluebg.png; do \
	  mv $$i $(d_app)/usr/share/GNUstep/Grr.app \
	  && dh_link usr/share/GNUstep/Grr.app/`basename $$i` \
	    $(GNUSTEP_SYSTEM_APPS)/Grr.app/Resources/`basename $$i`; \
	done
	chmod -x $(d_app)/usr/share/GNUstep/Grr.app/{FeedFetching,Fonts}.tiff
	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 
