diff options
Diffstat (limited to 'meta/files/toolchain-shar-template.sh')
-rw-r--r-- | meta/files/toolchain-shar-template.sh | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/meta/files/toolchain-shar-template.sh b/meta/files/toolchain-shar-template.sh deleted file mode 100644 index 151b973d35..0000000000 --- a/meta/files/toolchain-shar-template.sh +++ /dev/null | |||
@@ -1,205 +0,0 @@ | |||
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 | verlte () { | ||
7 | [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ] | ||
8 | } | ||
9 | |||
10 | verlt() { | ||
11 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
12 | } | ||
13 | |||
14 | verlt `uname -r` @OLDEST_KERNEL@ | ||
15 | if [ $? = 0 ]; then | ||
16 | echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@" | ||
17 | exit 1 | ||
18 | fi | ||
19 | |||
20 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then | ||
21 | # Allow for installation of ix86 SDK on x86_64 host | ||
22 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then | ||
23 | echo "Error: Installation machine not supported!" | ||
24 | exit 1 | ||
25 | fi | ||
26 | fi | ||
27 | |||
28 | DEFAULT_INSTALL_DIR="@SDKPATH@" | ||
29 | SUDO_EXEC="" | ||
30 | target_sdk_dir="" | ||
31 | answer="" | ||
32 | relocate=1 | ||
33 | savescripts=0 | ||
34 | verbose=0 | ||
35 | while getopts ":yd:DRS" OPT; do | ||
36 | case $OPT in | ||
37 | y) | ||
38 | answer="Y" | ||
39 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
40 | ;; | ||
41 | d) | ||
42 | target_sdk_dir=$OPTARG | ||
43 | ;; | ||
44 | D) | ||
45 | verbose=1 | ||
46 | ;; | ||
47 | R) | ||
48 | relocate=0 | ||
49 | savescripts=1 | ||
50 | ;; | ||
51 | S) | ||
52 | savescripts=1 | ||
53 | ;; | ||
54 | *) | ||
55 | echo "Usage: $(basename $0) [-y] [-d <dir>]" | ||
56 | echo " -y Automatic yes to all prompts" | ||
57 | echo " -d <dir> Install the SDK to <dir>" | ||
58 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" | ||
59 | echo " -S Save relocation scripts" | ||
60 | echo " -R Do not relocate executables" | ||
61 | echo " -D use set -x to see what is going on" | ||
62 | exit 1 | ||
63 | ;; | ||
64 | esac | ||
65 | done | ||
66 | |||
67 | if [ $verbose = 1 ] ; then | ||
68 | set -x | ||
69 | fi | ||
70 | |||
71 | if [ "$target_sdk_dir" = "" ]; then | ||
72 | read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir | ||
73 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
74 | fi | ||
75 | |||
76 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') | ||
77 | if [ -d "$target_sdk_dir" ]; then | ||
78 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) | ||
79 | else | ||
80 | target_sdk_dir=$(readlink -m "$target_sdk_dir") | ||
81 | fi | ||
82 | |||
83 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then | ||
84 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" | ||
85 | exit 1 | ||
86 | fi | ||
87 | |||
88 | if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then | ||
89 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." | ||
90 | printf "If you continue, existing files will be overwritten! Proceed[y/N]?" | ||
91 | |||
92 | default_answer="n" | ||
93 | else | ||
94 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?" | ||
95 | |||
96 | default_answer="y" | ||
97 | fi | ||
98 | |||
99 | if [ "$answer" = "" ]; then | ||
100 | read answer | ||
101 | [ "$answer" = "" ] && answer="$default_answer" | ||
102 | else | ||
103 | echo $answer | ||
104 | fi | ||
105 | |||
106 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | ||
107 | echo "Installation aborted!" | ||
108 | exit 1 | ||
109 | fi | ||
110 | |||
111 | # Try to create the directory (this will not succeed if user doesn't have rights) | ||
112 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
113 | |||
114 | # if don't have the right to access dir, gain by sudo | ||
115 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then | ||
116 | SUDO_EXEC=$(which "sudo") | ||
117 | if [ -z $SUDO_EXEC ]; then | ||
118 | echo "No command 'sudo' found, please install sudo first. Abort!" | ||
119 | exit 1 | ||
120 | fi | ||
121 | |||
122 | # test sudo could gain root right | ||
123 | $SUDO_EXEC pwd >/dev/null 2>&1 | ||
124 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 | ||
125 | |||
126 | # now that we have sudo rights, create the directory | ||
127 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
128 | fi | ||
129 | |||
130 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | ||
131 | |||
132 | printf "Extracting SDK..." | ||
133 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir | ||
134 | echo "done" | ||
135 | |||
136 | printf "Setting it up..." | ||
137 | # fix environment paths | ||
138 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do | ||
139 | $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script | ||
140 | done | ||
141 | |||
142 | # fix dynamic loader paths in all ELF SDK binaries | ||
143 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') | ||
144 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") | ||
145 | if [ "$dl_path" = "" ] ; then | ||
146 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" | ||
147 | exit 1 | ||
148 | fi | ||
149 | executable_files=$($SUDO_EXEC find $native_sysroot -type f \ | ||
150 | \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ") | ||
151 | |||
152 | tdir=`mktemp -d` | ||
153 | if [ x$tdir = x ] ; then | ||
154 | echo "SDK relocate failed, could not create a temporary directory" | ||
155 | exit 1 | ||
156 | fi | ||
157 | echo "#!/bin/bash" > $tdir/relocate_sdk.sh | ||
158 | echo exec ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files >> $tdir/relocate_sdk.sh | ||
159 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh | ||
160 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh | ||
161 | rm -rf $tdir | ||
162 | if [ $relocate = 1 ] ; then | ||
163 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh | ||
164 | if [ $? -ne 0 ]; then | ||
165 | echo "SDK could not be set up. Relocate script failed. Abort!" | ||
166 | exit 1 | ||
167 | fi | ||
168 | fi | ||
169 | |||
170 | # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc | ||
171 | for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do | ||
172 | $SUDO_EXEC find $replace -type f -exec file '{}' \; | \ | ||
173 | grep ":.*\(ASCII\|script\|source\).*text" | \ | ||
174 | awk -F':' '{printf "\"%s\"\n", $1}' | \ | ||
175 | grep -v "$target_sdk_dir/environment-setup-*" | \ | ||
176 | $SUDO_EXEC xargs -n32 sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" | ||
177 | done | ||
178 | |||
179 | # change all symlinks pointing to @SDKPATH@ | ||
180 | for l in $($SUDO_EXEC find $native_sysroot -type l); do | ||
181 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l | ||
182 | done | ||
183 | |||
184 | # find out all perl scripts in $native_sysroot and modify them replacing the | ||
185 | # host perl with SDK perl. | ||
186 | for perl_script in $($SUDO_EXEC find $native_sysroot -type f -exec grep -l "^#!.*perl" '{}' \;); do | ||
187 | $SUDO_EXEC sed -i -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" -e \ | ||
188 | "s: /usr/bin/perl: /usr/bin/env perl:g" $perl_script | ||
189 | done | ||
190 | |||
191 | echo done | ||
192 | |||
193 | @SDK_POST_INSTALL_COMMAND@ | ||
194 | |||
195 | # delete the relocating script, so that user is forced to re-run the installer | ||
196 | # if he/she wants another location for the sdk | ||
197 | if [ $savescripts = 0 ] ; then | ||
198 | $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh | ||
199 | fi | ||
200 | |||
201 | echo "SDK has been successfully set up and is ready to be used." | ||
202 | |||
203 | exit 0 | ||
204 | |||
205 | MARKER: | ||