summaryrefslogtreecommitdiffstats
path: root/tools/build/print_so_versions.sh
blob: a3c4ecdce86cd9c2980231bfbd0f485dea58ba82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

# Take a .so file as input and print the Debian packages and versions of the
# libraries it links.

set -euo pipefail
# set -x

source /etc/os-release

sofile="$1"

case "$ID" in
    alpine)
        depfiles=$( (ldd "$sofile" 2>/dev/null || true) | grep '=>' | sed 's/.*=> \(.*\) (.*)/\1/')
        (for depfile in $depfiles; do
             echo "$(basename "$depfile") => $(apk info --who-owns "${depfile}" | awk '{print $(NF)}')"
        done) | sort | uniq
        ;;

    debian)
        depfiles=$(ldd "$sofile" | grep '=>' | sed 's/.*=> \(.*\) (.*)/\1/')
        (for depfile in $depfiles; do
            pkgname=$(dpkg -S "${depfile}" | sed 's/\(\): .*/\1/')
            dpkg -l "${pkgname}" | grep '^ii' | awk '{print $2 " => " $3}'
        done) | sort | uniq
        ;;

    centos)
        echo "TODO!"
        ;;

    *)
        echo "$0: unexpected Linux distribution: '$ID'" >&2
        exit 1
        ;;
esac