#!/usr/bin/env bash
set -e

# This script finds all system libraries on which something in the package
# tree is dependent on.
#
# command line:
#   find-dependence.sh  EUPS_PATH

. "$1"/bashrc
setup-hscpipe

cd "$EUPS_PATH"

set +e
LANG=C find "$EUPS_PATH" -type f -exec ldd {} \; 2> /dev/null |
    sed -n -e '/=>/ { s/^.*=> *\([^ (]*\).*$/\1/g ; p }' |
    grep -v -F "$EUPS_PATH" |
    grep "^/" |
    tee /dev/stderr |
    sort | uniq > "$EUPS_PATH"/.signature/dependence.txt

set -e
echo "=== Found dependence ==="
cat "$EUPS_PATH"/.signature/dependence.txt
