aboutsummaryrefslogtreecommitdiffstats
path: root/Mk/Scripts/actual-package-depends.sh
blob: 18af33e57d39144bb1956b80d54c032c6f978c03 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# MAINTAINER: portmgr@FeeeBSD.org
# $FreeBSD$

[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_ACTUAL_PACKAGE_DEPENDS}" ] && set -x

if [ -z "${PKG_BIN}" ]; then
    echo "PKG_BIN required in environment." >&2
    exit 1
fi

resolv_symlink() {
    local file tgt
    file=${1}
    if [ ! -L ${file} ] ; then
        echo ${file}
        return
    fi

    tgt=`readlink ${file}`
    case $tgt in
    /*)
        echo $tgt
        return
        ;;
    esac

    file=${file%/*}/${tgt}
    absolute_path ${file}
}

absolute_path() {
    local file myifs target
    file=$1

    myifs=${IFS}
    IFS='/'
    set -- ${file}
    IFS=${myifs}
    for el; do
        case $el in
        .) continue ;;
        '') continue ;;
        ..) target=${target%/*} ;;
        *) target="${target}/${el}" ;;
        esac
    done
    echo ${target}
}

find_dep() {
    pattern=$1
    case ${pattern} in
    *\>*|*\<*|*=*)
        ${PKG_BIN} info -Eg "${pattern}" 2>/dev/null ||
            echo "actual-package-depends: dependency on ${pattern} not registered" >&2
        return
        ;;
    /*)
        searchfile=$pattern
        ;;
    *)
        searchfile=$(/usr/bin/which ${pattern} 2>/dev/null)
        ;;
    esac
    if [ -n "${searchfile}" ]; then
        ${PKG_BIN} which -q ${searchfile} || ${PKG_BIN} which -q "$(resolv_symlink ${searchfile} 2>/dev/null)" ||
            echo "actual-package-depends: dependency on ${searchfile} not registered (normal if it belongs to base)" >&2
    fi
}

for lookup; do
    ${PKG_BIN} query "\"%n\": {origin: \"%o\", version: \"%v\"}" "$(find_dep ${lookup})" || :
done