2021-12-12 20:04:46 +10:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# library_depends.sh - Automatically add library requirements to depends
|
|
|
|
#
|
2025-04-02 11:35:34 +10:00
|
|
|
# Copyright (c) 2021-2025 Pacman Development Team <pacman-dev@lists.archlinux.org>
|
2021-12-12 20:04:46 +10:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
[[ -n "$LIBMAKEPKG_AUTODEP_LIBRARY_DEPENDS_SH" ]] && return
|
|
|
|
LIBMAKEPKG_AUTODEP_LIBRARY_DEPENDS_SH=1
|
|
|
|
|
2023-10-21 01:45:20 +01:00
|
|
|
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
|
2021-12-12 20:04:46 +10:00
|
|
|
|
|
|
|
autodep_functions+=('library_depends')
|
|
|
|
|
|
|
|
library_depends() {
|
|
|
|
if check_option "autodeps" "y"; then
|
2023-02-13 01:00:14 +00:00
|
|
|
local dep filename libdeps libdir libpath prefix sofile isoptdep
|
|
|
|
declare -A libdeps
|
|
|
|
declare -A optlibdeps
|
2021-12-12 20:04:46 +10:00
|
|
|
|
|
|
|
while IFS= read -rd '' filename; do
|
|
|
|
for sofile in $(LC_ALL=C readelf -d $filename 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p'); do
|
|
|
|
# get the full path of the library
|
|
|
|
libpath=$(ldd $filename | sed -nr "s/.$sofile => (.*) \(.*\)/\1/p")
|
|
|
|
|
|
|
|
# if ldd can not find the library, it is likely part of the package and not in filesystem
|
|
|
|
if [[ -z $libpath ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# skip if the library is part of the package
|
|
|
|
if [[ -e "$pkgdir/$libpath" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# find the prefix for the dependency
|
|
|
|
libpath=${libpath#/}
|
|
|
|
libpath=${libpath%/*}
|
|
|
|
|
|
|
|
unset prefix
|
|
|
|
for libdir in ${LIB_DIRS[@]}; do
|
2025-01-31 15:56:51 +10:00
|
|
|
if [[ ${libdir#*:} == ${libpath} ]]; then
|
|
|
|
prefix=${libdir%%:*}
|
2021-12-12 20:04:46 +10:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z ${prefix} ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-05-20 02:15:37 -03:00
|
|
|
# only add library dependency if it exists - this helps bootstrapping dependencies
|
2021-12-12 20:04:46 +10:00
|
|
|
if [[ $(run_pacman -T "$prefix:$sofile") ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-02-13 01:00:14 +00:00
|
|
|
# if the binary marked as optional, add its dependencies to optdepends
|
|
|
|
unset isoptdep
|
|
|
|
for optbinary in "${optbinaries[@]}"
|
|
|
|
do
|
|
|
|
IFS=':'; local optbinarydata=($optbinary); unset IFS;
|
|
|
|
if [[ "${optbinarydata[0]}" == "${filename#$pkgdir/}" ]] ; then
|
|
|
|
if [[ -z ${optbinarydata[1]} ]]; then
|
|
|
|
optlibdeps["$prefix:$sofile"]+=""
|
|
|
|
else
|
|
|
|
optlibdeps["$prefix:$sofile"]+="${optbinarydata[1]# }; "
|
|
|
|
fi
|
|
|
|
isoptdep=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -n ${isoptdep} ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
libdeps["$prefix:$sofile"]=1
|
2021-12-12 20:04:46 +10:00
|
|
|
done
|
|
|
|
|
|
|
|
done < <(find "$pkgdir" -type f -perm -u+x -print0)
|
|
|
|
|
2023-02-13 01:00:14 +00:00
|
|
|
# remove optlibdep if already in libdep
|
|
|
|
for libdep in ${!libdeps[@]}; do
|
|
|
|
unset optlibdeps["$libdep"]
|
|
|
|
done
|
|
|
|
|
|
|
|
depends+=(${!libdeps[@]})
|
|
|
|
|
|
|
|
for optlibdep in "${!optlibdeps[@]}"; do
|
|
|
|
if [[ -z ${optlibdeps[${optlibdep}]} ]]; then
|
|
|
|
optdepends+=("$optlibdep")
|
|
|
|
else
|
|
|
|
optdepends+=("$optlibdep: ${optlibdeps[${optlibdep}]%; }")
|
|
|
|
fi
|
|
|
|
done
|
2021-12-12 20:04:46 +10:00
|
|
|
fi
|
|
|
|
}
|