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