#!/usr/bin/make -f

export LC_ALL=C.UTF-8
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-z,defs -Wl,--as-needed

include /usr/share/dpkg/default.mk

ifeq ($(shell dpkg --compare-versions `c++ -dumpversion || echo 0` ge 4.8 || echo old),old)
export CC = gcc-4.8
export CXX = g++-4.8
endif

%:
	dh $@

DOCS=disabled
BLUEZ5_CODEC_LDAC=disabled

libexecdir := libexec
libdir := lib/$(DEB_HOST_MULTIARCH)
DESTDIR := $(CURDIR)/debian/tmp

# We open-code the Meson clean, configure, build, test, install steps
# because the debhelper in SteamRT 1 'scout' is too old to have built-in
# knowledge of Meson.

override_dh_auto_clean:
	rm -fr _build

override_dh_auto_configure:
	if ! meson _build \
		--prefix=/usr \
		--libexecdir=$(libexecdir) \
		--libdir=$(libdir) \
		-Daudiotestsrc=enabled \
		-Dauto_features=enabled \
		-Dbluez5-codec-aac=disabled \
		-Dbluez5-codec-ldac=$(BLUEZ5_CODEC_LDAC) \
		-Dlibcamera=disabled \
		-Ddocs=$(DOCS) \
		-Dffmpeg=disabled \
		-Dinstalled_tests=enabled \
		-Dman=enabled \
		-Dtest=enabled \
		-Dvideotestsrc=enabled \
		-Dvolume=enabled \
		-Dvulkan=disabled \
		-Dalsa=disabled \
		-Dbluez5=disabled \
		-Dbluez5-backend-hsp-native=disabled \
		-Dbluez5-backend-hfp-native=disabled \
		-Dbluez5-backend-ofono=disabled \
		-Dbluez5-backend-hsphfpd=disabled \
		-Dbluez5-codec-aptx=disabled \
		-Dgstreamer=disabled \
		-Dgstreamer-device-provider=disabled \
		-Djack=disabled \
		-Dmedia-session=disabled \
		-Dpipewire-alsa=disabled \
		-Dpipewire-jack=disabled \
		-Dsystemd=disabled \
		-Dsystemd-system-service=disabled \
		-Dsystemd-user-service=disabled \
		-Dudev=disabled \
		-Dv4l2=disabled \
	; then \
		cat _build/meson-logs/meson-log.txt; \
		exit 1; \
	fi

override_dh_auto_build:
	ninja -v -C _build

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	meson test -C _build --verbose
endif

override_dh_auto_install:
	DESTDIR=$(DESTDIR) ninja -C _build install

override_dh_missing:
	dh_missing --fail-missing

override_dh_makeshlibs:
	dh_makeshlibs \
		--exclude=/usr/lib/$(DEB_HOST_MULTIARCH)/gstreamer-1.0 \
		--exclude=/usr/lib/$(DEB_HOST_MULTIARCH)/pipewire-0.3 \
		--exclude=/usr/lib/$(DEB_HOST_MULTIARCH)/spa-0.2 \
		-- -c4

override_dh_shlibdeps-arch:
	dh_shlibdeps \
		-l/usr/lib/$(DEB_HOST_MULTIARCH)/pipewire-0.3 \
		$(NULL)
