#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# dpkg-shlibdeps needs to know where is libKitware.mummy.Runtime.Unmanaged.so
export LD_LIBRARY_PATH+=:/usr/lib/cli/Kitware.mummy.Runtime-1.0

# http://vtk.org/Bug/view.php?id=11875
CMAKE_FLAGS = \
	-DAVDN_INSTALL_PREFIX:PATH=/usr \
	-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
	-DAVDN_SNKEYFILE:STRING=/usr/share/cli-common/keys/mono.snk \
	-Dcsc_EXECUTABLE=/usr/bin/mono-csc \
	-DAVDN_EXTRA_EXCLUDE_CLASSES:STRING="vtkMPIController;vtkMPICommunicator"

# B-D-I is still not quite right on buildd, but anyway let's be prepared:
ifeq "" "$(filter %-doc,$(shell dh_listpackages))"
  CMAKE_FLAGS += -DGENERATE_DOXYGEN:BOOL=OFF
else
  CMAKE_FLAGS += -DGENERATE_DOXYGEN:BOOL=ON
endif

%:
	dh $@ --parallel --with cli

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

# Let's be smart with building doc
override_dh_auto_build-indep:
	-$(MAKE) -C obj-* AVDN_doxygen

# No tests needed for docs
override_dh_auto_test-indep:

pkg_doc = activiz.net-doc
pkg_exa = activiz.net-examples

override_dh_install-indep:
	dh_install -p$(pkg_doc) obj-*/Doxygen/html usr/share/doc/$(pkg_doc)/
	find ./debian/$(pkg_doc)/usr/share/doc/$(pkg_doc)/html/ -name *.md5 -delete
	find ./debian/$(pkg_doc)/usr/share/doc/$(pkg_doc)/html/ -name *.dot -delete
	#dh_installexamples -p$(pkg_exa) usr/Examples/*
	dh_install -p$(pkg_exa) usr/Examples/*  usr/share/doc/$(pkg_exa)/examples
	find ./debian/$(pkg_exa) -name *.sln -delete

# HTML/map file
override_dh_compress-indep:
	dh_compress -X.map

# automatically compute SOVERSION from vtk package:
vtk_version=$(shell apt-cache policy libvtk5-dev | grep "Installed:" | cut -d: -f2 | cut -d' ' -f2 | cut -d- -f1 | cut -d. -f1-2)
override_dh_gencontrol:
	dh_gencontrol -- -Vvtk:Version=$(vtk_version)

get-orig-source:
	./debian/get-orig-source
