-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmksysroot
executable file
·148 lines (113 loc) · 3.6 KB
/
mksysroot
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /bin/bash
#
# This software is dedicated to Public Domain and, as such, bears no
# copyright. Please see LICENSE file for details.
#
function do_help() {
cat <<EOT
Usage:
$(basename $0) options <ssh-host> <sysroot-name>
Where,
<ssh-host>
is SSH connection string in form of [user@]server:
and it should connecto to the RaspberryPi for which
you are creating the sysroot.
<sysroot-name>
is the name to giv the sysroot. It is good idea to
give sysroots unique names such that to minimize
possibility of conflicts when using multiple sysroots
in a project.
options is one or more of the following:
-h display this text
-v produce verbose output
-f force overwriting of existing sysroot
EOT
}
function _error() {
echo "$@" >&2
}
function _info() {
if [[ $verbose == 1 ]]; then
echo "$@"
fi
}
echo "RaspberryPi sysroot creation script"
verbose=
force=
our_dir=$(dirname $0)
while getopts "hvf" OPTION "$@"; do
case $OPTION in
h) do_help
exit 1;;
v) verbose=1;;
f) force=1;;
*) _error "Unrecognized option $OPTION. Use -h for help."
exit 2;;
esac
done
shift $((OPTIND - 1))
ssh_host="$1"
sysroot_name="$2"
if [[ -z $ssh_host ]]; then
_error "SSH host parameter is missing. Use -h for help"
exit 2
fi
if [[ -z $sysroot_name ]]; then
_error "Sysroot name parameter is missing. Use -h for help"
exit 2
fi
#
# Make sure the destination directory is ready
#
sysroot_dir="$sysroot_name/sysroot"
sysroot_test="$sysroot_name/test"
if [[ -d "$sysroot_name" ]]; then
if [[ $force != 1 ]]; then
_error "Sysroot directory $sysroot_name already exists. Use -f to overwrite"
exit 3
else
_info "Cleaning up $sysroot_dir because -f specified"
[[ -d "$sysroot_dir" ]] && rm -r "$sysroot_dir" || exit $?
_info "Cleaning up $sysroot_test because -f specified"
[[ -d "$sysroot_test" ]] && rm -r "$sysroot_test" || exit $?
fi
else
_info "Creating directory $sysroot_name"
mkdir "$sysroot_name" || exit $?
fi
_info "Creating directory $sysroot_dir"
mkdir "$sysroot_dir" || exit $?
_info "Creating directory $sysroot_test"
mkdir "$sysroot_test" || exit $?
#
# Everything is prepared - copy sysroot from target
#
echo Copying sysroot files via rsync will take a while. Exercise patience..."
tripple=arm-linux-gnueabihf
_info "Copying sysroot files from $ssh_host"
rsync -rzLR --safe-links $ssh_host{/usr/lib/$tripple,/usr/lib/gcc/$tripple,/usr/include,/lib/$tripple} "$sysroot_dir/"
[[ $? == 0 ]] || exit $?
# This is quite a heuristic (a.k.a. a hack) to find this, but it works for me
_info "Finding the latest GCC version in sysroot"
gcc_dir=$(
for gcc_dir in $(find "$sysroot_dir/usr/include/c++" -type d -depth 1); do
if [[ $(ls -1 "$gcc_dir" | wc -l | sed -e 's/ //g') != 0 ]]; then
echo "$gcc_dir"
fi
done | sort -r | head -n 1
) || exit $?
if [[ -z $gcc_dir ]]; then
_error "Could not determine GCC version in the $sysroot_dir"
exit 4
fi
gcc_version=$(basename "$gcc_dir")
if [[ ! -d "$sysroot_dir/usr/include/c++/$gcc_version" ]]; then
_error "Something is very wrong - either a bug in this script or sysroot layout changed"
_error "GCC version '$gcc_version' not found in '$sysroot_dir/usr/include/c++'"
exit 5
fi
_info "Creating $sysroot_name/RPi.mk Makefile"
cat "$our_dir/RPiTemplate.mk" | sed -e "s/GCC_Version/$gcc_version/g;s/RPiTemplate_/${sysroot_name}_/g" > "$sysroot_name/RPi.mk"
_info "Creating test project"
cp -r "$our_dir/test" "$sysroot_name/" || exit $?
echo "Sysroot $sysroot_name created"