#!/usr/bin/make -f

VER_MAJOR = 3
VER_MINOR = 20
VER_PATCH = 0

PYVERS = $(shell pyversions -r debian/control)

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE:STRING=Release \
	-DCMAKE_C_FLAGS:STRING=-O2 \
	-DCMAKE_CXX_FLAGS:STRING=-O2 \
	-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
	-DCMAKE_SKIP_RPATH:BOOL=ON \
	-DITK_USE_REVIEW:BOOL=ON \
	-DITK_USE_REVIEW_STATISTICS:BOOL=ON \
	-DITK_USE_OPTIMIZED_REGISTRATION_METHODS:BOOL=ON \
	-DITK_USE_TRANSFORM_IO_FACTORIES:BOOL=ON \
	-DITK_USE_SYSTEM_GDCM:BOOL=ON \
	-DITK_USE_SYSTEM_VXL:BOOL=OFF \
	-DUSE_FFTWD:BOOL=ON \
	-DUSE_FFTWF:BOOL=ON \
	-DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$(PYVERS) \
	-DPYTHON_INCLUDE_PATH:PATH=/usr/include/$(PYVERS) \
	-DPYTHON_NUMPY_INCLUDE_PATH:PATH=/usr/include/$(PYVERS)/numpy \
	-DPYTHON_LIBRARY:FILEPATH=/usr/lib/lib$(PYVERS).so \
	-DWRAP_ITK_JAVA:BOOL=OFF \
	-DWRAP_ITK_PYTHON:BOOL=ON \
	-DWRAP_ITK_TCL:BOOL=OFF \
	-DWRAP_ITK_DIMS:STRING='2;3' \
	-DWRAP_complex_float:BOOL=ON \
	-DWRAP_covariant_vector_float:BOOL=ON \
	-DWRAP_float:BOOL=ON \
	-DWRAP_rgb_unsigned_char:BOOL=ON \
	-DWRAP_rgb_unsigned_short:BOOL=ON \
	-DWRAP_signed_short:BOOL=ON \
	-DWRAP_unsigned_char:BOOL=ON \
	-DWRAP_unsigned_short:BOOL=ON \
	-DWRAP_vector_float:BOOL=ON

VER_FULL = $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
SOVERSION = $(VER_MAJOR).$(VER_MINOR)

pkg_python = python-insighttoolkit$(VER_MAJOR)


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

override_dh_auto_configure: pre-build
	dh_auto_configure --buildsystem=cmake -- $(CMAKE_FLAGS)

pre-build:
	echo "Available disk space:"
	df -h .

override_dh_auto_install:
	make -C obj* DESTDIR=`pwd`/debian/$(pkg_python) install
	cd debian/$(pkg_python)/usr/lib/InsightToolkit/WrapITK \
		&& rm -rf ClassIndex Configuration SWIG WrapITKConfig.cmake \
		&& mv lib/libSwig* ../..
	rm -rf debian/$(pkg_python)/usr/share/cmake-2.8


override_dh_lintian:
	echo "$(pkg_python): non-dev-pkg-with-shlib-symlink" > debian/$(pkg_python).lintian-overrides
	echo "$(pkg_python): package-name-doesnt-match-sonames" >> debian/$(pkg_python).lintian-overrides
	dh_lintian

control-file:
	sed -e "s/@VER_MAJOR@/$(VER_MAJOR)/g" \
	    -e "s/@SOVERSION@/$(SOVERSION)/g" \
	    < debian/control.in > debian/control.tmp
	[ -e debian/control ] \
	  && cmp -s debian/control debian/control.tmp \
	  && rm -f debian/control.tmp && exit 0; \
	  mv debian/control.tmp debian/control
