From b12288fa69b171f7c9405518c9bed3581a06f7ce Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 12 Feb 2021 09:56:56 +0100 Subject: build: add support for fixing up library soname This makes it possible to declare a package ABI_VERSION independent from the upstream soname by setting PKG_ABI_VERSION in the package makefile. The library filename is fixed up for files installed to packages and to the staging dir. References to the original from executables within the same package are also fixed up Signed-off-by: Felix Fietkau --- scripts/set-abi-version.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 scripts/set-abi-version.sh (limited to 'scripts') diff --git a/scripts/set-abi-version.sh b/scripts/set-abi-version.sh new file mode 100755 index 0000000000..a61c842c6d --- /dev/null +++ b/scripts/set-abi-version.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2020 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +SELF=${0##*/} + +[ -n "$PATCHELF" ] || { + echo "$SELF: patchelf command not defined (PATCHELF variable not set)" + exit 1 +} + +ABI_VER="$1" +PATCH_DIR="$2" +REF_LIST="$3" + +[ -n "$ABI_VER" -a -n "$PATCH_DIR" ] || { + echo "$SELF: no ABI version or files/directories specified" + echo "usage: $SELF [...]" + exit 1 +} + +cmd() { + echo "$@" >&2 + "$@" || exit 1 +} + +gen_lib_list() { + while read F; do + F="${F##*/}" + case "$F" in + lib*.so*);; + *) continue;; + esac + echo -n "$F:" + done < "$REF_LIST" +} + +find "$PATCH_DIR" -type f -a -name 'lib*.so*' | \ +( + while read F; do + NEW_F="${F%%.so*}.so.$ABI_VER" + NEW_NAME="${NEW_F##*/}" + [ "$NEW_F" != "$F" ] || continue + cmd mv "$F" "$NEW_F" + [ "$REF_LIST" ] || cmd ln -s "$NEW_NAME" "$F" + cmd $PATCHELF --set-soname "$NEW_NAME" "$NEW_F" + done +) + +[ -n "$REF_LIST" ] || exit 0 + +LIBS="$(gen_lib_list)" +LIBS="${LIBS%%:}" +find "$PATCH_DIR" -type f -a -exec file {} \; | \ + sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.*/\1:\2/p' | \ +( + IFS=":" + while read F S; do + $PATCHELF --print-needed "$F" | while read L; do + BASE_L="${L%%.so*}" + for lib in $LIBS; do + base_lib="${lib%%.so*}" + [ "$BASE_L" = "$base_lib" ] || continue + [ "$l" = "$lib" ] && continue + cmd $PATCHELF --replace-needed "$L" "$lib" "$F" + done + done + done + true +) -- cgit v1.2.3