#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND=-pie

DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
ifeq ($(DEB_HOST_ARCH_OS),)
  DEB_HOST_ARCH_OS := $(subst -gnu,,$(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM))
  ifeq ($(DEB_HOST_ARCH_OS),gnu)
    DEB_HOST_ARCH_OS := hurd
  endif
endif

%:
	dh $@ --with=autotools_dev

override_dh_auto_configure:
	dh_auto_configure -- \
		CFLAGS="$(CFLAGS) -fPIE" \
		--with-snmp=no \
		--disable-locking \
		--enable-static \
		--enable-pthread \
		--enable-libusb=yes \
		--enable-libusb_1_0 \
		--without-gphoto2

# udev file is currently not useful but leave as an example
override_dh_installudev:

# not really needed, but it thinks otherwise
override_dh_makeshlibs:

override_dh_install:
	dh_install
ifeq (kfreebsd,$(DEB_HOST_ARCH_OS))
	rm -f debian/libsane-extras-common/usr/share/man/man5/sane-geniusvp2.5
	rm -rf debian/libsane-extras-common/usr/share/doc/libsane-extras/geniusvp2
endif
	# remove wrong libsane.so.1 symlink
	rm -f debian/libsane-extras/usr/lib/$(DEB_HOST_MULTIARCH)/sane/libsane.so.1

	# remove damn rpath
	find debian/libsane-extras/usr/lib/$(DEB_HOST_MULTIARCH)/sane -name "libsane-*.so.1" -exec chrpath -d {} \;

	# install the dll.d config file
	install -d debian/libsane-extras/etc/sane.d/dll.d
	cp debian/dll.d/libsane-extras debian/libsane-extras/etc/sane.d/dll.d

