#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

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

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

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
  confflags += --disable-silent-rules
endif

config.status: configure
	dh_testdir
	dh_update_autotools_config
	dh_autoreconf
	
	./configure \
	  CPPFLAGS="$(CPPFLAGS)" \
	  CFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)" \
	  $(confflags) \
	  --prefix=/usr \
	  --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

build-indep:
build-arch: config.status
	dh_testdir
	
	$(MAKE)
	
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) check VERBOSE=1 || true
endif

build: build-indep build-arch

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

binary-indep:

binary-arch: build-arch
	dh_testdir
	dh_testroot
	
	dh_prep
	dh_installdirs
	
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	
	dh_install
	dh_installdocs
	dh_installchangelogs doc/CHANGES
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -N libattr1
	dh_makeshlibs -p libattr1 -V 'libattr1 (>= 1:2.4.48)' --add-udeb libattr1-udeb
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

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