#!/usr/bin/make -f

# DH_VERBOSE := 1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

CMAKE_EXTRA_FLAGS = \
	-DCMAKE_SKIP_RPATH=ON \
	-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
	-DCAMITK_INSTALL_ROOT:PATH=/usr \
	-DTOOL_CORESCHEMA:BOOL=ON \
	-DTOOL_LML:BOOL=TRUE \
	-DTOOL_PML:BOOL=TRUE \
        -DMML_GENERATE_GUI:BOOL=ON \
	-DTOOL_MML:BOOL=TRUE \
	-DMML_GENERATE_XSD_LIB:BOOL=TRUE \
	-DACTION_ITKSEGMENTATION:BOOL=TRUE \
	-DACTION_ITKFILTERS:BOOL=TRUE \
	-DAPPLICATION_WIZARD:BOOL=TRUE \
	-DCOMPONENT_VTKMESH:BOOL=TRUE \
	-DCOMPONENT_DICOM:BOOL=TRUE \
	-DCOMPONENT_ITKIMAGE:BOOL=TRUE \
	-DCOMPONENT_PHYSICALMODEL:BOOL=TRUE \
	-DCOMPONENT_MML:BOOL=TRUE \
	-DAPIDOC_GENERATE_FOR_CAMITK_CORE:BOOL=TRUE

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_EXTRA_FLAGS)

VER_MAJOR=3
VER_MINOR=0
VER_SHORT=$(VER_MAJOR).$(VER_MINOR)

pkg_lib = libcamitk$(VER_MAJOR)
pkg_dev = libcamitk$(VER_MAJOR)-dev
pkg_data = libcamitk$(VER_MAJOR)-data
pkg_doc = libcamitk$(VER_MAJOR)-doc
pkg_imp = camitk-imp

# let's be smart with doc
override_dh_auto_build-indep:
	$(MAKE) -C obj-* apidoc
	# remove the javascript search field
	rm -f obj-*/share/apidoc/html/jquery.js

# No tests needed for docs
override_dh_auto_test-indep:

override_dh_install:
	# camitk dynamic library
	dh_install -p$(pkg_lib) debian/tmp/usr/lib/lib*.so.* usr/lib 
	dh_install -p$(pkg_lib) --autodest debian/tmp/usr/lib/camitk-$(VER_SHORT)/actions/lib*.so
	dh_install -p$(pkg_lib) --autodest debian/tmp/usr/lib/camitk-$(VER_SHORT)/components/lib*.so

	# camitk headers and static libs + wizard
	dh_install -p$(pkg_dev) debian/tmp/usr/lib/lib*.so usr/lib 
	dh_install -p$(pkg_dev) debian/tmp/usr/bin/camitk-wizard
	dh_install -p$(pkg_dev) --autodest debian/tmp/usr/lib/camitk-$(VER_SHORT)/lib*.a
	dh_install -p$(pkg_dev) --autodest debian/tmp/usr/include
	dh_install -p$(pkg_dev) --autodest debian/tmp/usr/share/camitk-$(VER_SHORT)/cmake/*.cmake 
	dh_installman -p$(pkg_dev) $(CURDIR)/applications/wizard/camitk-wizard.1

	# api doc
	dh_install -p$(pkg_doc) --autodest debian/tmp/usr/share/camitk-$(VER_SHORT)/apidoc

	# all test data
	dh_install -p$(pkg_data) --autodest debian/tmp/usr/share/camitk-$(VER_SHORT)/testdata

	# imp
	dh_install -p$(pkg_imp) debian/tmp/usr/bin/camitk-imp
	dh_installman -p$(pkg_imp) $(CURDIR)/applications/imp/camitk-imp.1

# see http://lists.debian.org/debian-mentors/2012/07/msg00124.html
get-orig-source:
	PERL_LWP_SSL_VERIFY_HOSTNAME=0 uscan --rename --verbose --force-download --destdir=../tarballs
