#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

override_dh_auto_build:
	# Invoke standard build mechanism.
	dh_auto_build
	# Enable this if you have a multi-core machine and are debugging the debian packages. Disable again for upload.
	# dh_auto_build -- -j10
	# build the core api documentation too
	dh_auto_build -- core_devdoc

override_dh_auto_configure:
	# We turn of several build options here to reduce dependencies. Later, several modules are moved to an extra package which then uses cuda/opencl and stuff.
	# NOTE: you can uncomment the last line for faster compilation/package debugging.
	dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release \
							-DOW_USE_CUDA=OFF\
							-DOW_USE_OPENCL=OFF\
							-DOW_USE_TESTS=OFF\
							-DOW_PACKAGE_BUILD=ON\
								-DOW_PACKAGE_NOCOPY_LICENSE=ON\
								-DOW_PACKAGE_NOCOPY_COREFONTS=ON\
								-DOW_PACKAGE_PACKAGER=deb\
							-DOW_MODULE_TOOLBOX_BASE=ON\
							-DOW_MODULE_TOOLBOX_EEG=ON\
							-DOW_MODULE_TOOLBOX_IO=ON\
							-DOW_MODULE_TOOLBOX_IMAGEPROCESSING=ON\
							-DOW_MODULE_TOOLBOX_OTHERS=ON\
							-DOW_C_FLAGS_INJECT="$(shell dpkg-buildflags --get CFLAGS)"\
							-DOW_CXX_FLAGS_INJECT="$(shell dpkg-buildflags --get CXXFLAGS)"\
							-DOW_LD_FLAGS_INJECT="$(shell dpkg-buildflags --get LDFLAGS)"\
							-DOW_CPP_FLAGS_INJECT="$(shell dpkg-buildflags --get CPPFLAGS)"

override_dh_auto_install:
	# libopenwalnut1
	cmake -DCOMPONENT=CORE      -DCMAKE_INSTALL_PREFIX=debian/libopenwalnut1/usr -P build/cmake_install.cmake
	cmake -DCOMPONENT=EXT       -DCMAKE_INSTALL_PREFIX=debian/libopenwalnut1/usr -P build/cmake_install.cmake
	# libopenwalnut1-dev
	cmake -DCOMPONENT=CORE_DEV  -DCMAKE_INSTALL_PREFIX=debian/libopenwalnut1-dev/usr -P build/cmake_install.cmake
	cmake -DCOMPONENT=EXT_DEV  -DCMAKE_INSTALL_PREFIX=debian/libopenwalnut1-dev/usr -P build/cmake_install.cmake
	# libopenwalnut1-doc
	# Use jquery from Debian package, so prune shipped one. Taken from https://github.com/neurodebian/statsmodels/tree/debian/debian
	-rm ./doc/core/html/jquery.js
	cmake -DCOMPONENT=CORE_DOC  -DCMAKE_INSTALL_PREFIX=debian/libopenwalnut1-doc/usr -P build/cmake_install.cmake
	# openwalnut-qt4
	cmake -DCOMPONENT=QT4GUI    -DCMAKE_INSTALL_PREFIX=debian/openwalnut-qt4/usr -P build/cmake_install.cmake
	# openwalnut-modules
	cmake -DCOMPONENT=MODULES   -DCMAKE_INSTALL_PREFIX=debian/openwalnut-modules/usr -P build/cmake_install.cmake

%:
	# Ensure that dh finds our source and detects that this is made with cmake
	dh $@ --sourcedirectory=src --builddirectory=build

