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