forked from adapteva/epiphany-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common-functions
101 lines (70 loc) · 2.12 KB
/
common-functions
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
################################################################################
# #
# Shell functions #
# #
################################################################################
# Function to check for relative directory and makes it absolute
# @param[in] $1 The directory to make absolute if necessary.
absdir() {
case ${1} in
/*)
echo "${1}"
;;
*)
echo "${PWD}/${1}"
;;
esac
}
# Check a component directory exists in the basedir
# @param[in] $1 the directory to check
# @return 0 (success) if the directory is there and readable, 1 (failure)
# otherwise.
check_dir_exists () {
if [ ! -d "${basedir}/${1}" ]
then
logterm "ERROR: Component directory ${basedir}/${1} missing."
return 1
fi
}
# Check if toolchain is present.
# @param[in] $1 Toolchain prefix
# @return Returns 0 on success. Anything else indicates failure.
check_toolchain () {
local prefix
prefix=$1
(which ${prefix}gcc && which ${prefix}as &&
which ${prefix}ld && which ${prefix}ar) >/dev/null
}
# Convenience function to copy a message to the log and terminal
# @param[in] $1 The message to log
logterm () {
echo $1 | tee -a ${logfile}
}
# Convenience function to copy a message to the log only
# @param[in] $1 The message to log
logonly () {
echo $1 >> ${logfile}
}
# Get the architecture from a triplet.
# This is the first field up to -, but with "arm" translated to "armv7l".
# @param[in] $1 triplet
# @return The architecture of the triplet, but with arm translated to armv7l.
getarch () {
triplet=$1
if [ "x${triplet}" = "x" ]
then
arch=$(uname -m)
else
arch=`echo $triplet | sed -e 's/^\([^-]*\).*$/\1/'`
fi
if [ "x${arch}" = "xarm" ]
then
arch="armv7l"
fi
echo ${arch}
}
# Convenience function to exit with a suitable message.
failedbuild () {
echo "Build failed. See ${logfile} for details."
exit 1
}