summaryrefslogtreecommitdiffstats
path: root/meta/files
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-14 13:33:33 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-15 17:21:46 (GMT)
commit82b7504691f70fffb64b206bd1ca1ebc3cd03ac9 (patch)
tree27a08547a0ebca22628f12d5a80da52c8e552f94 /meta/files
parent2501287c69c67579f86b75839a410e5808f528dc (diff)
downloadpoky-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/files')
-rw-r--r--meta/files/toolchain-shar-template.sh182
1 files changed, 182 insertions, 0 deletions
diff --git a/meta/files/toolchain-shar-template.sh b/meta/files/toolchain-shar-template.sh
new file mode 100644
index 0000000..a6207bb
--- /dev/null
+++ b/meta/files/toolchain-shar-template.sh
@@ -0,0 +1,182 @@
1#!/bin/bash
2
3INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
4SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
5
6if [ "$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
12fi
13
14DEFAULT_INSTALL_DIR="@SDKPATH@"
15SUDO_EXEC=""
16target_sdk_dir=""
17answer=""
18relocate=1
19savescripts=0
20verbose=0
21while 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
51done
52
53if [ $verbose = 1 ] ; then
54 set -x
55fi
56
57if [ "$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
60fi
61
62eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
63if [ -d "$target_sdk_dir" ]; then
64 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
65else
66 target_sdk_dir=$(readlink -m "$target_sdk_dir")
67fi
68
69if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
70 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
71 exit 1
72fi
73
74if [ -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"
79else
80 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?"
81
82 default_answer="y"
83fi
84
85if [ "$answer" = "" ]; then
86 read answer
87 [ "$answer" = "" ] && answer="$default_answer"
88else
89 echo $answer
90fi
91
92if [ "$answer" != "Y" -a "$answer" != "y" ]; then
93 echo "Installation aborted!"
94 exit 1
95fi
96
97# Try to create the directory (this will not succeed if user doesn't have rights)
98mkdir -p $target_sdk_dir >/dev/null 2>&1
99
100# if don't have the right to access dir, gain by sudo
101if [ ! -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
114fi
115
116payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
117
118printf "Extracting SDK..."
119tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir
120echo "done"
121
122printf "Setting it up..."
123# fix environment paths
124for 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
126done
127
128# fix dynamic loader paths in all ELF SDK binaries
129native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
130dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
131if [ "$dl_path" = "" ] ; then
132 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
133 exit 1
134fi
135executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -printf "'%h/%f' ")
136
137tdir=`mktemp -d`
138if [ x$tdir = x ] ; then
139 echo "SDK relocate failed, could not create a temporary directory"
140 exit 1
141fi
142echo "#!/bin/bash" > $tdir/relocate_sdk.sh
143echo 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
146rm -rf $tdir
147if [ $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
153fi
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@
159for 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
161done
162
163# find out all perl scripts in $native_sysroot and modify them replacing the
164# host perl with SDK perl.
165for 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
168done
169
170echo 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
174if [ $savescripts = 0 ] ; then
175 $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
176fi
177
178echo "SDK has been successfully set up and is ready to be used."
179
180exit 0
181
182MARKER: