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

export DH_VERBOSE=1
DESTDIR=$(CURDIR)/debian/tmp/
PERLVER=$(shell perl -e 'use Config; print $$Config{version}')
HTTPDCONF=$(shell if [ -d "/etc/apache2/conf-available" ]; then echo "/etc/apache2/conf-available"; else echo "/etc/apache2/conf.d"; fi )
SHELL=bash
export PERL5LIB=/usr/lib/thruk/perl5:/usr/lib64/thruk/perl5

override_dh_auto_configure:
	dh_auto_configure -- --prefix=/usr \
		--bindir="/usr/bin" \
		--datadir="/usr/share/thruk" \
		--libdir="/usr/lib/thruk" \
		--localstatedir="/var/lib/thruk" \
		--with-tempdir="/var/cache/thruk" \
		--sysconfdir="/etc/thruk" \
		--mandir="/usr/share/man" \
		--with-initdir="/etc/init.d" \
		--with-logdir="/var/log/thruk" \
		--with-logrotatedir="/etc/logrotate.d" \
		--with-bashcompletedir="/etc/bash_completion.d" \
		--with-thruk-user="www-data" \
		--with-thruk-group="www-data" \
		--with-thruk-libs="/usr/lib/thruk/perl5" \
		--with-httpd-conf="$(HTTPDCONF)" \
		--with-htmlurl="/thruk"
	echo $(HTTPDCONF)/thruk.conf                   >> debian/thruk-base.install
	echo $(HTTPDCONF)/thruk_cookie_auth_vhost.conf >> debian/thruk-base.install
	# make sure themes are built as this point
	test -f themes/themes-available/Light/stylesheets/Light.css || make themes
	test -f themes/themes-available/Light/stylesheets/Light.css || exit 1

override_dh_auto_install: local_auto_install

local_auto_install:
	dh_auto_install
	# enable su logrotate, available since ubuntu 13.04 and debian 6
	sed -i -e 's/^.*#su/    su/' debian/tmp/etc/logrotate.d/thruk-base
	test -f debian/tmp/usr/share/thruk/root/thruk/cache/thruk-panorama-*.js || exit 1

override_dh_gencontrol:
	dh_gencontrol -- -Vextra:Depends=perlapi-$(PERLVER)

override_dh_strip:
	dh_strip

override_dh_auto_test:

%:
	dh $@
