From 0a544924748a37e2960a338fadf77719f9fa7d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ball=C3=B3=20Gy=C3=B6rgy?= Date: Mon, 13 Feb 2023 01:00:14 +0000 Subject: [PATCH] libmakepkg/autodep: add support for optional autodeps This allows to specify paths for binaries in a new optbinaries=() array in PKGBUILD, which are not essential for the package and their dependencies can be considered optional. If a libdepend is needed only by optional binaries, then it's added to opdepends with a cumulated comment. --- .../libmakepkg/autodep/library_depends.sh.in | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/scripts/libmakepkg/autodep/library_depends.sh.in b/scripts/libmakepkg/autodep/library_depends.sh.in index 596a9821..c27af075 100644 --- a/scripts/libmakepkg/autodep/library_depends.sh.in +++ b/scripts/libmakepkg/autodep/library_depends.sh.in @@ -27,8 +27,9 @@ autodep_functions+=('library_depends') library_depends() { if check_option "autodeps" "y"; then - local dep filename libdeps libdir libpath prefix sofile - declare -a libdeps + local dep filename libdeps libdir libpath prefix sofile isoptdep + declare -A libdeps + declare -A optlibdeps 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 @@ -65,11 +66,43 @@ library_depends() { continue fi - libdeps+=("$prefix:$sofile") + # 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 done done < <(find "$pkgdir" -type f -perm -u+x -print0) - depends+=($(printf '%s\n' "${libdeps[@]}" | LC_ALL=C sort -u)) + # 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 fi }