#!/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/viewpdf.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) messages=yes CPPFLAGS="$(CPPFLAGS)" \
	  OBJCFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	touch $@

clean:
	dh_testdir
	dh_testroot
	$(MAKE) clean
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) install GNUSTEP_INSTALLATION_DOMAIN=SYSTEM DESTDIR=$(d_app)
	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
	dh_installdocs
	dh_installmenu
	dh_installman
	gsdh_gnustep
	dh_installdirs usr/share/GNUstep
	mv $(d_app)$(GNUSTEP_SYSTEM_APPS)/ViewPDF.app/Resources \
	  $(d_app)/usr/share/GNUstep/ViewPDF.app
	dh_link usr/share/GNUstep/ViewPDF.app \
	  $(GNUSTEP_SYSTEM_APPS)/ViewPDF.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
