Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | if ! xargs --version > /dev/null 2>&1; then |
| 2 | echo "xargs is required by the relocation script, please install it first. Abort!" |
| 3 | exit 1 |
| 4 | fi |
| 5 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # fix dynamic loader paths in all ELF SDK binaries |
| 7 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') |
| 8 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") |
| 9 | if [ "$dl_path" = "" ] ; then |
| 10 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" |
| 11 | exit 1 |
| 12 | fi |
| 13 | executable_files=$($SUDO_EXEC find $native_sysroot -type f \ |
| 14 | \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | if [ "x$executable_files" = "x" ]; then |
| 16 | echo "SDK relocate failed, could not get executalbe files" |
| 17 | exit 1 |
| 18 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | |
| 20 | tdir=`mktemp -d` |
| 21 | if [ x$tdir = x ] ; then |
| 22 | echo "SDK relocate failed, could not create a temporary directory" |
| 23 | exit 1 |
| 24 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 25 | cat <<EOF >> $tdir/relocate_sdk.sh |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | #!/bin/sh |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 27 | for py in python python2 python3 |
| 28 | do |
| 29 | PYTHON=\`which \${py} 2>/dev/null\` |
| 30 | if [ \$? -eq 0 ]; then |
| 31 | break; |
| 32 | fi |
| 33 | done |
| 34 | |
| 35 | if [ x\${PYTHON} = "x" ]; then |
| 36 | echo "SDK could not be relocated. No python found." |
| 37 | exit 1 |
| 38 | fi |
| 39 | \${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files |
| 40 | EOF |
| 41 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh |
| 43 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh |
| 44 | rm -rf $tdir |
| 45 | if [ $relocate = 1 ] ; then |
| 46 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh |
| 47 | if [ $? -ne 0 ]; then |
| 48 | echo "SDK could not be set up. Relocate script failed. Abort!" |
| 49 | exit 1 |
| 50 | fi |
| 51 | fi |
| 52 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 53 | # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc. |
| 54 | # replace the host perl with SDK perl. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 56 | $SUDO_EXEC find $replace -type f |
| 57 | done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 58 | awk -F': ' '{printf "\"%s\"\n", $1}' | \ |
| 59 | grep -Fv -e "$target_sdk_dir/environment-setup-" \ |
| 60 | -e "$target_sdk_dir/relocate_sdk" \ |
| 61 | -e "$target_sdk_dir/post-relocate-setup" \ |
| 62 | -e "$target_sdk_dir/${0##*/}" | \ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 63 | xargs -n100 $SUDO_EXEC sed -i \ |
| 64 | -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" \ |
| 65 | -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \ |
| 66 | -e "s: /usr/bin/perl: /usr/bin/env perl:g" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | if [ $? -ne 0 ]; then |
| 69 | echo "Failed to replace perl. Relocate script failed. Abort!" |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | # change all symlinks pointing to @SDKPATH@ |
| 74 | for l in $($SUDO_EXEC find $native_sysroot -type l); do |
| 75 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 76 | if [ $? -ne 0 ]; then |
| 77 | echo "Failed to setup symlinks. Relocate script failed. Abort!" |
| 78 | exit 1 |
| 79 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | done |
| 81 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | echo done |