#!/usr/bin/make -f

# Add hardening build flags.  We have to omit PIE because it breaks the Perl
# module build (and probably the other interpretors as well).
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

# Link with --as-needed so that the remctl client library doesn't inherit
# the shared library dependencies of libremctl.
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# The additional flags to pass to Makefile.PL, picked up by the upstream
# build system.
export REMCTL_PERL_FLAGS := INSTALLDIRS=vendor

# The supported Python versions and the additional Python flags, picked up
# by the upstream build system.
export REMCTL_PYTHON_INSTALL  := --install-layout=deb
export REMCTL_PYTHON_VERSIONS := $(shell pyversions -s)

%:
	dh $@ --parallel --with python2,autoreconf

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure --parallel -- --sysconfdir=/etc/remctl \
	    --enable-reduced-depends --enable-perl --enable-php \
	    --enable-python --enable-ruby

# For the first pass, build the Ruby 1.8 extension.  We'll go back and build
# the extension for 1.9.1.
override_dh_auto_build:
	dh_auto_build --parallel -- REMCTL_RUBY=ruby1.8

override_dh_auto_test:
	dh_auto_test --parallel -- REMCTL_RUBY=ruby1.8

# After installing the build for the default version of Ruby, go back and
# rebuild for the newer version.
override_dh_auto_install:
	dh_auto_install -- RUBYARCHDIR='$$(vendorarchdir)$$(target_prefix)'
	cd ruby && $(MAKE) distclean
	dh_auto_build --parallel -- REMCTL_RUBY=ruby1.9.1
	cd ruby && $(MAKE) install DESTDIR='$(CURDIR)/debian/tmp' \
	    RUBYARCHDIR='$$(vendorarchdir)$$(target_prefix)'

# Override install to check for missing installed files.
override_dh_install:
	dh_install --fail-missing -Xlibremctl.la

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_makeshlibs:
	dh_makeshlibs -V 'libremctl1 (>= 3.1)'

override_dh_gencontrol:
	dh_gencontrol -- -V"php:Depends=phpapi-`php-config5 --phpapi`"
