git: 2ec0ea0e3f77 - main - Mk: add a new HAS_SYMBOL_VERSION

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Thu, 20 Mar 2025 16:49:12 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/ports/commit/?id=2ec0ea0e3f7757b4bb991edb52f26e12cfc8cd2e

commit 2ec0ea0e3f7757b4bb991edb52f26e12cfc8cd2e
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2025-03-20 09:22:43 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-03-20 16:49:02 +0000

    Mk: add a new HAS_SYMBOL_VERSION
    
    When a port is tagged with this (should contain the list of libraries
    with SYMBOL version) the ports tree will add an extra check that
    the built library actually have symbols versions.
---
 Mk/Scripts/check_have_symbols.sh | 27 +++++++++++++++++++++++++++
 Mk/bsd.port.mk                   |  9 ++++++++-
 x11/libxkbcommon/Makefile        |  2 ++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/Mk/Scripts/check_have_symbols.sh b/Mk/Scripts/check_have_symbols.sh
new file mode 100644
index 000000000000..ee3095dabf74
--- /dev/null
+++ b/Mk/Scripts/check_have_symbols.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -eu
+set -o pipefail
+
+# the 3 implementations of readelf we can use have different output, but they all have a similarity
+# for the .gnu.version_d section they all have the symbol version in last element of their output
+# and have "Name:" or "vda_name": in the 10th position, no other section displayed have this
+# it means that if there are no symbols exported then nothing matches this search pattern.
+
+STAGEDIR=$1
+shift
+ret=0
+failed=""
+for lib; do
+	if ! /usr/bin/readelf -V ${STAGEDIR}$lib  | awk 'BEGIN { ret=1 } $10 == "Name:" || $10 == "vda_name:" { ret=0; exit 0 } END { exit ret }'; then
+		ret=1
+		failed="${failed} ${lib}"
+	fi
+done
+if [ "$failed" != "" ]; then
+	echo "the following libraries are supposed to have symbols versioning but they don't" >&2
+	for l in ${failed}; do
+		echo "- $l" >&2
+	done
+fi
+exit $ret
diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index 709f554ee078..5bfbf1728b95 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -5394,6 +5394,12 @@ show-dev-errors:
 .      endif
 .    endif #DEVELOPER
 
+.    if defined(HAS_SYMBOL_VERSION)
+stage-sanity: check_has_symbol_version
+check_has_symbol_version:
+		${SH} ${SCRIPTSDIR}/check_have_symbols.sh ${STAGEDIR} ${HAS_SYMBOL_VERSION}
+.    endif # HAS_SYMBOL_VERSION
+
 ${_PORTS_DIRECTORIES}:
 	@${MKDIR} ${.TARGET}
 
@@ -5465,7 +5471,8 @@ _STAGE_SEQ=		050:stage-message 100:stage-dir 150:run-depends \
 				900:add-plist-info 910:add-plist-docs 920:add-plist-examples \
 				930:add-plist-data 940:add-plist-post ${POST_PLIST:C/^/990:/} \
 				${_OPTIONS_install} ${_USES_install} \
-				${_OPTIONS_stage} ${_USES_stage} ${_FEATURES_stage}
+				${_OPTIONS_stage} ${_USES_stage} ${_FEATURES_stage} \
+				994:stage-sanity
 .    if defined(DEVELOPER)
 _STAGE_SEQ+=	995:stage-qa
 .    else
diff --git a/x11/libxkbcommon/Makefile b/x11/libxkbcommon/Makefile
index 489cde98c08e..32f1662d4802 100644
--- a/x11/libxkbcommon/Makefile
+++ b/x11/libxkbcommon/Makefile
@@ -25,6 +25,8 @@ CPE_VENDOR=	xkbcommon
 SHEBANG_FILES=	test/xkeyboard-config-test.py.in \
 		test/*.py
 
+HAS_SYMBOL_VERSION=	${PREFIX}/lib/libxkbregistry.so.0.8.1
+
 OPTIONS_DEFINE=	EVDEV WAYLAND X11
 OPTIONS_DEFAULT=EVDEV WAYLAND X11
 OPTIONS_SUB=	yes