#!/usr/bin/make -f
#export DH_VERBOSE=1

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS += -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -O0 
else
    CFLAGS += -O2 
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
    INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_autoreconf
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --prefix=/usr --sysconfdir=/etc $(shell dpkg-buildflags --export=configure)

build: build-arch build-indep

build-arch: build-stamp

build-indep: build-stamp

build-stamp: config.status 
	dh_testdir

	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	debconf-updatepo
	rm -f build-stamp build-stamp6

	dh_autotools-dev_restoreconfig
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/davfs2

binary-indep: install build

binary-arch: install build install6 build6
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installman
	dh_link usr/sbin/mount.davfs sbin/mount.davfs usr/sbin/umount.davfs sbin/umount.davfs
	dh_strip
	dh_compress
	dh_fixperms -X etc/davfs2/secrets -X var/run/mount.davfs -X etc/davfs2/certs/private
	dh_installdebconf
	dh_lintian 
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build build6 clean binary-indep binary-arch binary install install6
