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

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall

export OPTFLAGS =-DDISCOVERY_FILE=\"/var/lib/open-iscsi/discovery\" -DNODE_FILE=\"/var/lib/open-iscsi/node\"

%:
	dh $@ --with autotools_dev,autoreconf

DEB_UPSTREAM_VERSION := $(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p')

get-orig-source:
	uscan --force-download --rename --repack --download-version=$(DEB_UPSTREAM_VERSION) --destdir=.

override_dh_auto_build:
	$(MAKE) -C utils/fwparam_ibft
	$(MAKE) user
	$(MAKE) -C utils

override_dh_auto_clean:
	$(MAKE) -C utils/fwparam_ibft clean
	$(MAKE) -C usr clean
	$(MAKE) -C utils clean
	rm -rf modules

override_dh_auto_install:
	@# do nothing, we install stuff with dh_install etc.

override_dh_fixperms:
	dh_fixperms
	@# That configuration file might contain authentication data, so
	@# don't make it world-readable. See bug #735773 for details.
	chmod 0600 $(CURDIR)/debian/open-iscsi/etc/iscsi/iscsid.conf
	@# Since this file is copied from the installer ramdisk to the
	@# system if the udeb is used, the permissions need to be changed
	@# here as well.
	@# However, we might be building on an architecture that doesn't
	@# have udeb support yet (see debian/control), so see if it was
	@# installed during build before trying to adjust permissions.
	if [ -f $(CURDIR)/debian/open-iscsi-udeb/etc/iscsi/iscsid.conf ] ; then \
		chmod 0600 $(CURDIR)/debian/open-iscsi-udeb/etc/iscsi/iscsid.conf ; \
	fi

override_dh_installinit:
	dh_installinit --no-start
	dh_installinit --no-start --name=umountiscsi.sh
