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

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

# shorewall version
export VFULL=`grep "^VERSION=" install.sh | head -n 1 | cut -f 2 -d "="`
export V=`grep "^VERSION=" install.sh | head -n 1 | cut -f 2 -d "=" | cut -f 1-3 -d "."`
VMAJOR:=$(shell echo $(V) |cut -f 1 -d .)
VMINOR:=$(shell echo $(V) |cut -f 2 -d .)
VPATCH:=$(shell echo $(V) |cut -f 3 -d .)
NEXTPATCH:=$(shell expr $(VPATCH) + 1 2>/dev/null || expr `echo $(VPATCH) | cut -f 1 -d - ` + 1)

SRWL=$(CURDIR)/debian/shorewall6

%:
	dh $@ 

debian/po/templates.pot: debian/shorewall6.templates
	@debconf-updatepo

override_dh_auto_configure:
	./configure

override_dh_auto_build:
	true

override_dh_auto_clean:
	rm -rf $(SRWL) shorewallrc

override_dh_install:
	echo 'shorewall:current=$(VMAJOR).$(VMINOR).$(VPATCH)~' \
		>> debian/shorewall6.substvars
	echo 'shorewall:next=$(VMAJOR).$(VMINOR).$(NEXTPATCH)~' \
		>> debian/shorewall6.substvars
	DESTDIR=$(SRWL) MANDIR=man BUILD=debian HOST=debian $(CURDIR)/install.sh
	rmdir $(SRWL)/usr/share/shorewall/Shorewall
	rmdir $(SRWL)/usr/share/shorewall

override_dh_fixperms:
	# Temporary zones are only available to root
	chmod 750 $(SRWL)/var/lib/shorewall6
	# By default, configuration is not world-readable
	chmod 640 $(SRWL)/etc/shorewall6/*
	# These should not be executable
	chmod 644 $(SRWL)/etc/shorewall6/shorewall6.conf
	chmod 644 $(SRWL)/etc/shorewall6/Makefile
	# Global configuration has to be fully readable
	chmod 644 $(SRWL)/usr/share/shorewall6/*
	chmod 755 $(SRWL)/usr/share/shorewall6/configfiles/
	dh_fixperms -Xetc/shorewall6 -Xvar/lib/shorewall6

override_dh_compress:
	dh_compress

override_dh_installinit:
	dh_installinit --onlyscripts --no-start -u"start 40 S . stop 89 0 6 ."

override_dh_installman:
	dh_installman manpages/*

override_dh_installlogrotate:
	dh_installlogrotate -pshorewall6 --name=shorewall6

