blob: e8ab357717f3235a02ac939567223c5c7253c54e [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001if ! xargs --version > /dev/null 2>&1; then
2 echo "xargs is required by the relocation script, please install it first. Abort!"
3 exit 1
4fi
5
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006# fix dynamic loader paths in all ELF SDK binaries
Patrick Williams73bd93f2024-02-20 08:07:48 -06007# allow symlinks to be accessed via the find command too
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
Patrick Williams73bd93f2024-02-20 08:07:48 -06009dl_path=$($SUDO_EXEC find $native_sysroot/lib/ -maxdepth 1 -name "ld-linux*")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010if [ "$dl_path" = "" ] ; then
11 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
12 exit 1
13fi
14executable_files=$($SUDO_EXEC find $native_sysroot -type f \
15 \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060016if [ "x$executable_files" = "x" ]; then
17 echo "SDK relocate failed, could not get executalbe files"
18 exit 1
19fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
21tdir=`mktemp -d`
22if [ x$tdir = x ] ; then
23 echo "SDK relocate failed, could not create a temporary directory"
24 exit 1
25fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026cat <<EOF >> $tdir/relocate_sdk.sh
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027#!/bin/sh
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028for py in python python2 python3
29do
30 PYTHON=\`which \${py} 2>/dev/null\`
31 if [ \$? -eq 0 ]; then
32 break;
33 fi
34done
35
36if [ x\${PYTHON} = "x" ]; then
37 echo "SDK could not be relocated. No python found."
38 exit 1
39fi
40\${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files
41EOF
42
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043$SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh
44$SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh
45rm -rf $tdir
46if [ $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
52fi
53
Patrick Williamsf1e5d692016-03-30 15:21:19 -050054# replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
55# replace the host perl with SDK perl.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -050057 $SUDO_EXEC find $replace -type f
58done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \
Andrew Geisslerd1e89492021-02-12 15:35:20 -060059 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 Williamsf1e5d692016-03-30 15:21:19 -050064 xargs -n100 $SUDO_EXEC sed -i \
Patrick Williams213cb262021-08-07 19:21:33 -050065 -e "s:$SDK_BUILD_PATH:$target_sdk_dir:g" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -050066 -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
67 -e "s: /usr/bin/perl: /usr/bin/env perl:g"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069if [ $? -ne 0 ]; then
70 echo "Failed to replace perl. Relocate script failed. Abort!"
71 exit 1
72fi
73
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074# change all symlinks pointing to @SDKPATH@
75for l in $($SUDO_EXEC find $native_sysroot -type l); do
Patrick Williams0ca19cc2021-08-16 14:03:13 -050076 $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$SDK_BUILD_PATH:$target_sdk_dir:") $l
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 if [ $? -ne 0 ]; then
78 echo "Failed to setup symlinks. Relocate script failed. Abort!"
79 exit 1
80 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081done
82
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083echo done