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)
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
23 $XBPS_UHELPER_CMD cmpver
"$i" "$dep"
25 if [ $rval -eq 255 ]; then
26 run_depends
="${run_depends/${i}/${dep}}"
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"
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().
57 mapshlibs
=$XBPS_COMMONDIR/shlibs
59 if [ -n "$noverifyrdeps" ]; then
60 store_pkgdestdir_rundeps
64 depsftmp
=$
(mktemp
) ||
exit 1
65 find ${PKGDESTDIR} -type f
-perm -u+w
> $depsftmp 2>/dev
/null
67 for f
in ${shlib_requires}; do
71 exec 3<&0 # save stdin
75 if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
76 msg_normal
"Skipping dependency scan for ${lf}\n"
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
84 for j
in ${verify_deps}; do
85 [[ $j == $nlib ]] && found
=1 && break
87 [[ $found -eq 0 ]] && verify_deps
="$verify_deps $nlib"
91 exec 0<&3 # restore stdin
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)"
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}"
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}"
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"
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"
134 _sdep
="${_pkgname}>=${_rdepver}"
136 # By this point, SONAME can't be found in current pkg
139 echo " SONAME: $f <-> ${_sdep}"
140 add_rundep
"${_sdep}"
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