#!/usr/bin/make -f
# -*- makefile -*-

# Hardening flags.
export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie

# Retrieve environment information.
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Linux-specific stuff (dc1394, v4l, ois only available on linux)
ifeq ($(DEB_HOST_ARCH_OS),linux)
  CMAKE_ARCH_FLAGS = -DUSE_DC1394=ON -DUSE_V4L2=ON -DUSE_OIS=ON
else
  CMAKE_ARCH_FLAGS = -DUSE_DC1394=OFF -DUSE_V4L2=OFF -DUSE_OIS=OFF
endif

# CMake flags
CMAKE_FLAGS = \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_INCLUDEDIR="include/$(DEB_HOST_MULTIARCH)" \
	-DCMAKE_INSTALL_LIBDIR="lib/$(DEB_HOST_MULTIARCH)" \
	-DCMAKE_VERBOSE_MAKEFILE=ON \
	-DCMAKE_C_FLAGS_RELEASE="$(CFLAGS)" \
	-DCMAKE_CXX_FLAGS_RELEASE="$(CXXFLAGS)" \
	-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$(LDFLAGS)" \
	-DCMAKE_EXE_LINKER_FLAGS_RELEASE="$(LDFLAGS)" \
	-DCMAKE_BUILD_TYPE=Release \
	-DUSE_COIN3D=OFF \
	$(CMAKE_ARCH_FLAGS)

%:
	dh $@ --buildsystem=cmake --parallel

override_dh_clean:
	dh_clean -O--buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_auto_build-indep:
	dh_auto_build -- visp_doc # Generate Doxygen HTML documentation.

override_dh_installdocs:
	dh_installdocs -X.md5

override_dh_strip:
	dh_strip -plibvisp-ar3.1 --dbg-package=libvisp-ar3.1-dbg
	dh_strip -plibvisp-blob3.1 --dbg-package=libvisp-blob3.1-dbg
	dh_strip -plibvisp-core3.1 --dbg-package=libvisp-core3.1-dbg
	dh_strip -plibvisp-detection3.1 --dbg-package=libvisp-detection3.1-dbg
	dh_strip -plibvisp-gui3.1 --dbg-package=libvisp-gui3.1-dbg
	dh_strip -plibvisp-imgproc3.1 --dbg-package=libvisp-imgproc3.1-dbg
	dh_strip -plibvisp-io3.1 --dbg-package=libvisp-io3.1-dbg
	dh_strip -plibvisp-klt3.1 --dbg-package=libvisp-klt3.1-dbg
	dh_strip -plibvisp-mbt3.1 --dbg-package=libvisp-mbt3.1-dbg
	dh_strip -plibvisp-me3.1 --dbg-package=libvisp-me3.1-dbg
	dh_strip -plibvisp-robot3.1 --dbg-package=libvisp-robot3.1-dbg
	dh_strip -plibvisp-sensor3.1 --dbg-package=libvisp-sensor3.1-dbg
	dh_strip -plibvisp-visual-features3.1 --dbg-package=libvisp-visual-features3.1-dbg
	dh_strip -plibvisp-vision3.1 --dbg-package=libvisp-vision3.1-dbg
	dh_strip -plibvisp-vs3.1 --dbg-package=libvisp-vs3.1-dbg
	dh_strip -plibvisp-tt3.1 --dbg-package=libvisp-tt3.1-dbg
	dh_strip -plibvisp-tt-mi3.1 --dbg-package=libvisp-tt-mi3.1-dbg
	dh_strip

# Due to numerical imprecision, some tests are failing on ia64.
# This is not a critical issue so we let the testing fail on this
# architecture for now.
# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=723803
ifeq ($(DEB_HOST_ARCH),ia64)
  DH_AUTOTEST_CAN_FAIL=true
else
  DH_AUTOTEST_CAN_FAIL=false
endif

override_dh_auto_test-indep:

override_dh_auto_test-arch:
	export VISP_INPUT_IMAGE_PATH=/usr/share/visp-images-data/ \
	 && dh_auto_test || ${DH_AUTOTEST_CAN_FAIL}


