#! /usr/bin/make -f

%:
	dh $@ --with autoreconf --with autotools_dev


ARCH  := $(shell dpkg-architecture -qDEB_BUILD_ARCH)
# Tests are buggy; disable test on sparc
ifeq ($(ARCH),sparc)
	DEB_BUILD_OPTIONS += nocheck
endif



DEB_CONFIGURE_EXTRA_FLAGS = --enable-shared --enable-minc2 --enable-acr-nema CFLAGS="$(CFLAGS)"


override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

ps_docs = doc/prog_ref.ps doc/prog_guide.ps volume_io/Documentation/volume_io.ps

doc/prog_ref.ps doc/prog_guide.ps:
	$(MAKE) -C doc docs

volume_io/Documentation/volume_io.ps:
	$(MAKE) -C volume_io/Documentation docs

override_dh_install: $(ps_docs)
	# minc-tools
	rm -f debian/tmp/usr/bin/byte_swap
	rm -f debian/tmp/usr/bin/extract
	rm -f debian/tmp/usr/bin/acr_test
	rm -f debian/tmp/usr/bin/dicom_test
	dh_install -pminc-tools --autodest debian/tmp/usr/bin
	dh_install -pminc-tools --autodest debian/tmp/usr/share/man
	dh_link -pminc-tools \
		/usr/share/man/man1/voxeltoworld.1 \
		/usr/share/man/man1/worldtovoxel.1
	# libminc2-3
	dh_install -plibminc2-3 --autodest debian/tmp/usr/lib/*/lib*.so.*
	# libminc-dev
	dh_install -plibminc-dev --autodest debian/tmp/usr/lib/*/lib*.so
	dh_install -plibminc-dev --autodest  debian/tmp/usr/lib/*/lib*.a
	dh_install -plibminc-dev --autodest  debian/tmp/usr/include
	dh_installdocs -plibminc-dev $(ps_docs) debian/index.html
