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

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

SHELL = /bin/bash
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
CFLAGS ?= $(shell dpkg-buildflags --get  CPPFLAGS; dpkg-buildflags --get CFLAGS)
LDFLAGS ?= $(shell dpkg-buildflags --get LDFLAGS)

%:
	dh $@ --buildsystem=autoconf --with sphinxdoc

# work around debhelper, v9 overwrites CFLAGS in the build :-/

override_dh_auto_configure:
	-env | grep CFLAGS
	dh_auto_configure -- \
		--includedir=\$${prefix}/include/$(DEB_HOST_MULTIARCH) \
		--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)"

override_dh_auto_test:
	: # needs download of tests, disabled

override_dh_auto_install:
	dh_auto_install
	ln -sf libmpdec.so.2.3 debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libmpdec.so

override_dh_sphinxdoc:
	cp -a debian/tmp/usr/share/doc/mpdecimal/* \
		debian/libmpdec-dev/usr/share/doc/libmpdec-dev
	rm -f debian/libmpdec-dev/usr/share/doc/libmpdec-dev/LICENSE*
	cp -p /usr/share/javascript/sphinxdoc/1.0/{doctools,jquery,searchtools,sidebar,underscore}.js \
		debian/libmpdec-dev/usr/share/doc/libmpdec-dev/_static/.
	dh_sphinxdoc
