#!/usr/bin/make -f

DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

DESTDIR = $(CURDIR)/debian/tmp
BUILDDIR = $(CURDIR)/debian/build

# Decide whether to enable gtk-doc.
#
# It is enabled by default, but we disable it if the doc package is
# not going to be built, as is the case for a binary-arch build, or
# one for which the nodoc build profile is enabled.
#
# This helps with cross building, because gtk-doc doesn't really work
# in that scenario.
ENABLE_GTK_DOC = yes
ifeq (, $(filter libcattle-1.0-doc, $(shell dh_listpackages)))
    ENABLE_GTK_DOC = no
endif

%:
	dh $@ --with gir \
		  --builddir $(BUILDDIR)

# Refresh the build system.
#
# The build system is completely regenerated to ensure the tools used to
# build the binary package are the ones shipped with Debian.
#
# We need to intialize gtk-doc explicitly because autoreconf doesn't do
# that for us.
override_dh_autoreconf:
	gtkdocize
	dh_autoreconf

# Clean up the build system.
#
# Most files are handled for us automatically, but once again we have
# to take care of gtk-doc ourselves.
override_dh_autoreconf_clean:
	rm -f gtk-doc.*
	dh_autoreconf_clean

# Call configure.
#
# debhelper will take care of all the important stuff such as build
# architecture and installation paths, but we still need to explicitly
# pass a couple of parameters ourselves.
override_dh_auto_configure:
	dh_auto_configure -- \
	                  --enable-introspection=yes \
	                  --enable-gtk-doc=$(ENABLE_GTK_DOC)

# Prepare files.
#
# The upstream build system mostly does the right thing, but we still
# want to move some files around to make things easier for debhelper
# tools that are called later.
override_dh_auto_install:
	dh_auto_install --destdir $(DESTDIR)
	mv $(DESTDIR)/usr/share/doc/cattle-1.0/NEWS.rst \
	   $(DESTDIR)/usr/share/doc/cattle-1.0/NEWS

# Install documentation.
#
# debhelper's automatic detection results in the release notes for
# the -doc package ending up in a directory named after the -dev
# package, which is clearly not what we want, so we have to be a bit
# more hands-on here.
override_dh_installdocs:
	dh_installdocs -plibcattle-1.0-doc --doc-main-package libcattle-1.0-doc
	dh_installdocs -Nlibcattle-1.0-doc
