#!/usr/bin/make -f

DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
ifneq ($(DEB_HOST_ARCH_OS),linux)
CONFIGURE_EXTRA_FLAGS += --disable-alsa
endif

%:
	dh $@ --parallel --with=autotools-dev,python2

override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-pyecasound=python \
		$(CONFIGURE_EXTRA_FLAGS)

override_dh_auto_build:
	dh_auto_build
ifeq ($(shell dpkg-query -s python-docutils 1>/dev/null 2>&1 && echo yes),yes)
	$(MAKE) docs
endif

override_dh_auto_clean:
	mv ecasound.spec ecasound.spec.orig
	dh_auto_clean
	mv ecasound.spec.orig ecasound.spec

override_dh_fixperms:
	dh_fixperms
ifneq (,$(findstring python-ecasound, $(shell dh_listpackages)))
	chmod a-x debian/python-ecasound/usr/share/pyshared/pyeca.py
	chmod a-x debian/python-ecasound/usr/share/pyshared/ecacontrol.py
	chmod a-x debian/python-ecasound/usr/share/pyshared/eci.py
endif
ifneq (,$(findstring libecasound-ruby1.8, $(shell dh_listpackages)))
	chmod a-x debian/libecasound-ruby1.8/usr/lib/ruby/1.8/ecasound.rb
endif

override_dh_install:
ifneq (,$(findstring python-ecasound, $(shell dh_listpackages)))
	dh_install -ppython-ecasound \
		usr/lib/python$(shell pyversions -dv)/lib-dynload/*.py \
			usr/share/pyshared/
endif
	dh_install --remaining-packages

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_auto_test:
