#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/autoreconf.mk

export AUTOPOINT=intltoolize --automake --copy

# Needed for testsuite
export XDG_RUNTIME_DIR = $(CURDIR)/debian/tmp/tmp/xdgruntimedir
export CK_TIMEOUT_MULTIPLIER = 0

#Don't build all the modules packages when bootstrapping
ifeq ($(words $(sort $(filter stage1,$(DEB_BUILD_PROFILES)))),1)
  $(warning Bootstrap profile build)
  export DH_OPTIONS += -Npulseaudio-module-bluetooth -Npulseaudio-module-bluetooth-dbg
  DEB_CONFIGURE_EXTRA_FLAGS += --disable-bluez
endif

common-install-arch::
	find $(DEB_DESTDIR) -name "*.la" -delete
	mkdir -p $(CURDIR)/debian/tmp/usr/share/alsa/alsa.conf.d
	cp -a $(CURDIR)/debian/pulse.conf \
		$(CURDIR)/debian/tmp/usr/share/alsa/alsa.conf.d
	cp -a $(CURDIR)/debian/pulse-alsa.conf $(CURDIR)/debian/tmp/usr/share/alsa
	install -d $(CURDIR)/debian/tmp/usr/share/apport/package-hooks
	cp $(CURDIR)/debian/apport-hook.py $(CURDIR)/debian/tmp/usr/share/apport/package-hooks/source_pulseaudio.py

common-binary-post-install-arch:: list-missing

# Libs should be in the multi-arch path, but the modules should be in the
# normal directory as pulseaudio is foreign
DEB_CONFIGURE_EXTRA_FLAGS = --enable-x11 --disable-hal-compat \
  --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
  --with-module-dir=\$${prefix}/lib/pulse-$(DEB_UPSTREAM_VERSION)/modules \
  --with-zsh-completion-dir=\$${datadir}/zsh/vendor-completions \
  --with-bash-completion-dir=\$${datadir}/bash-completion/completions \
  --with-systemduserunitdir=\$${prefix}/lib/systemd/user \
  --disable-bluez4


ifeq ($(words $(sort $(filter stage1,$(DEB_BUILD_PROFILES)))),1)
  DEB_CONFIGURE_EXTRA_FLAGS += --disable-bluez
endif


DEB_DH_MAKESHLIBS_ARGS_ALL = --exclude=usr/lib/pulse-$(DEB_UPSTREAM_VERSION)/modules \
			     --exclude=usr/lib/$(DEB_HOST_MULTIARCH)/pulseaudio

LDFLAGS += -Wl,--no-as-needed

DEB_DH_INSTALL_SOURCEDIR = $(CURDIR)/debian/tmp

DEB_MAKE_CHECK_TARGET = check VERBOSE=1
