#!/usr/bin/make -f
# -*- makefile -*-

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

# debian/rules file for the Debian GNU/Linux stunnel package
# Copyright 2003 by Julien LEMOINE <speedblue@debian.org>
# Copyright 2014 by Peter Pentchev <roam@ringlet.net>

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND=-Wall

multiarch_path=	$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_auto_configure -- \
	  --enable-ipv6 --with-threads=pthread

override_dh_auto_install:
	dh_auto_install -- -C src
	dh_auto_install -- -C doc

	# .la file is useless
	rm $(CURDIR)/debian/stunnel4/usr/lib/$(multiarch_path)/stunnel/libstunnel.la

	ln doc/stunnel.8 doc/stunnel4.8
	ln doc/stunnel.pl.8 doc/stunnel4.pl.8

	# Manpages will be installed by dh_installman
	rm -rf $(CURDIR)/debian/stunnel4/usr/share/man

	# Rename binary
	mv $(CURDIR)/debian/stunnel4/usr/bin/stunnel 			\
	  $(CURDIR)/debian/stunnel4/usr/bin/stunnel4

	# Move docs into proper dir
	mv $(CURDIR)/debian/stunnel4/usr/share/doc/stunnel		\
	  $(CURDIR)/debian/stunnel4/usr/share/doc/stunnel4

	# Copy sample init script into place for dh_installinit
	cp $(CURDIR)/tools/stunnel.init $(CURDIR)/debian/stunnel4.init

	# Basic docs for the user on how to create an initial configuration
	install -p -m 0644 $(CURDIR)/debian/stunnel4.conf.README \
	  $(CURDIR)/debian/stunnel4/etc/stunnel/README

override_dh_installinit:
	dh_installinit --restart-after-upgrade

override_dh_installppp:
	dh_installppp --name=0stunnel4

override_dh_compress:
	dh_compress --exclude=StunnelConf-0.1.pl

%:
	dh $@
