Skip to content
Snippets Groups Projects
rules 4.34 KiB
#!/usr/bin/make -f
# Copyright © 2019-2020 Collabora Ltd.
# SPDX-License-Identifier: MIT
# (see debian/copyright)

export LC_ALL=C.UTF-8

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

meson_options =

ifeq ($(DEB_DISTRIBUTION),UNRELEASED)
meson_options += --werror
endif

gtk_doc_has_cflags := $(shell \
	if gtkdoc-scangobj --help 2>&1 | grep '[-]-cflags' >/dev/null; then \
		echo true; \
	else \
		echo false; \
	fi \
)
dh_options :=
ifeq ($(gtk_doc_has_cflags),false)
dh_options += -Nlibsteam-runtime-tools-0-doc
endif

%:
	dh $@ $(dh_options)

# 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
	rm -fr debian/locales

libexecdir := libexec
pkglibexecdir := $(libexecdir)/steam-runtime-tools-0
libdir := lib/$(DEB_HOST_MULTIARCH)
pkglibdir := $(libdir)/steam-runtime-tools-0
DESTDIR := $(CURDIR)/debian/tmp
relocatable_pkglibdir := $(CURDIR)/debian/libsteam-runtime-tools-0-relocatable-libs/usr/$(pkglibdir)

override_dh_auto_configure:
	if ! meson _build \
		--prefix=/usr \
		--libexecdir=$(libexecdir) \
		--libdir=$(libdir) \
		-Dgtk_doc=$(gtk_doc_has_cflags) \
		-Dintrospection=false \
		-Dman=true \
		-Dmultiarch_tuple=$(DEB_HOST_MULTIARCH) \
		-Dsrcdir=src \
		-Dversion=$(DEB_VERSION) \
		$(meson_options) \
	; 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)),)
	debian/check-version-number.sh $(CURDIR)/_build $(DEB_VERSION_UPSTREAM)
	mkdir debian/locales
	localedef -f UTF-8 -i en_US --no-archive debian/locales/en_US.UTF-8
	env LOCPATH=$(CURDIR)/debian/locales LC_ALL=en_US.UTF-8 \
	meson test -C _build --verbose
endif

override_dh_auto_install:
	DESTDIR=$(DESTDIR) ninja -C _build install
	ln -s ../../bin/$(DEB_HOST_MULTIARCH)-vulkaninfo \
		$(DESTDIR)/usr/$(pkglibexecdir)/
	ln -s ../../bin/$(DEB_HOST_MULTIARCH)-wflinfo \
		$(DESTDIR)/usr/$(pkglibexecdir)/
	ln -s ../../lib/libcapsule/relocatable/$(DEB_HOST_MULTIARCH)-capsule-capture-libs \
		$(DESTDIR)/usr/$(pkglibexecdir)/
	set -e; for x in $(DESTDIR)/usr/libexec/installed-tests/steam-runtime-tools-0/*; do \
		if [ -f "$$x" ] \
		&& cmp -s "$$x" \
			$(DESTDIR)/usr/libexec/steam-runtime-tools-0/$(DEB_HOST_MULTIARCH)-true; \
		then \
			ln -fnsv ../../steam-runtime-tools-0/$(DEB_HOST_MULTIARCH)-true "$$x"; \
		fi; \
	done

override_dh_shlibdeps:
	dh_shlibdeps \
		-plibsteam-runtime-tools-0-relocatable-libs \
		-- \
		-prelocatable \
		-e$(DESTDIR)/usr/bin/steam-runtime-check-requirements \
		-e$(DESTDIR)/usr/bin/steam-runtime-system-info \
		-e$(DESTDIR)/usr/$(pkglibexecdir)/$(DEB_HOST_MULTIARCH)-check-locale \
		$(NULL)
	dh_shlibdeps

override_dh_link:
	dh_link
	:
	install -d $(relocatable_pkglibdir)
	ln -fnsv ../libsteam-runtime-tools-0.so.0 $(relocatable_pkglibdir)
	export PATH=/usr/lib/libcapsule/relocatable:$$PATH; \
	LD_LIBRARY_PATH='$(DESTDIR)/usr/$(libdir)' \
	$(DEB_HOST_MULTIARCH)-capsule-capture-libs \
		--container / \
		--dest $(relocatable_pkglibdir) \
		--link-target / \
		--no-glibc \
		--provider / \
		only-dependencies:path:$(DESTDIR)/usr/bin/steam-runtime-check-requirements \
		only-dependencies:path:$(DESTDIR)/usr/bin/steam-runtime-system-info \
		only-dependencies:path:$(DESTDIR)/usr/$(pkglibexecdir)/$(DEB_HOST_MULTIARCH)-check-locale \
		$(NULL)
	:
	# Make the links in $(pkglibdir) relative. This is contrary
	# to Debian policy, but is what we need for the LD_LIBRARY_PATH
	# Steam Runtime, where GLib is in /lib.
	# Also make them point to the SONAME if possible.
	set -e; \
	cd $(relocatable_pkglibdir); \
	for link in lib*; do \
		target="$$(readlink -v "$$link")"; \
		echo "before: $$link -> $$target"; \
		by_soname="$${target%/*}/$$link"; \
		if ! [ -e "$$by_soname" ]; then \
			echo "$$by_soname does not exist"; \
		elif ! command test "$$target" -ef "$$by_soname"; then \
			echo "$$target is not the same file as $$by_soname"; \
		else \
			target="$$by_soname"; \
		fi; \
		case "$$target" in \
			(/*) \
				target="../../../..$${target}"; \
				;; \
		esac; \
		echo "after:  $$link -> $$target"; \
		ln -fnsv "$${target}" "$${link}"; \
	done

override_dh_missing:
	dh_missing --fail-missing