diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-14 14:33:33 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-15 18:21:46 +0100 |
commit | 82b7504691f70fffb64b206bd1ca1ebc3cd03ac9 (patch) | |
tree | 27a08547a0ebca22628f12d5a80da52c8e552f94 /meta | |
parent | 2501287c69c67579f86b75839a410e5808f528dc (diff) | |
download | poky-82b7504691f70fffb64b206bd1ca1ebc3cd03ac9.tar.gz |
populate_sdk_base: Move toolchain installation script to a separate file
It makes sense to move the script to a separate file, making the bbclass
clearer and allowing the end user to more easily customise or replace
it. There are no functionality changes, just the addition of some
substitution variables.
(From OE-Core rev: f99732a29689c65083ad09abb302f372042c8cd4)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/populate_sdk_base.bbclass | 193 | ||||
-rw-r--r-- | meta/files/toolchain-shar-template.sh | 182 |
2 files changed, 191 insertions, 184 deletions
diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass index 8736942fd2..9e3bd61925 100644 --- a/meta/classes/populate_sdk_base.bbclass +++ b/meta/classes/populate_sdk_base.bbclass | |||
@@ -120,190 +120,15 @@ fakeroot tar_sdk() { | |||
120 | } | 120 | } |
121 | 121 | ||
122 | fakeroot create_shar() { | 122 | fakeroot create_shar() { |
123 | cat << "EOF" > ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh | 123 | # copy in the template shar extractor script |
124 | #!/bin/bash | 124 | cp ${COREBASE}/meta/files/toolchain-shar-template.sh ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh |
125 | 125 | ||
126 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | 126 | # substitute variables |
127 | SDK_ARCH=$(echo ${SDK_ARCH} | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | 127 | sed -i -e 's#@SDK_ARCH@#${SDK_ARCH}#g' \ |
128 | 128 | -e 's#@SDKPATH@#${SDKPATH}#g' \ | |
129 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then | 129 | -e 's#@REAL_MULTIMACH_TARGET_SYS@#${REAL_MULTIMACH_TARGET_SYS}#g' \ |
130 | # Allow for installation of ix86 SDK on x86_64 host | 130 | ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh |
131 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then | 131 | |
132 | echo "Error: Installation machine not supported!" | ||
133 | exit 1 | ||
134 | fi | ||
135 | fi | ||
136 | |||
137 | DEFAULT_INSTALL_DIR="${SDKPATH}" | ||
138 | SUDO_EXEC="" | ||
139 | target_sdk_dir="" | ||
140 | answer="" | ||
141 | relocate=1 | ||
142 | savescripts=0 | ||
143 | verbose=0 | ||
144 | while getopts ":yd:DRS" OPT; do | ||
145 | case $OPT in | ||
146 | y) | ||
147 | answer="Y" | ||
148 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
149 | ;; | ||
150 | d) | ||
151 | target_sdk_dir=$OPTARG | ||
152 | ;; | ||
153 | D) | ||
154 | verbose=1 | ||
155 | ;; | ||
156 | R) | ||
157 | relocate=0 | ||
158 | savescripts=1 | ||
159 | ;; | ||
160 | S) | ||
161 | savescripts=1 | ||
162 | ;; | ||
163 | *) | ||
164 | echo "Usage: $(basename $0) [-y] [-d <dir>]" | ||
165 | echo " -y Automatic yes to all prompts" | ||
166 | echo " -d <dir> Install the SDK to <dir>" | ||
167 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" | ||
168 | echo " -S Save relocation scripts" | ||
169 | echo " -R Do not relocate executables" | ||
170 | echo " -D use set -x to see what is going on" | ||
171 | exit 1 | ||
172 | ;; | ||
173 | esac | ||
174 | done | ||
175 | |||
176 | if [ $verbose = 1 ] ; then | ||
177 | set -x | ||
178 | fi | ||
179 | |||
180 | if [ "$target_sdk_dir" = "" ]; then | ||
181 | read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir | ||
182 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
183 | fi | ||
184 | |||
185 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') | ||
186 | if [ -d "$target_sdk_dir" ]; then | ||
187 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) | ||
188 | else | ||
189 | target_sdk_dir=$(readlink -m "$target_sdk_dir") | ||
190 | fi | ||
191 | |||
192 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then | ||
193 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" | ||
194 | exit 1 | ||
195 | fi | ||
196 | |||
197 | if [ -e "$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}" ]; then | ||
198 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." | ||
199 | printf "If you continue, existing files will be overwritten! Proceed[y/N]?" | ||
200 | |||
201 | default_answer="n" | ||
202 | else | ||
203 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?" | ||
204 | |||
205 | default_answer="y" | ||
206 | fi | ||
207 | |||
208 | if [ "$answer" = "" ]; then | ||
209 | read answer | ||
210 | [ "$answer" = "" ] && answer="$default_answer" | ||
211 | else | ||
212 | echo $answer | ||
213 | fi | ||
214 | |||
215 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | ||
216 | echo "Installation aborted!" | ||
217 | exit 1 | ||
218 | fi | ||
219 | |||
220 | # Try to create the directory (this will not succeed if user doesn't have rights) | ||
221 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
222 | |||
223 | # if don't have the right to access dir, gain by sudo | ||
224 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then | ||
225 | SUDO_EXEC=$(which "sudo") | ||
226 | if [ -z $SUDO_EXEC ]; then | ||
227 | echo "No command 'sudo' found, please install sudo first. Abort!" | ||
228 | exit 1 | ||
229 | fi | ||
230 | |||
231 | # test sudo could gain root right | ||
232 | $SUDO_EXEC pwd >/dev/null 2>&1 | ||
233 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 | ||
234 | |||
235 | # now that we have sudo rights, create the directory | ||
236 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
237 | fi | ||
238 | |||
239 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | ||
240 | |||
241 | printf "Extracting SDK..." | ||
242 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir | ||
243 | echo "done" | ||
244 | |||
245 | printf "Setting it up..." | ||
246 | # fix environment paths | ||
247 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do | ||
248 | $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script | ||
249 | done | ||
250 | |||
251 | # fix dynamic loader paths in all ELF SDK binaries | ||
252 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') | ||
253 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") | ||
254 | if [ "$dl_path" = "" ] ; then | ||
255 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" | ||
256 | exit 1 | ||
257 | fi | ||
258 | executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -printf "'%h/%f' ") | ||
259 | |||
260 | tdir=`mktemp -d` | ||
261 | if [ x$tdir = x ] ; then | ||
262 | echo "SDK relocate failed, could not create a temporary directory" | ||
263 | exit 1 | ||
264 | fi | ||
265 | echo "#!/bin/bash" > $tdir/relocate_sdk.sh | ||
266 | echo exec ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files >> $tdir/relocate_sdk.sh | ||
267 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh | ||
268 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh | ||
269 | rm -rf $tdir | ||
270 | if [ $relocate = 1 ] ; then | ||
271 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh | ||
272 | if [ $? -ne 0 ]; then | ||
273 | echo "SDK could not be set up. Relocate script failed. Abort!" | ||
274 | exit 1 | ||
275 | fi | ||
276 | fi | ||
277 | |||
278 | # replace ${SDKPATH} with the new prefix in all text files: configs/scripts/etc | ||
279 | $SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep ":.*\(ASCII\|script\|source\).*text"|awk -F':' '{printf "%s\0", $1}'|$SUDO_EXEC xargs -0 sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" | ||
280 | |||
281 | # change all symlinks pointing to ${SDKPATH} | ||
282 | for l in $($SUDO_EXEC find $native_sysroot -type l); do | ||
283 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l | ||
284 | done | ||
285 | |||
286 | # find out all perl scripts in $native_sysroot and modify them replacing the | ||
287 | # host perl with SDK perl. | ||
288 | for perl_script in $($SUDO_EXEC find $native_sysroot -type f -exec grep "^#!.*perl" -l '{}' \;); do | ||
289 | $SUDO_EXEC sed -i -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" -e \ | ||
290 | "s: /usr/bin/perl: /usr/bin/env perl:g" $perl_script | ||
291 | done | ||
292 | |||
293 | echo done | ||
294 | |||
295 | # delete the relocating script, so that user is forced to re-run the installer | ||
296 | # if he/she wants another location for the sdk | ||
297 | if [ $savescripts = 0 ] ; then | ||
298 | $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh | ||
299 | fi | ||
300 | |||
301 | echo "SDK has been successfully set up and is ready to be used." | ||
302 | |||
303 | exit 0 | ||
304 | |||
305 | MARKER: | ||
306 | EOF | ||
307 | # add execution permission | 132 | # add execution permission |
308 | chmod +x ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh | 133 | chmod +x ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh |
309 | 134 | ||
diff --git a/meta/files/toolchain-shar-template.sh b/meta/files/toolchain-shar-template.sh new file mode 100644 index 0000000000..a6207bbd4d --- /dev/null +++ b/meta/files/toolchain-shar-template.sh | |||
@@ -0,0 +1,182 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
4 | SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
5 | |||
6 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then | ||
7 | # Allow for installation of ix86 SDK on x86_64 host | ||
8 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then | ||
9 | echo "Error: Installation machine not supported!" | ||
10 | exit 1 | ||
11 | fi | ||
12 | fi | ||
13 | |||
14 | DEFAULT_INSTALL_DIR="@SDKPATH@" | ||
15 | SUDO_EXEC="" | ||
16 | target_sdk_dir="" | ||
17 | answer="" | ||
18 | relocate=1 | ||
19 | savescripts=0 | ||
20 | verbose=0 | ||
21 | while getopts ":yd:DRS" OPT; do | ||
22 | case $OPT in | ||
23 | y) | ||
24 | answer="Y" | ||
25 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
26 | ;; | ||
27 | d) | ||
28 | target_sdk_dir=$OPTARG | ||
29 | ;; | ||
30 | D) | ||
31 | verbose=1 | ||
32 | ;; | ||
33 | R) | ||
34 | relocate=0 | ||
35 | savescripts=1 | ||
36 | ;; | ||
37 | S) | ||
38 | savescripts=1 | ||
39 | ;; | ||
40 | *) | ||
41 | echo "Usage: $(basename $0) [-y] [-d <dir>]" | ||
42 | echo " -y Automatic yes to all prompts" | ||
43 | echo " -d <dir> Install the SDK to <dir>" | ||
44 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" | ||
45 | echo " -S Save relocation scripts" | ||
46 | echo " -R Do not relocate executables" | ||
47 | echo " -D use set -x to see what is going on" | ||
48 | exit 1 | ||
49 | ;; | ||
50 | esac | ||
51 | done | ||
52 | |||
53 | if [ $verbose = 1 ] ; then | ||
54 | set -x | ||
55 | fi | ||
56 | |||
57 | if [ "$target_sdk_dir" = "" ]; then | ||
58 | read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir | ||
59 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
60 | fi | ||
61 | |||
62 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') | ||
63 | if [ -d "$target_sdk_dir" ]; then | ||
64 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) | ||
65 | else | ||
66 | target_sdk_dir=$(readlink -m "$target_sdk_dir") | ||
67 | fi | ||
68 | |||
69 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then | ||
70 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" | ||
71 | exit 1 | ||
72 | fi | ||
73 | |||
74 | if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then | ||
75 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." | ||
76 | printf "If you continue, existing files will be overwritten! Proceed[y/N]?" | ||
77 | |||
78 | default_answer="n" | ||
79 | else | ||
80 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?" | ||
81 | |||
82 | default_answer="y" | ||
83 | fi | ||
84 | |||
85 | if [ "$answer" = "" ]; then | ||
86 | read answer | ||
87 | [ "$answer" = "" ] && answer="$default_answer" | ||
88 | else | ||
89 | echo $answer | ||
90 | fi | ||
91 | |||
92 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | ||
93 | echo "Installation aborted!" | ||
94 | exit 1 | ||
95 | fi | ||
96 | |||
97 | # Try to create the directory (this will not succeed if user doesn't have rights) | ||
98 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
99 | |||
100 | # if don't have the right to access dir, gain by sudo | ||
101 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then | ||
102 | SUDO_EXEC=$(which "sudo") | ||
103 | if [ -z $SUDO_EXEC ]; then | ||
104 | echo "No command 'sudo' found, please install sudo first. Abort!" | ||
105 | exit 1 | ||
106 | fi | ||
107 | |||
108 | # test sudo could gain root right | ||
109 | $SUDO_EXEC pwd >/dev/null 2>&1 | ||
110 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 | ||
111 | |||
112 | # now that we have sudo rights, create the directory | ||
113 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
114 | fi | ||
115 | |||
116 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | ||
117 | |||
118 | printf "Extracting SDK..." | ||
119 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir | ||
120 | echo "done" | ||
121 | |||
122 | printf "Setting it up..." | ||
123 | # fix environment paths | ||
124 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do | ||
125 | $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script | ||
126 | done | ||
127 | |||
128 | # fix dynamic loader paths in all ELF SDK binaries | ||
129 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') | ||
130 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") | ||
131 | if [ "$dl_path" = "" ] ; then | ||
132 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" | ||
133 | exit 1 | ||
134 | fi | ||
135 | executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -printf "'%h/%f' ") | ||
136 | |||
137 | tdir=`mktemp -d` | ||
138 | if [ x$tdir = x ] ; then | ||
139 | echo "SDK relocate failed, could not create a temporary directory" | ||
140 | exit 1 | ||
141 | fi | ||
142 | echo "#!/bin/bash" > $tdir/relocate_sdk.sh | ||
143 | echo exec ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files >> $tdir/relocate_sdk.sh | ||
144 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh | ||
145 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh | ||
146 | rm -rf $tdir | ||
147 | if [ $relocate = 1 ] ; then | ||
148 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh | ||
149 | if [ $? -ne 0 ]; then | ||
150 | echo "SDK could not be set up. Relocate script failed. Abort!" | ||
151 | exit 1 | ||
152 | fi | ||
153 | fi | ||
154 | |||
155 | # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc | ||
156 | $SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep ":.*\(ASCII\|script\|source\).*text"|awk -F':' '{printf "%s\0", $1}'|$SUDO_EXEC xargs -0 sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" | ||
157 | |||
158 | # change all symlinks pointing to @SDKPATH@ | ||
159 | for l in $($SUDO_EXEC find $native_sysroot -type l); do | ||
160 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l | ||
161 | done | ||
162 | |||
163 | # find out all perl scripts in $native_sysroot and modify them replacing the | ||
164 | # host perl with SDK perl. | ||
165 | for perl_script in $($SUDO_EXEC find $native_sysroot -type f -exec grep "^#!.*perl" -l '{}' \;); do | ||
166 | $SUDO_EXEC sed -i -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" -e \ | ||
167 | "s: /usr/bin/perl: /usr/bin/env perl:g" $perl_script | ||
168 | done | ||
169 | |||
170 | echo done | ||
171 | |||
172 | # delete the relocating script, so that user is forced to re-run the installer | ||
173 | # if he/she wants another location for the sdk | ||
174 | if [ $savescripts = 0 ] ; then | ||
175 | $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh | ||
176 | fi | ||
177 | |||
178 | echo "SDK has been successfully set up and is ready to be used." | ||
179 | |||
180 | exit 0 | ||
181 | |||
182 | MARKER: | ||