#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

PKG_VERSION=$(shell dpkg-parsechangelog | awk '/^Version:/ { print $$2 }')

%:
	dh $@ --with bash-completion

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/drbd-utils.drbd.init

override_dh_auto_configure:
	./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc \
		--sbindir=/sbin --with-utils --with-udev --with-xen \
		--with-pacemaker --with-rgmanager --with-bashcompletion \
		--with-initscripttype=sysv \
		--with-bashcompletion=no

override_dh_auto_build:
	dh_auto_build
	$(MAKE) doc

override_dh_auto_install:
	dh_auto_install --destdir debian/drbd-utils
	# Shipped with dh_installman, upstream creates a dangling symlink
	rm debian/drbd-utils/usr/share/man/man8/drbd-overview.8

override_dh_install:
	dh_install --fail-missing

	# Move drbd-overview to /usr/sbin
	mv $(CURDIR)/debian/drbd-utils/sbin/drbd-overview $(CURDIR)/debian/drbd-utils/usr/sbin/

	# Place the initscript where dh_installinit can find it
	mv $(CURDIR)/debian/drbd-utils/etc/init.d/drbd $(CURDIR)/debian/drbd-utils.drbd.init

	# systemd/kmod integration
	install -D -m0644 $(CURDIR)/debian/drbd.modules-load.d $(CURDIR)/debian/drbd-utils/lib/modules-load.d/drbd.conf


override_dh_installinit:
	dh_installinit --name=drbd --no-start

override_dh_gencontrol:
	dh_gencontrol -Ndrbd8-utils
	# Add the previous epoch to drbd8-utils
	dh_gencontrol -pdrbd8-utils -- -v2:$(PKG_VERSION)

.PHONY: override_dh_auto_configure override_dh_install \
	override_dh_auto_clean override_dh_installinit \
	override_dh_gencontrol override_dh_auto_install \
	override_dh_auto_build
