#! /usr/bin/make -f
#
# debian/rules
# Part of Debian ‘inform’ package.
#
# Copyright © 2015 Ben Finney <ben+debian@benfinney.id.au>
# Copyright © 2008 Jan Christoph Nordholz <hesso@pool.math.tu-berlin.de>
#
# This is free software; you may copy, modify, and/or distribute this
# work under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 of that License or later.
# No warranty expressed or implied.
# See the file '/usr/share/common-licenses/GPL-3' for details.

SOURCE_DIR = inform-6.31.1

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

.PHONY: clean
clean:
	dh_testdir
	dh_testroot
	$(RM) ${GENERATED_FILES}
	$(RM) ${SOURCE_DIR}/config/config.guess
	$(RM) ${SOURCE_DIR}/config/config.sub
	[ ! -f ${SOURCE_DIR}/Makefile ] || $(MAKE) -C ${SOURCE_DIR}/ maintainer-clean
	dh_autoreconf_clean
	dh_clean

.PHONY: autoreconf
autoreconf: autoreconf.stamp

GENERATED_FILES += autoreconf.stamp
autoreconf.stamp:
	autoreconf -f -i ${SOURCE_DIR}/
	touch "$@"

.PHONY: build
build: build-arch build-indep

.PHONY: build-arch
build-arch: build.stamp
.PHONY: build-indep
build-indep: build.stamp

GENERATED_FILES += build.stamp
build.stamp:
	dh_testdir
	dh_autoreconf $(firstword ${MAKEFILE_LIST}) -- autoreconf
	cd ${SOURCE_DIR}/ && ./configure --prefix=/usr
	$(MAKE) -C ${SOURCE_DIR}/
	touch "$@"

.PHONY: binary
binary: binary-arch binary-indep

.PHONY: binary-indep
binary-indep:
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installchangelogs
	dh_fixperms
	dh_strip
	dh_link
	dh_compress
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

.PHONY: binary-arch
binary-arch: build
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installchangelogs ${SOURCE_DIR}/NEWS
	dh_installexamples
	dh_installman
	dh_fixperms
	dh_strip
	dh_link
	dh_compress
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb


.PHONY: get-packaged-orig-source
get-packaged-orig-source:
	$(uscan-download-source) --download-current-version

# Policy §4.9 strongly recommends the ‘get-orig-source’ target:
# “This target is optional, but providing it if possible is a good idea.”
#
# This target is an anomaly: per Policy §4.9, it fetches the *latest*
# upstream source, regardless of this package's version. To fetch the
# upstream source corresponding to this package's *declared* version
# in ‘debian/changelog’, use ‘get-packaged-orig-source’ instead.
.PHONY: get-orig-source
get-orig-source:
	$(uscan-download-source)

get-orig-source get-packaged-orig-source: http_proxy =
get-orig-source get-packaged-orig-source: makefile_dir = $(abspath $(dir $(firstword ${MAKEFILE_LIST})))
get-orig-source get-packaged-orig-source: package_dir = $(abspath $(dir ${makefile_dir}))

define uscan-download-source
	uscan --noconf --verbose \
	    --force-download \
	    --rename \
	    --destdir=$(CURDIR) \
	    --check-dirname-level=0 ${package_dir}
endef # uscan-download-source


# Local variables:
# mode: makefile
# coding: utf-8
# End:
# vim: filetype=make fileencoding=utf-8 :
