blob: d4bcf0e55d2f92799afa66400b457ca6ad66559f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# fix dynamic loader paths in all ELF SDK binaries
2native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
3dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
4if [ "$dl_path" = "" ] ; then
5 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
6 exit 1
7fi
8executable_files=$($SUDO_EXEC find $native_sysroot -type f \
9 \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
10
11tdir=`mktemp -d`
12if [ x$tdir = x ] ; then
13 echo "SDK relocate failed, could not create a temporary directory"
14 exit 1
15fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016cat <<EOF >> $tdir/relocate_sdk.sh
17#!/bin/bash
18for py in python python2 python3
19do
20 PYTHON=\`which \${py} 2>/dev/null\`
21 if [ \$? -eq 0 ]; then
22 break;
23 fi
24done
25
26if [ x\${PYTHON} = "x" ]; then
27 echo "SDK could not be relocated. No python found."
28 exit 1
29fi
30\${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files
31EOF
32
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033$SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh
34$SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh
35rm -rf $tdir
36if [ $relocate = 1 ] ; then
37 $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh
38 if [ $? -ne 0 ]; then
39 echo "SDK could not be set up. Relocate script failed. Abort!"
40 exit 1
41 fi
42fi
43
Patrick Williamsf1e5d692016-03-30 15:21:19 -050044# replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
45# replace the host perl with SDK perl.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -050047 $SUDO_EXEC find $replace -type f
48done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \
49 awk -F':' '{printf "\"%s\"\n", $1}' | \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 grep -Ev "$target_sdk_dir/(environment-setup-*|relocate_sdk*|${0##*/})" | \
Patrick Williamsf1e5d692016-03-30 15:21:19 -050051 xargs -n100 $SUDO_EXEC sed -i \
52 -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" \
53 -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
54 -e "s: /usr/bin/perl: /usr/bin/env perl:g"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
56# change all symlinks pointing to @SDKPATH@
57for l in $($SUDO_EXEC find $native_sysroot -type l); do
58 $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l
59done
60
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061echo done