#!/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 Build.PL, picked up by the upstream build
# system.
export REMCTL_PERL_FLAGS := --installdirs vendor --create_packlist 0

# 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,ruby

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure --parallel -- --sysconfdir=/etc/remctl	\
	    --with-systemdsystemunitdir=/lib/systemd/system		\
	    --enable-reduced-depends --enable-perl --enable-php		\
	    --enable-python --enable-ruby

# Override install to check for missing installed files.  Ignore the Ruby
# module installed in usr/local/lib by the upstream build system.  Run
# dh_ruby --install to build and install the module for each supported Ruby
# version.
override_dh_install:
	dh_install --fail-missing -Xlibremctl.la -Xusr/local/lib
	dh_ruby --install

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`"
