~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/check/funcs.sh

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# has is the same as which, except it handles cross environments
 
2
has() {
 
3
        if [ -z "$CROSS_COMPILE" ]; then
 
4
                command which "$@"
 
5
                return $?
 
6
        fi
 
7
 
 
8
        check_sys_root || return 1
 
9
 
 
10
        # subshell to prevent pollution of caller's IFS
 
11
        (
 
12
        IFS=:
 
13
        for p in $PATH; do
 
14
                if [ -x "$CROSS_SYS_ROOT/$p/$1" ]; then
 
15
                        echo "$CROSS_SYS_ROOT/$p/$1"
 
16
                        return 0
 
17
                fi
 
18
        done
 
19
        return 1
 
20
        )
 
21
}
 
22
 
 
23
has_or_fail() {
 
24
        has "$1" >/dev/null || fail "can't find $1"
 
25
}
 
26
 
 
27
has_header() {
 
28
        case $1 in
 
29
                /*) ;;
 
30
                *) set -- "/usr/include/$1" ;;
 
31
        esac
 
32
 
 
33
        check_sys_root || return 1
 
34
 
 
35
        test -r "$CROSS_SYS_ROOT$1"
 
36
        return $?
 
37
}
 
38
 
 
39
has_lib() {
 
40
        check_sys_root || return 1
 
41
 
 
42
        # subshell to prevent pollution of caller's environment
 
43
        (
 
44
        PATH=/sbin:$PATH        # for ldconfig
 
45
 
 
46
        # This relatively common in a sys-root; libs are installed but
 
47
        # ldconfig hasn't run there, so ldconfig -p won't work.
 
48
        if [ "$OS" = Linux -a ! -f "$CROSS_SYS_ROOT/etc/ld.so.cache" ]; then
 
49
            echo "Please run ldconfig -r \"$CROSS_SYS_ROOT\" to generate ld.so.cache"
 
50
            # fall through; ldconfig test below should fail
 
51
        fi
 
52
        ldconfig -p ${CROSS_SYS_ROOT+-r "$CROSS_SYS_ROOT"} | grep -Fq "$1"
 
53
        return $?
 
54
        )
 
55
}
 
56
 
 
57
test_link() {
 
58
        # subshell to trap removal of tmpfile
 
59
        (
 
60
        unset tmpfile
 
61
        trap 'rm -f "$tmpfile"; exit' 0 1 2 15
 
62
        tmpfile=`mktemp` || return 1
 
63
        ld "$@" -o "$tmpfile" >/dev/null 2>&1
 
64
        return $?
 
65
        )
 
66
}
 
67
 
 
68
# this function is used commonly above
 
69
check_sys_root() {
 
70
        [ -z "$CROSS_COMPILE" ] && return 0
 
71
        if [ -z "$CROSS_SYS_ROOT" ]; then
 
72
                echo "please set CROSS_SYS_ROOT in the environment"
 
73
                return 1
 
74
        fi
 
75
        if [ ! -d "$CROSS_SYS_ROOT" ]; then
 
76
                echo "no sys-root found at $CROSS_SYS_ROOT"
 
77
                return 1
 
78
        fi
 
79
}
 
80
 
 
81
warning() {
 
82
        echo
 
83
        echo " *** `basename "$0"` FAILED${*+: $*}"
 
84
}
 
85
 
 
86
fail() {
 
87
        echo
 
88
        echo " *** `basename "$0"` FAILED${*+: $*}"
 
89
        exit 1
 
90
}