#!/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

# freenect is not available on hurd.
ifeq ($(DEB_HOST_ARCH_OS),hurd)
  CMAKE_ARCH_FLAGS += -DUSE_LIBFREENECT=OFF
else
  CMAKE_ARCH_FLAGS += -DUSE_LIBFREENECT=ON
endif

# CMake flags
CMAKE_FLAGS = \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-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 \
	-DBUILD_DEMOS=ON \
	-DBUILD_TESTS=ON \
	-DBUILD_EXAMPLES=ON \
	-DBUILD_TUTORIALS=ON \
	-DBUILD_SHARED_LIBS=ON \
	-DUSE_FFMPEG=OFF \
	-DUSE_OPENCV=ON \
	-DUSE_COIN3D=ON \
	-DUSE_LAPACK=ON \
	-DUSE_GSL=ON \
	-DUSE_XML2=ON \
	-DUSE_GTK2=OFF \
	-DUSE_JPEG=ON \
	-DUSE_PNG=ON \
	-DUSE_X11=ON \
	-DUSE_ZBAR=ON \
	-DUSE_DMTX=ON \
	$(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-core3.0 --dbg-package=libvisp-core3.0-dbg
	dh_strip -plibvisp-gui3.0 --dbg-package=libvisp-gui3.0-dbg
	dh_strip -plibvisp-io3.0 --dbg-package=libvisp-io3.0-dbg
	dh_strip -plibvisp-detection3.0 --dbg-package=libvisp-detection3.0-dbg
	dh_strip -plibvisp-ar3.0 --dbg-package=libvisp-ar3.0-dbg
	dh_strip -plibvisp-blob3.0 --dbg-package=libvisp-blob3.0-dbg
	dh_strip -plibvisp-me3.0 --dbg-package=libvisp-me3.0-dbg
	dh_strip -plibvisp-klt3.0 --dbg-package=libvisp-klt3.0-dbg
	dh_strip -plibvisp-sensor3.0 --dbg-package=libvisp-sensor3.0-dbg
	dh_strip -plibvisp-robot3.0 --dbg-package=libvisp-robot3.0-dbg
	dh_strip -plibvisp-visual-features3.0 --dbg-package=libvisp-visual-features3.0-dbg
	dh_strip -plibvisp-vision3.0 --dbg-package=libvisp-vision3.0-dbg
	dh_strip -plibvisp-vs3.0 --dbg-package=libvisp-vs3.0-dbg
	dh_strip -plibvisp-mbt3.0 --dbg-package=libvisp-mbt3.0-dbg
	dh_strip -plibvisp-tt3.0 --dbg-package=libvisp-tt3.0-dbg
	dh_strip -plibvisp-tt-mi3.0 --dbg-package=libvisp-tt-mi3.0-dbg
	dh_strip

# Parallelism is disabled in tests as some cannot run at the same
# time
#
# 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 --max-parallel=1 || ${DH_AUTOTEST_CAN_FAIL}

# Since Ogre removal no more useful
#override_dh_install:
#ifneq ($(DEB_HOST_ARCH_OS),hurd)
#  ifneq ($(DEB_HOST_ARCH_OS),kfreebsd)
#	# On hurd and kfreebsd usr/lib/*/visp/* is empty and produces an error
#	dh_install "usr/lib/*/visp/*" -p libvisp-dev
#        # Continue with regular dh_install
#	dh_install
#  endif
#endif

