#!/usr/bin/make -f

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

export DEB_CFLAGS_MAINT_APPEND  := -Wall
export DEB_BUILD_MAINT_OPTIONS	:= hardening=+bindnow

DESTDIR=$(CURDIR)/debian/tmp

conf_args = \
		--localstatedir=/var/lib \
		--with-logdir=/var/log/ctdb

%:
	dh $@

override_dh_auto_configure: check-external-libs
	dh_auto_configure -- $(conf_args)

override_dh_auto_test:
	# skipping tests

override_dh_auto_install:
	dh_auto_install
	mkdir -p $(DESTDIR)/etc/default
	install -m644 config/ctdb.sysconfig $(DESTDIR)/etc/default/ctdb

override_dh_installdocs:
	dh_installdocs
ifeq ($(DEB_BUILD_ARCH_OS), hurd)
	dh_installdocs debian/README.hurd
endif
	#patch doc
	sed -i 's|/etc/sysconfig/|/etc/default/|' $(CURDIR)/debian/ctdb/usr/share/doc/ctdb/web/*.html
	#upstream changelog 
	grep -A 10000 '%changelog' packaging/RPM/ctdb.spec.in > $(CURDIR)/debian/ctdb/usr/share/doc/ctdb/changelog

override_dh_installinit:
	#install init script
	dh_installinit -pctdb --no-start --no-restart-on-upgrade

override_dh_strip:
	dh_strip --dbg-package=ctdb-dbg

check-external-libs:
	if [ -e lib/popt ]; then \
              echo " *****************************************"; \
	      echo " **                                     **"; \
	      echo " **  tar contains external libraries!   **"; \
	      echo " **                                     **"; \
              echo " *****************************************"; \
	      echo "The tarball should be made by using uscan or"; \
	      echo "debian/uupdate-wrapper"; \
	      echo ""; \
	      exit 1; \
        fi

