#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

options = export DEBUG=-DNDEBUG DISTRIBUTION=debian \
	  CONFIG_SHELL=/bin/sh;

confflags += \
  --libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
  --libexecdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
  $(nil)

# Ensure cross builds succeed
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

build-arch: build
build-indep: build
build: built
built: config
	$(MAKE) default
	rm -f po/acl.pot
	$(MAKE) -C po acl.pot
	touch built

check: built
	dh_testdir
	
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C test tests || true
endif

config: .census
.census:
	dh_testdir
	dh_update_autotools_config
	$(options) $(MAKE) configure LOCAL_CONFIGURE_OPTIONS="$(confflags)"
	touch .census

clean:
	dh_testdir
	-rm -f built .census
	$(MAKE) distclean
	dh_clean

binary-indep:

binary-arch: check
	dh_testdir
	dh_testroot
	
	dh_prep
	dh_installdirs
	
	DIST_ROOT=$(CURDIR)/debian/tmp \
	  $(MAKE) install install-dev install-lib
	
	dh_install
	dh_installdocs
	dh_installchangelogs doc/CHANGES
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -N libacl1
	dh_makeshlibs -p libacl1 -V 'libacl1 (>= 2.2.51-8)'
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
