#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# Get the hardening build flags and enable all compiler warnings:
CFLAGS   := $(shell dpkg-buildflags --get CFLAGS) -Wall
CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) -Wall
CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS  := $(shell dpkg-buildflags --get LDFLAGS)

CONFIG := CFLAGS="$(CFLAGS) $(CPPFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
	--enable-ssl-tunnel

ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
	CONFIG += --disable-locking
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIG)

override_dh_auto_build-arch:
	dh_auto_build -a
	docbook-to-man debian/havp.sgml > havp.1

override_dh_auto_clean:
	debconf-updatepo
	dh_auto_clean

override_dh_install:
	dh_install -a

	# clean up to make lintian shut up...
	rm -r $(CURDIR)/debian/havp/var/tmp $(CURDIR)/debian/havp/var/run
	chmod -x $(CURDIR)/debian/havp/etc/havp/templates/*/*.html

override_dh_installinit:
	dh_installinit --error-handler=init_error

override_dh_installman:
	dh_installman havp.1