#!/usr/bin/make -f

STAMP_DIR := debian/stampdir

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

configure_flags += \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--docdir=/usr/share/doc/libnss-myhostname \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--libexecdir=/lib/nss-myhostname \
		--libdir=/lib/$(DEB_HOST_MULTIARCH)

CFLAGS := -Wall -g -O$(if $(findstring noopt,$(DEB_BUILD_OPTIONS)),0,2)

LDFLAGS += -Wl,-z,defs

$(STAMP_DIR)/autoreconf-stamp:
	dh_autoreconf
	-mkdir -p $(STAMP_DIR)
	touch $@

$(STAMP_DIR)/configure-stamp: $(STAMP_DIR)/autoreconf-stamp
	dh_testdir
	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" ./configure $(configure_flags)
	-mkdir -p $(STAMP_DIR)
	touch $@

configure: configure-stamp

$(STAMP_DIR)/build-stamp: $(STAMP_DIR)/configure-stamp
	dh_testdir
	$(MAKE)
	touch $@

build: $(STAMP_DIR)/build-stamp

$(STAMP_DIR)/install-stamp: $(STAMP_DIR)/build-stamp
	$(MAKE) install DESTDIR=$(CURDIR)/debian/libnss-myhostname
	touch $@

install: $(STAMP_DIR)/install-stamp

clean:
	dh_testdir
	dh_testroot
	# remove install and build dirs
	[ ! -e Makefile ] || $(MAKE) distclean
	-rm -rf $(STAMP_DIR)
	dh_autoreconf_clean
	dh_clean

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -s
	dh_installdocs -s
	dh_install -s
	dh_installman -s
	dh_link -s
	dh_strip -s
	dh_compress -s
	dh_fixperms -s
	dh_makeshlibs -s
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

binary: binary-indep binary-arch
.PHONY: configure build install clean binary-indep binary-arch binary
