clojure-lsp: update to 2024.08.05.
[void-pkg.git] / common / hooks / pre-pkg / 04-generate-runtime-deps.sh
blob78c4be2e63d51b057d9f095e60c1c3b9935ae4f5
1 # vim: set ts=4 sw=4 et:
3 # This hook executes the following tasks:
4 # - Generates rdeps file with run-time dependencies for xbps-create(1)
5 # - Generates shlib-requires file for xbps-create(1)
7 add_rundep() {
8 local dep="$1" i= rpkgdep= _depname= found=
10 _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
11 if [ -z "${_depname}" ]; then
12 _depname="$($XBPS_UHELPER_CMD getpkgname ${dep} 2>/dev/null)"
15 for i in ${run_depends}; do
16 rpkgdep="$($XBPS_UHELPER_CMD getpkgdepname $i 2>/dev/null)"
17 if [ -z "$rpkgdep" ]; then
18 rpkgdep="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
20 if [ "${rpkgdep}" != "${_depname}" ]; then
21 continue
23 $XBPS_UHELPER_CMD cmpver "$i" "$dep"
24 rval=$?
25 if [ $rval -eq 255 ]; then
26 run_depends="${run_depends/${i}/${dep}}"
28 found=1
29 done
30 if [ -z "$found" ]; then
31 run_depends+=" ${dep}"
35 store_pkgdestdir_rundeps() {
36 if [ -n "$run_depends" ]; then
37 for f in ${run_depends}; do
38 _curdep="$(echo "$f" | sed -e 's,\(.*\)?.*,\1,')"
39 if [ -z "$($XBPS_UHELPER_CMD getpkgdepname ${_curdep} 2>/dev/null)" -a \
40 -z "$($XBPS_UHELPER_CMD getpkgname ${_curdep} 2>/dev/null)" ]; then
41 _curdep="${_curdep}>=0"
43 printf "%s " "${_curdep}"
44 done > "${PKGDESTDIR}/rdeps"
48 hook() {
49 local depsftmp f lf j mapshlibs sorequires _curdep elfmagic broken_shlibs verify_deps
50 local _shlib_dir="${XBPS_STATEDIR}/shlib-provides"
52 # Disable trap on ERR, xbps-uhelper cmd might return error... but not something
53 # to be worried about because if there are broken shlibs this hook returns
54 # error via msg_error().
55 trap - ERR
57 mapshlibs=$XBPS_COMMONDIR/shlibs
59 if [ -n "$noverifyrdeps" ]; then
60 store_pkgdestdir_rundeps
61 return 0
64 depsftmp=$(mktemp) || exit 1
65 find ${PKGDESTDIR} -type f -perm -u+w > $depsftmp 2>/dev/null
67 for f in ${shlib_requires}; do
68 verify_deps+=" ${f}"
69 done
71 exec 3<&0 # save stdin
72 exec < $depsftmp
73 while read -r f; do
74 lf=${f#${PKGDESTDIR}}
75 if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
76 msg_normal "Skipping dependency scan for ${lf}\n"
77 continue
79 read -n4 elfmagic < "$f"
80 if [ "$elfmagic" = $'\177ELF' ]; then
81 for nlib in $($OBJDUMP -p "$f"|awk '/NEEDED/{print $2}'); do
82 [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
83 found=0
84 for j in ${verify_deps}; do
85 [[ $j == $nlib ]] && found=1 && break
86 done
87 [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
88 done
90 done
91 exec 0<&3 # restore stdin
92 rm -f $depsftmp
95 # Add required run time packages by using required shlibs resolved
96 # above, the mapping is done thru the common/shlibs file.
98 for f in ${verify_deps}; do
99 unset _rdep _pkgname _rdepver
101 local _findargs="-name"
102 # if SONAME is a path, find should use -wholename
103 if [[ "$f" = */* ]]; then
104 _findargs="-wholename"
106 if [ "$(find "${PKGDESTDIR}" $_findargs "$f")" ]; then
107 # Ignore libs by current pkg
108 echo " SONAME: $f <-> $pkgname (ignored)"
109 continue
110 # If this library is provided by a subpkg of sourcepkg, use that subpkg
111 elif _pkgname="$(cd "$_shlib_dir" && grep -F -l -x "$f" *.soname 2>/dev/null)"; then
112 # If that library has SONAME, add it to shlibs-requires, too.
113 _pkgname=${_pkgname%.soname}
114 _sdep="${_pkgname}-${version}_${revision}"
115 sorequires+="${f} "
116 elif _pkgname="$(cd "$_shlib_dir" && grep -F -l -x "$f" *.nosoname 2>/dev/null)"; then
117 _pkgname=${_pkgname%.nosoname}
118 _sdep="${_pkgname}-${version}_${revision}"
119 else
120 _rdep="$(awk -v sl="$f" '$1 == sl { print $2; exit; }' "$mapshlibs")"
122 if [ -z "$_rdep" ]; then
123 msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
124 broken_shlibs=1
125 continue
127 _pkgname=$($XBPS_UHELPER_CMD getpkgname "${_rdep}" 2>/dev/null)
128 _rdepver=$($XBPS_UHELPER_CMD getpkgversion "${_rdep}" 2>/dev/null)
129 if [ -z "${_pkgname}" -o -z "${_rdepver}" ]; then
130 msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
131 broken_shlibs=1
132 continue
134 _sdep="${_pkgname}>=${_rdepver}"
136 # By this point, SONAME can't be found in current pkg
137 sorequires+="${f} "
139 echo " SONAME: $f <-> ${_sdep}"
140 add_rundep "${_sdep}"
141 done
143 # If pkg uses any unknown SONAME error out.
145 if [ -n "$broken_shlibs" -a -z "$allow_unknown_shlibs" ]; then
146 msg_error "$pkgver: cannot guess required shlibs, aborting!\n"
149 store_pkgdestdir_rundeps
151 if [ -n "${sorequires}" ]; then
152 echo "${sorequires}" | xargs -n1 | sort | xargs > ${PKGDESTDIR}/shlib-requires