#! /usr/bin/make -f

ARCH  = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export CFLAGS=-std=gnu17
CMAKE_FLAGS =


# Tests are buggy; disable test on armhf, sparc
ifeq ($(ARCH),armhf)
	DEB_BUILD_OPTIONS += nocheck
endif
ifeq ($(ARCH),sparc)
	DEB_BUILD_OPTIONS += nocheck
endif

ifneq ($(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial/libhdf5.so),)
  export DEB_CPPFLAGS_MAINT_APPEND := -I/usr/include/hdf5/serial
  export DEB_LDFLAGS_MAINT_APPEND := -Wl,-L/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial
endif

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_install:
	cd debian/minc-tools && mkdir -p usr/share && mv usr/man usr/share
	dh_link /usr/share/man/man1/voxeltoworld.1 \
		/usr/share/man/man1/worldtovoxel.1
	for pl in `grep -Rl '#![[:space:]]*/usr/bin/env[[:space:]]\+perl' debian/*/usr/*` ; do \
	    sed -i '1s?^#![[:space:]]*/usr/bin/env[[:space:]]\+perl?#!/usr/bin/perl?' $${pl} ; \
	done
