#!/usr/bin/make -f
# -*- makefile -*-
#
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# This has to be exported to make some magic below work.
DH_OPTIONS = -v

DAEMON_USER = bareos
DAEMON_GROUP = bareos
DIRECTOR_DAEMON_USER = $(DAEMON_USER)
STORAGE_DAEMON_USER = $(DAEMON_USER)
FILE_DAEMON_USER = root
STORAGE_DAEMON_GROUP = $(DAEMON_GROUP)
WORKING_DIR = /var/lib/bareos

define CONFIGURE_COMMON
  --with-sbin-perm=755 \
  --libdir=/usr/lib/bareos \
  --sysconfdir=/etc/bareos \
  --with-archivedir=/var/lib/bareos/storage \
  --with-backenddir=/usr/lib/bareos/backends \
  --with-scriptdir=/usr/lib/bareos/scripts \
  --with-plugindir=/usr/lib/bareos/plugins \
  --with-working-dir=/var/lib/bareos \
  --with-pid-dir=/var/lib/bareos \
  --with-bsrdir=/var/lib/bareos \
  --with-logdir=/var/log/bareos \
  --with-subsys-dir=/var/lock \
  --enable-smartalloc \
  --disable-conio \
  --enable-readline \
  --enable-batch-insert \
  --enable-dynamic-cats-backends \
  --enable-dynamic-storage-backends \
  --enable-acl \
  --enable-xattr \
  --enable-scsi-crypto \
  --enable-lmdb \
  --enable-ndmp \
  --enable-ipv6 \
  --with-postgresql \
  --with-mysql \
  --with-sqlite3 \
  --with-tcp-wrappers \
  --without-openssl \
  --with-gnutls \
  --with-dir-user=$(DIRECTOR_DAEMON_USER) \
  --with-dir-group=$(DAEMON_GROUP) \
  --with-sd-user=$(STORAGE_DAEMON_USER) \
  --with-sd-group=$(STORAGE_DAEMON_GROUP) \
  --with-fd-user=$(FILE_DAEMON_USER) \
  --with-fd-group=$(DAEMON_GROUP) \
  --with-dir-password="XXX_REPLACE_WITH_DIRECTOR_PASSWORD_XXX" \
  --with-fd-password="XXX_REPLACE_WITH_CLIENT_PASSWORD_XXX" \
  --with-sd-password="XXX_REPLACE_WITH_STORAGE_PASSWORD_XXX" \
  --with-mon-dir-password="XXX_REPLACE_WITH_DIRECTOR_MONITOR_PASSWORD_XXX" \
  --with-mon-fd-password="XXX_REPLACE_WITH_CLIENT_MONITOR_PASSWORD_XXX" \
  --with-mon-sd-password="XXX_REPLACE_WITH_STORAGE_MONITOR_PASSWORD_XXX" \
  --with-basename="XXX_REPLACE_WITH_LOCAL_HOSTNAME_XXX" \
  --with-hostname="XXX_REPLACE_WITH_LOCAL_HOSTNAME_XXX" \
  --enable-includes \
  --disable-rpath
endef

#  --docdir="\$(_docdir)/bareos" \
#  --htmldir="\$(_docdir)/bareos/html" \

CONFIGURE_CLIENT_ONLY = $(CONFIGURE_COMMON) --enable-client-only
CONFIGURE_FULL        = $(CONFIGURE_COMMON) --with-python --enable-bat --enable-traymonitor

override_dh_auto_configure:
	if [ "`lsb_release --short  --id`" = "Ubuntu" ] && [ "`lsb_release --short  --release`" = "8.04" ]; then \
		echo "configure common configuration"; \
		dh_auto_configure -- $(CONFIGURE_COMMON); \
	else \
		echo "configure full configuration"; \
		dh_auto_configure -- $(CONFIGURE_FULL); \
	fi

override_dh_fixperms:
	# all files in /etc/bareos
	dh_fixperms \
		--exclude etc/bareos/ \
		--exclude var/lib/bareos/ \
		--exclude var/log/bareos/

override_dh_strip:
	dh_strip --dbg-package=bareos-dbg

override_dh_install:
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/bareos/backends/libbareoscats-mysql* \
		$(CURDIR)/debian/tmp/usr/lib/bareos/backends/libbareoscats-postgresql* \
		$(CURDIR)/debian/tmp/usr/lib/bareos/backends/libbareoscats-sqlite3*
	dh_install

override_dh_installinit:
	dh_installinit --package=bareos-director   --name=bareos-dir --no-start
	dh_installinit --package=bareos-storage    --name=bareos-sd  --no-start
	dh_installinit --package=bareos-filedaemon --name=bareos-fd

override_dh_makeshlibs:
	dh_makeshlibs -n

%:
	PARALLEL="--parallel"; \
	if [ "`lsb_release --short  --id`" = "Ubuntu" ] && [ "`lsb_release --short  --release`" = "8.04" ]; then PARALLEL=""; fi; \
	dh $@ $$PARALLEL

gen-debian-copyright:
	(cd debian; make copyright)
