#!/bin/bash # Copyright Advanced Micro Devices, Inc. # SPDX-License-Identifier: MIT set -e PREFIX="${1:?Expected install prefix argument}" PATCHELF="${PATCHELF:-patchelf}" # update_library_links # --------------------- # Purpose: # Normalize a shared library so that its real file is named exactly as its ELF SONAME, # and rename the input file (usually a symlink) to a desired linker name (e.g., libfoo.so). # # Synopsis: # update_library_links # # Arguments: # libfile Path to the library file or symlink. # Example: $PREFIX/lib/librocm_sysdeps_cap.so # linker_name Desired linker-name filename to exist in the same directory. # Example: libcap.so update_library_links() { local libfile="$1" # e.g. $PREFIX/lib/librocm_sysdeps_cap.so local linker_name="$2" # e.g. libcap.so if [ ! -e "$libfile" ]; then echo "Error: File '$libfile' not found" >&2 return 1 fi local dir="$(dirname -- "$libfile")" # Get the soname and realname local lib_soname="$("$PATCHELF" --print-soname "$libfile" 2>/dev/null || true)" local realname="$(readlink -f -- "$libfile" 2>/dev/null || true)" if [[ -z "$lib_soname" || -z "$realname" ]]; then [[ -z "$lib_soname" ]] && echo "Error: No SONAME found in '$libfile'" >&2 [[ -z "$realname" ]] && echo "Error: readlink -f failed for '$libfile'" >&2 return 1 fi if [[ "$realname" != "$dir/$lib_soname" ]]; then # Move the real file to $dir/$lib_soname mv -v -- "$realname" "$dir/$lib_soname" pushd "$dir" > /dev/null ln -sf "$lib_soname" "$linker_name" popd > /dev/null rm "$libfile" else # Rename symlink in the same directory mv "$libfile" "$dir/$linker_name" fi } update_library_links "$PREFIX/lib/librocm_sysdeps_cap.so" "libcap.so" update_library_links "$PREFIX/lib/librocm_sysdeps_psx.so" "libpsx.so" # pc files are not output with a relative prefix. Sed it to relative. if [ -d "$PREFIX/lib/pkgconfig" ]; then for pcfile in "$PREFIX/lib/pkgconfig"/*.pc; do if [ -f "$pcfile" ]; then sed -i -E 's|^prefix=.+|prefix=${pcfiledir}/../..|' "$pcfile" sed -i -E 's|^exec_prefix=.+|exec_prefix=${pcfiledir}/../..|' "$pcfile" sed -i -E 's|^libdir=.+|libdir=${prefix}/lib|' "$pcfile" sed -i -E 's|^includedir=.+|includedir=${prefix}/include|' "$pcfile" fi done fi