#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/default.mk

do_parallel=$(shell echo $(DEB_HOST_ARCH) | grep -q mips && echo '' || echo '--parallel')
do_help=$(shell echo $(DEB_HOST_ARCH) | grep -q -E '(mipsel|m68k|sh4)' && echo 'OFF' || echo 'ON')

export  http_proxy=http://127.0.0.1:9/
export  https_proxy=http://127.0.0.1:9/

export DEB_CFLAGS_MAINT_APPEND = -DNDEBUG
export DEB_CXXFLAGS_MAINT_APPEND := -DNDEBUG -DGLM_ENABLE_EXPERIMENTAL

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

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

# Default mega-rule
%:
	dh $@ $(do_parallel) --sourcedirectory=src

override_dh_clean:
	# Bring shipped version back
	[ -e src/FtglFont.aside ] && mv src/FtglFont.aside src/FtglFont || :
	dh_clean

override_dh_auto_configure:
	# Just to make sure we are not using shipped version
	[ -e src/FtglFont ] && mv src/FtglFont src/FtglFont.aside || [ -e src/FtglFont.aside ]
	OSMESA_DIR=/usr \
     dh_auto_configure -- \
		-DWORKBENCH_MESA_DIR=/usr \
		-DCMAKE_SKIP_RPATH:BOOL=OFF \
		-DWORKBENCH_USE_QT5_QOPENGL_WIDGET:BOOL=ON \
		-DWORKBENCH_INCLUDE_HELP_HTML_RESOURCES:BOOL=$(do_help)
#-DBUILD_SHARED_LIBS:BOOL=ON

override_dh_auto_install:
	dh_auto_install

	: # Sloppy man pages for now. Improve with templates
	mkdir -p debian/$(DEB_SOURCE)/usr/share/man/man1
	help2man --no-info --help-option=-help --version-string=$(DEB_VERSION_UPSTREAM) \
		-n "visualization and discovery tool used to map neuroimaging data" \
		debian/$(DEB_SOURCE)/usr/bin/wb_view \
		>| debian/$(DEB_SOURCE)/usr/share/man/man1/wb_view.1

	help2man --no-info --help-option=-all-commands-help --version-string=$(DEB_VERSION_UPSTREAM) \
		-n "command-line program for performing a variety of algorithmic tasks using volume, surface, and grayordinate data" \
		debian/$(DEB_SOURCE)/usr/bin/wb_command \
		>| debian/$(DEB_SOURCE)/usr/share/man/man1/wb_command.1

override_dh_install:
	dh_install
	install -D -m 0644 icons/linux/workbench_128x128x32.png debian/connectome-workbench/usr/share/pixmaps/connectome-workbench.png
