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

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

export CFLAGS=$(shell dpkg-buildflags --get CFLAGS)
export CPPFLAGS=$(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS=$(shell dpkg-buildflags --get CFXXLAGS)
export LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)

export DEB_BUILD_HARDENING=1

# set environment for waf
export LINKFLAGS=-Wl,--as-needed
WAF_OPTIONS = --verbose --destdir=debian/tmp --prefix=/usr --enable-fftw3f
WAF_CMD = ./waf

%:
	dh $@ --with python2,python3 --buildsystem=pybuild

override_dh_auto_clean:
	-$(WAF_CMD) distclean
	-find python -name '*.pyc' -delete
	rm -rf build/ dist/ .waf* .lock-waf*
	rm -rf python/gen/ aubio.egg-info
	rm -rf python/lib/*.pyc python/lib/aubio/*.so
	rm -rf python/ext/config.h
	rm -rf python/tests/sounds
	rm -rf .pybuild
	rm -rf debian/tmp
	rm -rf doc/web/
	rm -rf manpages.refs manpages.links

override_dh_auto_configure:
	$(WAF_CMD) configure $(WAF_OPTIONS)

override_dh_auto_build:
	$(WAF_CMD) build $(WAF_OPTIONS)
	dh_auto_build --buildsystem=pybuild

override_dh_auto_test:
	# run tests
	make create_test_sounds
	LD_LIBRARY_PATH=build/src:$(LD_LIBRARY_PATH) \
		dh_auto_test --buildsystem=pybuild

override_dh_auto_install:
	# library
	$(WAF_CMD) install $(WAF_OPTIONS)
	cp -prv build/src/libaubio.a debian/tmp/usr/lib
	# python extension
	dh_auto_install --buildsystem=pybuild
	# call dh_numpy to add dependency on numpy abi
	if [ -x /usr/bin/dh_numpy ]; then dh_numpy; fi
