tazpkg annotate modules/find-depends @ rev 844

Finish modularization. Beta release: still have few FIXMEs and TODOs.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Oct 05 03:53:47 2015 +0300 (2015-10-05)
parents a02e36d44d06
children 3af642cd5e69
rev   line source
al@822 1 #!/bin/sh
al@828 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
al@828 3 # find-depends - TazPkg module
al@828 4 # Functions that are common to tazpkg and tazpkg-convert, and sourced by them.
al@822 5
al@822 6
al@822 7 # search dependencies for files in $TMP_DIR/$file/fs
al@822 8
al@828 9 find_depends() {
al@828 10 DEFAULT_DEPENDS='glibc-base gcc-lib-base'
al@822 11
al@844 12 [ ! -f "$PKGS_DB/files.list.lzma" ] && tazpkg recharge >/dev/null
al@844 13
al@844 14 for i in "$PKGS_DB/files.list.lzma" \
al@844 15 "$PKGS_DB/undigest/"*"/files.list.lzma"; do
al@840 16 [ -f "$i" ] && lzma d "$i" -so >> "$TMP_DIR/files.list"
al@822 17 done
al@822 18
al@828 19 _ 'Find depends...' 1>&2
al@828 20 libs_found=''
al@844 21 find "$1" -type f | \
al@840 22 while read chkfile; do
al@844 23 [ "$(dd bs=1 skip=1 count=3 < "$chkfile" 2>/dev/null)" != 'ELF' ] && continue
al@844 24
al@822 25 case "$chkfile" in
al@828 26 *.o|*.ko|*.ko.gz|*.ko.xz) continue;;
al@822 27 esac
al@822 28
al@844 29 for lib in $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so "$chkfile" 2>/dev/null | sed '/=>/!d;s/ =>.*//'); do
al@822 30 case " $libs_found " in
al@844 31 *\ $lib\ *) continue;;
al@822 32 esac
al@822 33 libs_found="$libs_found $lib"
al@822 34 case "$lib" in
al@822 35 statically|linux-gate.so*|ld-*.so|*/ld-*.so) continue;;
al@822 36 esac
al@840 37 find "${1:-$TMP_DIR/$file/fs}" | grep -q /$lib$ && continue
al@822 38
al@828 39 _n 'for %s' "$lib" 1>&2
al@844 40 echo -ne ' \r' 1>&2
al@828 41
al@844 42 for dep in $(fgrep "$lib" "$TMP_DIR/files.list" | cut -d: -f1); do
al@822 43 case " $DEFAULT_DEPENDS " in
al@822 44 *\ $dep\ *) continue 2;;
al@822 45 esac
al@840 46 grep -qs "^$dep$" "$TMP_DIR/depends" && continue 2
al@822 47 done
al@822 48
al@822 49 if [ -n "$dep" ]; then
al@840 50 echo "$dep" >> "$TMP_DIR/depends"
al@822 51 else
al@840 52 grep -qs ^$lib$ "$TMP_DIR/unresolved" ||
al@840 53 echo "$lib" >> "$TMP_DIR/unresolved"
al@822 54 fi
al@822 55 done
al@822 56 done
al@822 57
al@828 58 spc=''
al@828 59 [ -s "$TMP_DIR/depends" ] &&
al@840 60 sort < "$TMP_DIR/depends" 2>/dev/null | uniq | \
al@822 61 while read file; do
al@822 62 echo -n "$spc$file"
al@828 63 spc=' '
al@822 64 done
al@822 65 }
al@822 66
al@822 67