#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

soname=3
soversion=3.6
changelog=README.36
HISTORY=debian/HISTORY
CONFIGS   = config.guess config.sub
CONFIGTGZ = config.tar.gz

rexxpkg=regina-rexx

export DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
export DEB_BUILD_ARCH     ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

ifeq ($(DEB_BUILD_ARCH), ia64)
	DEB_CFLAGS_MAINT_STRIP=""
endif

# Get default build flags for maximum hardening (Needs dpkg-dev >= 1.16.1.1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

confflags=--prefix=/usr \
	--with-addon-dir=/usr/lib/$(DEB_HOST_MULTIARCH)/$(rexxpkg)/$(soversion) \
	--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

# Enable Regina GCI only on supported platforms.
ifneq ($(filter alpha amd64 i386,$(DEB_HOST_ARCH)), )
  confflags+=--enable-gci
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Preserve old config files and replace them by recent ones.
	[ -e "$(CONFIGTGZ)" ] || tar -cvzf $(CONFIGTGZ) $(addprefix common/,$(CONFIGS))
	for i in $(CONFIGS); do cp -f /usr/share/misc/$$i common/$$i; done
	# Add here commands to configure the package.
	./configure $(confflags)
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) CFLAGS="$(CFLAGS) $(CPPFLAGS)" LDFLAGS="$(LDFLAGS)"
	#docbook-to-man debian/pam-encfs.sgml > pam-encfs.1
	cat README.0* README.2* README.3* > $(HISTORY)

	touch build-stamp

clean:
	dh_testdir

	# Add here commands to clean up after the build process.
	rm -f build-stamp configure-stamp
	if [ -e "$(CONFIGTGZ)" ]; then \
	tar -xvzf $(CONFIGTGZ) && rm $(CONFIGTGZ); fi
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f $(HISTORY)

	dh_clean

install: build
	dh_testdir
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install-lib DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) install-dev DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) install-rexx DESTDIR=$(CURDIR)/debian/tmp

# 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 -A $(HISTORY)
	dh_install
	dh_installman
	dh_installexamples
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure patch \
	unpatch
