#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

include /usr/share/dpkg/default.mk

gcc_major = 8

DESTDIR := $(CURDIR)/debian/tmp

# This is a subset of debhelper compat level 13 syntax.
SUBST := sed \
	-e 's![$$]{DEB_HOST_ARCH_BITS}!$(DEB_HOST_ARCH_BITS)!' \
	-e 's![$$]{DEB_HOST_MULTIARCH}!$(DEB_HOST_MULTIARCH)!' \
	$(NULL)

# This is a subset of dh-exec syntax.
ifeq ($(DEB_HOST_ARCH),amd64)
SUBST += -e 's/^\[amd64\] *//'
else
SUBST += -e '/^\[amd64\]/d'
endif
ifeq ($(DEB_HOST_ARCH),i386)
SUBST += -e 's/^\[i386\] *//'
else
SUBST += -e '/^\[i386\]/d'
endif

%:
	dh $@

# debcrossgen in Debian 10 got the i386 Meson architecture wrong
override_dh_auto_configure:
	if ! meson obj-$(DEB_HOST_GNU_TYPE) \
		--sysconfdir=/etc \
		--prefix=/usr \
		--libexecdir=libexec \
		--libdir=lib/$(DEB_HOST_MULTIARCH) \
	; then \
		cat obj-$(DEB_HOST_GNU_TYPE)/meson-logs/meson-log.txt; \
		exit 1; \
	fi

override_dh_installdirs:
	set -e; for p in \
		steamrt-container-host-compat \
	; do \
		$(SUBST) < debian/$$p.dirs.in > debian/$$p.dirs; \
	done
	dh_installdirs

override_dh_link:
	set -e; for p in \
		steamrt-container-host-compat \
	; do \
		$(SUBST) < debian/$$p.links.in > debian/$$p.links; \
	done
	dh_link

override_dh_auto_test:
	dh_auto_test
	test "$$(gcc -dumpversion)" = $(gcc_major)

override_dh_gencontrol:
	python3 abi/generate-dependencies.py \
		$(DEB_HOST_MULTIARCH) \
		obj-$(DEB_HOST_GNU_TYPE)/abi/steam-runtime-abi.json
	dh_gencontrol \
		-plibegl-dev -plibgles-dev \
		-- \
		-v1.1.0-0steamrt$(DEB_VERSION_UPSTREAM) \
		${NULL}
	dh_gencontrol \
		-plibfreetype-dev \
		-- \
		-v2.9.1-0steamrt$(DEB_VERSION_UPSTREAM) \
		${NULL}
	dh_gencontrol \
		-pautoconf2.69 \
		-- \
		-v2.69-0steamrt$(DEB_VERSION_UPSTREAM) \
		${NULL}
	dh_gencontrol \
		--remaining-packages \
		-- \
		-Vsteamrt:gcc-major=$(gcc_major) \
		${NULL}

override_dh_missing:
	dh_missing --fail-missing
