Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # fix dynamic loader paths in all ELF SDK binaries |
| 2 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') |
| 3 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") |
| 4 | if [ "$dl_path" = "" ] ; then |
| 5 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" |
| 6 | exit 1 |
| 7 | fi |
| 8 | executable_files=$($SUDO_EXEC find $native_sysroot -type f \ |
| 9 | \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ") |
| 10 | |
| 11 | tdir=`mktemp -d` |
| 12 | if [ x$tdir = x ] ; then |
| 13 | echo "SDK relocate failed, could not create a temporary directory" |
| 14 | exit 1 |
| 15 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 16 | cat <<EOF >> $tdir/relocate_sdk.sh |
| 17 | #!/bin/bash |
| 18 | for py in python python2 python3 |
| 19 | do |
| 20 | PYTHON=\`which \${py} 2>/dev/null\` |
| 21 | if [ \$? -eq 0 ]; then |
| 22 | break; |
| 23 | fi |
| 24 | done |
| 25 | |
| 26 | if [ x\${PYTHON} = "x" ]; then |
| 27 | echo "SDK could not be relocated. No python found." |
| 28 | exit 1 |
| 29 | fi |
| 30 | \${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files |
| 31 | EOF |
| 32 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh |
| 34 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh |
| 35 | rm -rf $tdir |
| 36 | if [ $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 |
| 42 | fi |
| 43 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 44 | # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc. |
| 45 | # replace the host perl with SDK perl. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 47 | $SUDO_EXEC find $replace -type f |
| 48 | done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \ |
| 49 | awk -F':' '{printf "\"%s\"\n", $1}' | \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | grep -Ev "$target_sdk_dir/(environment-setup-*|relocate_sdk*|${0##*/})" | \ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 51 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | |
| 56 | # change all symlinks pointing to @SDKPATH@ |
| 57 | for 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 |
| 59 | done |
| 60 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | echo done |