#!/usr/bin/make -f

SHELL := sh -e

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
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        MAKEFLAGS += -j$(NUMJOBS)
endif

%:
	dh ${@} --with autotools_dev

override_dh_auto_configure:
	dh_auto_configure --	--host=$(DEB_HOST_GNU_TYPE) \
				--build=$(DEB_BUILD_GNU_TYPE) \
				--prefix=/usr \
				--mandir=\$${prefix}/share/man \
				--infodir=\$${prefix}/share/info \
				--disable-example \
				CFLAGS="$(CFLAGS)" \
				LDFLAGS="-Wl,-z,defs"

override_dh_install:
	# remove unused files
	rm -f debian/tmp/etc/init.d/fuse
	rm -f debian/tmp/etc/udev/rules.d/99-fuse.rules
	rm -f debian/tmp/usr/lib/*.la

	dh_install --fail-missing

override_dh_installinit:
	dh_installinit --no-start --update-rcd-params='start 9 S .'

override_dh_compress:
	dh_compress -Xusr/share/doc/libfuse-dev/examples

override_dh_strip:
	dh_strip --dbg-package=fuse-dbg

override_dh_makeshlibs:
	dh_makeshlibs -s -V "libfuse2 (>= 2.8.1)" --add-udeb=libfuse2-udeb

override_dh_fixperms:
	dh_fixperms

	if [ -e debian/fuse/usr/bin/fusermount ]; \
	then \
		chmod 0755 debian/fuse/usr/bin/fusermount; \
	fi
