WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Script for checking dependencies  (Read 1183 times)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Script for checking dependencies
« on: December 17, 2022, 10:42:12 PM »
This script checks which libraries a binary is linked to and checks which
extensions provide them. It then creates a .dep file that contains the
minimum list of extensions required to satisfy that requirement:
Code: [Select]
tc@E310:~/Scripting/LddCheck$ ./LddCheck.sh $(which mc)
Created dependency file 10.x-x86/Result.dep
tc@E310:~/Scripting/LddCheck$ cat 10.x-x86/Result.dep
glib2.tcz
libssh2.tcz
slang.tcz

If I check the same binary against the 13.x repo:
Code: [Select]
tc@E310:~/Scripting/LddCheck$ ./LddCheck.sh -TC=13.x $(which mc)
Created dependency file 13.x-x86/Result.dep
tc@E310:~/Scripting/LddCheck$ cat 13.x-x86/Result.dep
glib2.tcz
libgcrypt.tcz
libssh2.tcz
slang.tcz
an extra dependency (libgcrypt.tcz) shows up because libssh2.tcz,dep no
longer includes it.

This is the help message:
Code: [Select]
Script to build a dependency file for an executables or libraries.
 It will find which extensions contain the libraries the executable
 requires and create a minimal list that satisfies that requirement.
 This will only pick up linked in library.so files. Optional libraries
 are not linked in and won't show up. Neither will icons and modules.

 Usage: (Path/To/Executable must be the last entry in the command)
        ./LddCheck.sh [ -TC= ][ -ARCH= ] Path/To/Executable

 Examples:
        ./LddCheck.sh -ARCH=x86 -TC=10.x /usr/local/bin/ffplay
        ./LddCheck.sh -ARCH=x86_64 -TC=13.x $(which mpg123)

 Optional Arguments:
        -TC=    Override which version of TC to use.
        -ARCH=  Override which architecture to use.
                Valid values x86  x86_64  armv6  armv7  armv7l  aarch64
        -ADDR=  Override which mirror to use.

 Current values in this script are:
        TC=10.x  ARCH=x86  ADDR=http://repo.tinycorelinux.net

The values for  TC,  ARCH, and  ADDR  are set near the beginning of the
script if you wish to change their default values. As the help message
shows, you can also override any of those values from the command line.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: Script for checking dependencies
« Reply #1 on: March 14, 2023, 11:49:11 AM »
Hi, Rich. I wrote something similar but more barebones, called deps, for folks like me who prefer a more manual process. deps is trivial: It just outputs each linked library and the extension that provides it, in table format (similar to readelf -d output). It's then up to the person creating the extension to use the data in the table to create a recursive .dep file (e.g., using Brian Smith's deptree script).

I hope you don't mind me attaching deps and deptree here. I thought it might be nice for this thread to be one-stop shopping for anyone looking for this kind of thing.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1020
Re: Script for checking dependencies
« Reply #2 on: March 14, 2023, 07:28:47 PM »
I use this to globally check which mounted tcz's are missing which library dependencies:
Code: [Select]
#!/bin/sh
#
for a in $(find /tmp/tcloop -type f)
        do file -b $a | grep -q '^ELF ' && TLIB=$(ldd $a | grep found) && [ -n "${TLIB:+x}" ] && echo -e "$a\n$TLIB"
done

Conversely, this script lists tcz's which are not a dependency of another through libraries. This doesn't mean it won't be a dependency for another reason, like tzdata or ca-certificates for example. This will list utilities as well as libraries you may or may not need or want:
Code: [Select]
#!/bin/sh
#
{ tce-status -i ;
for b in $(for a in $(find /tmp/tcloop -type f)
                do file -b $a | grep -q '^ELF ' && ldd $a | grep /local/ | cut -d\  -f3 | cut -d/ -f5
                done | sort -u)
        do find /tmp/tcloop -name $b | cut -d/ -f4
done | sort -u ; } | sort | uniq -u

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Script for checking dependencies
« Reply #3 on: March 14, 2023, 09:44:16 PM »
Hi GNUser
... I hope you don't mind me attaching deps and deptree here. I thought it might be nice for this thread to be one-stop shopping for anyone looking for this kind of thing.
No, it's fine. Thank you.