#!/usr/bin/make -f

### This version at least shares the same ABI, used in the dh_makeshlibs calls:
SHLIBS=2.5.2
major=6

### Architecture handling:
CONFIGURE_OPTIONS += --without-libusb
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
ifeq ($(DEB_HOST_ARCH_OS),hurd)
  CONFIGURE_OPTIONS += --without-libusb-1.0
endif

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

### Overrides:
override_dh_auto_configure:
	dh_auto_configure -- --with-drivers=all --enable-static $(CONFIGURE_OPTIONS)

override_dh_auto_install:
	LIBRARY_PATH=$(CURDIR)/debian/tmp/usr/lib $(MAKE) install prefix=$(CURDIR)/debian/tmp/usr
	# Remove upstream 0-byte files to make lintian happy. Print them first:
	find debian/tmp -size 0 -print
	find debian/tmp -size 0 -delete
	# Remove the COPYING file, debian/copyright is there already:
	find debian/tmp -name COPYING -delete
	# Remove the recursive symlink:
	rm debian/tmp/usr/include/gphoto2/gphoto2

override_dh_install:
	dh_install --list-missing -X.la
	# Double-check that and act accordingly:
	-test -e debian/tmp/usr/lib/udev/check-mtp-device && \
		mkdir -p debian/libgphoto2-port10/lib/udev && \
		mv debian/tmp/usr/lib/udev/check-mtp-device \
			debian/libgphoto2-port10/lib/udev/check-mtp-device

ifeq ($(DEB_HOST_ARCH_OS),linux)
override_dh_installudev:
	# No longer needed with current udev. But check with non-Linux architectures stuff:
	# rm debian/libgphoto2-2/lib/udev/check-ptp-camera
	# Generate the udev file, get it installed, and clean:
	CAMLIBS=`ls -d debian/libgphoto2-$(major)/usr/lib/$(DEB_HOST_MULTIARCH)/libgphoto2/2*` ./packaging/generic/print-camera-list udev-rules version 175 mode 0664 group plugdev > debian/libgphoto2-$(major).udev
	mkdir -p debian/libgphoto2-$(major)/lib/udev/hwdb.d/
	CAMLIBS=`ls -d debian/libgphoto2-$(major)/usr/lib/$(DEB_HOST_MULTIARCH)/libgphoto2/2*` ./packaging/generic/print-camera-list hwdb > debian/libgphoto2-$(major)/lib/udev/hwdb.d/20-libgphoto2-$(major).hwdb
	dh_installudev
	rm debian/libgphoto2-$(major).udev
endif

override_dh_fixperms:
	dh_fixperms --exclude usbcam

override_dh_makeshlibs:
	dh_makeshlibs -plibgphoto2-$(major) -V 'libgphoto2-$(major) (>= $(SHLIBS))' -X/usr/lib/$(DEB_HOST_MULTIARCH)/libgphoto2/
	dh_makeshlibs -plibgphoto2-port10    -V 'libgphoto2-port10    (>= $(SHLIBS))' -X/usr/lib/$(DEB_HOST_MULTIARCH)/libgphoto2_port/

override_dh_shlibdeps:
	dh_shlibdeps -ldebian/libgphoto2-$(major)/usr/lib/:debian/libgphoto2-port10/usr/lib/

ifeq (linux,$(DEB_HOST_ARCH_OS))
override_dh_gencontrol:
	dh_gencontrol
	dh_gencontrol -plibgphoto2-$(major) -- -Vudev-hotplug='udev (>= 201)'
endif

%:
	dh $@ --with autoreconf
