#!/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

gcc_major = 10
gcc_major_plus_one = $(shell expr $(gcc_major) + 1)
clang_major = 11
clang_major_plus_one = $(shell expr $(clang_major) + 1)

DESTDIR := $(CURDIR)/debian/tmp

# This is a subset of dh-exec syntax.
SUBST := sed -e ''
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 $@

override_dh_install:
	dh_install
ifneq ($(filter amd64 i386,$(DEB_HOST_ARCH)),)
	dh_install -psteamrt-dev 'usr/share/meson/cross/binutils*.txt'
	dh_install -psteamrt-dev 'usr/share/meson/cross/gcc*.txt'
endif

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 \
		-- \
		-Vsteamrt:gcc-major=$(gcc_major) \
		-Vsteamrt:gcc-major-plus-one=$(gcc_major_plus_one) \
		-Vsteamrt:clang-major=$(clang_major) \
		-Vsteamrt:clang-major-plus-one=$(clang_major_plus_one) \
		${NULL}
