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

include /usr/share/GNUstep/debian/config.mk
include /usr/share/dpkg/buildflags.mk

SHELL := /bin/bash

export GNUSTEP_MAKEFILES := $(GS_MAKE_DIR)
d_app := $(CURDIR)/debian/projectcenter.app
LDFLAGS += -Wl,-z,defs -Wl,--as-needed -Wl,-rpath,/usr/lib/projectcenter.app

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 DO_LIB_LINK=yes GDB=/usr/bin/gdb
	convert Images/ProjectCenter.tiff -resize 32x32 ProjectCenter.xpm
	touch $@

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

install: build
	dh_testdir
	dh_testroot
	dh_prep
# Install the private library in /usr/lib/projectcenter.app.
	$(MAKE) install messages=yes DESTDIR=$(d_app) \
	  GNUSTEP_SYSTEM_LIBRARIES=/usr/lib/projectcenter.app \
	  GNUSTEP_INSTALLATION_DOMAIN=SYSTEM 
	dh_install debian/*.desktop usr/share/applications/
	rm $(d_app)$(GNUSTEP_SYSTEM_APPS)/*.app/Resources/*.desktop
	install -D -m 644 ProjectCenter.xpm \
	  $(d_app)/usr/share/pixmaps/ProjectCenter.xpm

# 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/ProjectCenter.1
	dh_installchangelogs ChangeLog
	gsdh_gnustep
# We cannot symlink Resources straight away because it contains
# arch-dependent executables.  Previous versions installed bundles in
# /usr/lib/GNUstep/Bundles/ProjectCenter, but as of 0.5.3 this is
# broken because the Preferences were split to dynamically load
# available modules, all of which reside in the app bundle's resources
# dir.  So we move only the images, to avoid lintian warnings.  It
# would be much more convoluted, complex, and fragile to move
# every arch-independent file/dir to /usr/share/GNUstep.
	dh_installdirs usr/share/GNUstep/ProjectCenter.app
	for i in \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/ProjectCenter.app/Resources/{,English.lproj/Info.gorm/}*.tiff; do \
	  mv $$i $(d_app)/usr/share/GNUstep/ProjectCenter.app/ \
	  && dh_link usr/share/GNUstep/ProjectCenter.app/`basename $$i` \
	    $(GNUSTEP_SYSTEM_APPS)/ProjectCenter.app/Resources/`basename $$i`; \
	done
	for i in \
	  $(d_app)$(GNUSTEP_SYSTEM_APPS)/ProjectCenter.app/Resources/ProjectCenter.{debugger,editor}/Resources/*.{png,tiff}; do \
	  mv $$i $(d_app)/usr/share/GNUstep/ProjectCenter.app/ \
	  && dh_link usr/share/GNUstep/ProjectCenter.app/`basename $$i` \
	    $(GNUSTEP_SYSTEM_APPS)/ProjectCenter.app/Resources/`basename $$i`; \
        done
	dh_link
	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
