Skip to content

Commit f11810b

Browse files
committed
makepkg: Implement 'autolibprovides'/'autolibdepends' options
'autolibprovides' tries to find all real (no symlinks) library names in the paths a compiler/linker search for by default. And then add those libraries to 'libprovides'. 'autolibdepends' searches all libraries and binaries in default paths for library dependencies, then adds those dependencies to 'libdepends'. Both options are disabled by default.` Signed-off-by: Mohammad AlSaleh <[email protected]>
1 parent 7d05ffc commit f11810b

File tree

2 files changed

+85
-11
lines changed

2 files changed

+85
-11
lines changed

etc/makepkg.conf.in

+12-11
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,20 @@ BUILDENV=(!distcc color !ccache check !sign)
7373
# These are default values for the options=() settings
7474
#########################################################################
7575
#
76-
# Default: OPTIONS=(!strip docs libtool staticlibs emptydirs !zipman !purge !debug)
76+
# Default: OPTIONS=(!strip docs libtool staticlibs emptydirs !zipman !purge !debug !autolibprovides !autolibdepends)
7777
# A negated option will do the opposite of the comments below.
7878
#
79-
#-- strip: Strip symbols from binaries/libraries
80-
#-- docs: Save doc directories specified by DOC_DIRS
81-
#-- libtool: Leave libtool (.la) files in packages
82-
#-- staticlibs: Leave static library (.a) files in packages
83-
#-- emptydirs: Leave empty directories in packages
84-
#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
85-
#-- purge: Remove files specified by PURGE_TARGETS
86-
#-- debug: Add debugging flags as specified in DEBUG_* variables
87-
#
88-
OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !debug)
79+
#-- strip: Strip symbols from binaries/libraries
80+
#-- docs: Save doc directories specified by DOC_DIRS
81+
#-- libtool: Leave libtool (.la) files in packages
82+
#-- staticlibs: Leave static library (.a) files in packages
83+
#-- emptydirs: Leave empty directories in packages
84+
#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
85+
#-- purge: Remove files specified by PURGE_TARGETS
86+
#-- autolibprovides: Auto-add so provides
87+
#-- autolibdepends: Auto-add so depends
88+
#
89+
OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !debug !autolibprovides !autolibdepends)
8990

9091
#-- File integrity checks to use. Valid: md5, sha1, sha224, sha256, sha384, sha512
9192
INTEGRITY_CHECK=(md5)

scripts/makepkg.sh.in

+73
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ declare -r startdir="$(pwd -P)"
4848

4949
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
5050

51+
packaging_options+=('autolibprovides')
52+
packaging_options+=('autolibdepends')
5153
build_options=('ccache' 'distcc' 'buildflags' 'makeflags')
5254
splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
5355
'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
@@ -499,6 +501,42 @@ run_package() {
499501
run_function_safe "package${1:+_$1}"
500502
}
501503

504+
auto_libdepends() {
505+
local l f solib search_paths bin_paths autolibdepends
506+
507+
msg2 "$(gettext "Auto-adding libdepends...")"
508+
509+
# Only search default library/binary paths
510+
search_paths=($(${CC:-gcc} -print-search-dirs | grep '^lib' | sed "s|^libraries: =|:|;s|:| ${pkgdir}|g"))
511+
bin_paths=(${pkgdir}${PATH//:/ ${pkgdir}})
512+
513+
for f in $(find ${search_paths[@]} ${bin_paths[@]} -maxdepth 1 -type f 2>/dev/null); do
514+
# Skip files with relative path to avoid wasting time on dups
515+
if [[ ! "$f" =~ \.\./ ]]; then
516+
while read solib; do
517+
if ! in_array "${solib}" ${autolibdepends[@]}; then
518+
autolibdepends+=(${solib})
519+
fi
520+
done < <(LC_ALL=C readelf -d "$f" 2>/dev/null | grep '(NEEDED)' | while read l; do
521+
l="${l#*\[}"
522+
echo "${l%.so*}.so"
523+
done)
524+
fi
525+
done
526+
527+
# Pass depends if there is any
528+
# We don't do this unconditionally to avoid passing an empty line to mapfile
529+
if [[ ${depends[@]} ]]; then
530+
printf '%s\n' "${depends[@]}"
531+
fi
532+
533+
# Print and pass autolibdepends if any was found
534+
if [[ ${autolibdepends[@]} ]]; then
535+
msg2 "$(gettext "Auto-added libdepends %s")" "${autolibdepends[@]}"
536+
printf '%s\n' "${autolibdepends[@]}"
537+
fi
538+
}
539+
502540
find_libdepends() {
503541
local d sodepends
504542
@@ -563,6 +601,34 @@ find_libdepends() {
563601
(( ${#libdepends[@]} )) && printf '%s\n' "${libdepends[@]}"
564602
}
565603
604+
auto_libprovides() {
605+
local f solib search_paths autolibprovides
606+
607+
msg2 "$(gettext "Auto-adding libprovides...")"
608+
609+
# Only search default library paths
610+
search_paths=($(${CC:-gcc} -print-search-dirs | grep '^lib' | sed "s|^libraries: =|:|;s|:| ${pkgdir}|g"))
611+
612+
for f in $(find ${search_paths[@]} -maxdepth 1 -type f 2>/dev/null); do
613+
# Match solibs, but exclude ones with a relative path to avoid dups
614+
if [[ "$f" =~ \.so ]] && [[ ! "$f" =~ \.\./ ]]; then
615+
solib="${f##*/}"
616+
autolibprovides+=("${solib%.so*}.so")
617+
fi
618+
done
619+
620+
# Pass provides if there is any
621+
# We don't do this unconditionally to avoid passing an empty line to mapfile
622+
if [[ ${provides[@]} ]]; then
623+
printf '%s\n' "${provides[@]}"
624+
fi
625+
626+
# Print and pass autolibprovides if any was found
627+
if [[ ${autolibprovides[@]} ]]; then
628+
msg2 "$(gettext "Auto-added libprovides %s")" "${autolibprovides[@]}"
629+
printf '%s\n' "${autolibprovides[@]}"
630+
fi
631+
}
566632
567633
find_libprovides() {
568634
local p libprovides missing
@@ -655,7 +721,14 @@ write_pkginfo() {
655721
write_kv_pair "size" "$size"
656722
write_kv_pair "arch" "$pkgarch"
657723
724+
if check_option "autolibprovides" "y"; then
725+
mapfile -t provides < <(auto_libprovides)
726+
fi
658727
mapfile -t provides < <(find_libprovides)
728+
729+
if check_option "autolibdepends" "y"; then
730+
mapfile -t depends < <(auto_libdepends)
731+
fi
659732
mapfile -t depends < <(find_libdepends)
660733
661734
write_kv_pair "license" "${license[@]}"

0 commit comments

Comments
 (0)