#!/usr/bin/make -f
SHELL+= -e

#export DH_VERBOSE=1

include debian/scripts/vars

BUILD_DIR := $(SOURCE_DIR)
B := $(BUILD_DIR)
D := $(CURDIR)/debian/tmp

DOCS := FAQ README TODO

all: build

unpack: $(STAMP_DIR)/unpack
$(STAMP_DIR)/unpack:
	$(MAKE) -f debian/sys-build.mk source.make
	touch $@

# used by the maintainer
unpack.nopatch:
	$(MAKE) -f debian/sys-build.mk source.build

# used by the maintainer
diff:
	$(MAKE) -f debian/sys-build.mk make-diff

clean:
	$(MAKE) -f debian/sys-build.mk source.clean
	$(MAKE) clean
	dh_clean


build: $(STAMP_DIR)/build
$(STAMP_DIR)/build: $(STAMP_DIR)/unpack
	dh_testdir
	NOISY=1 \
	$(MAKE) -f debian/sys-build.mk source.command SOURCE_CMD=" \
		$(MAKE) $(MAKE_VARIABLES) all \
	"
	touch $@

binary-arch: $(STAMP_DIR)/build checkroot
	dh_testdir
	dh_clean -k
	dh_installdirs

	cp $B/multipath/multipath $B/devmap_name/devmap_name \
		$B/kpartx/kpartx \
		$D/sbin/
	cp $B/multipathd/multipathd $D/usr/bin/

	install --mode=755 $B/multipath/multipath.dev \
		$D/etc/dev.d/block/

	dh_installchangelogs $B/ChangeLog
	dh_installdocs $(addprefix $B/,$(DOCS))
	dh_installexamples $B/multipath.conf.annotated
	dh_installexamples $B/multipath.conf.synthetic
	dh_installman $B/*/*.8
	dh_installinit --no-start --update-rcd-params='start 04 S .'

	dh_strip
	dh_compress
	dh_fixperms
	dh_shlibdeps
	dh_installdebconf
	dh_installdeb
	dh_gencontrol
	dh_builddeb


binary:	binary-arch

checkroot:
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep unpack configure build clean checkroot
