#!/usr/bin/make -f

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

export OPENAIS_BUILD=$(if $(findstring debug,$(DEB_BUILD_OPTIONS)),DEBUG)

configure-stamp:
	dh_autoreconf
	./configure --prefix=/usr \
		    --sysconfdir=/etc \
                    --libexecdir=/usr/lib/ \
		    --with-lcrso-dir=/usr/lib/lcrso
	touch $@

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	make
	touch $@

clean:
	dh_testdir
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_autoreconf_clean
	dh_clean configure-stamp build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp/
	chmod a-x debian/tmp/usr/lib/lcrso/*.lcrso
	dh_install --sourcedir=debian/tmp --list-missing
	dh_installdirs
	install -m 644 debian/ckpt-service `pwd`/debian/openais/etc/corosync/service.d/ckpt-service
	dh_installchangelogs CHANGELOG
	dh_installdocs
	dh_installexamples
	dh_strip --dbg-package=openais-dbg
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	strip --remove-section=.comment --remove-section=.note --strip-unneeded debian/openais/usr/lib/lcrso/*
endif
	dh_compress
	dh_fixperms
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: install

binary-indep:

binary: binary-arch binary-indep

