blob: 8ea6194eca5a9ac89e9d81098f8dd522fdffc4f6 [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
7native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
8dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
9if [ "$dl_path" = "" ] ; then
10 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
11 exit 1
12fi
13executable_files=$($SUDO_EXEC find $native_sysroot -type f \
14 \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015if [ "x$executable_files" = "x" ]; then
16 echo "SDK relocate failed, could not get executalbe files"
17 exit 1
18fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20tdir=`mktemp -d`
21if [ x$tdir = x ] ; then
22 echo "SDK relocate failed, could not create a temporary directory"
23 exit 1
24fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050025cat <<EOF >> $tdir/relocate_sdk.sh
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026#!/bin/sh
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027for py in python python2 python3
28do
29 PYTHON=\`which \${py} 2>/dev/null\`
30 if [ \$? -eq 0 ]; then
31 break;
32 fi
33done
34
35if [ x\${PYTHON} = "x" ]; then
36 echo "SDK could not be relocated. No python found."
37 exit 1
38fi
39\${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files
40EOF
41
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042$SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh
43$SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh
44rm -rf $tdir
45if [ $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
51fi
52
Patrick Williamsf1e5d692016-03-30 15:21:19 -050053# replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
54# replace the host perl with SDK perl.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056 $SUDO_EXEC find $replace -type f
57done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \
Andrew Geisslerd1e89492021-02-12 15:35:20 -060058 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 Williamsf1e5d692016-03-30 15:21:19 -050063 xargs -n100 $SUDO_EXEC sed -i \
Patrick Williams213cb262021-08-07 19:21:33 -050064 -e "s:$SDK_BUILD_PATH:$target_sdk_dir:g" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -050065 -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
66 -e "s: /usr/bin/perl: /usr/bin/env perl:g"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068if [ $? -ne 0 ]; then
69 echo "Failed to replace perl. Relocate script failed. Abort!"
70 exit 1
71fi
72
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073# change all symlinks pointing to @SDKPATH@
74for 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 Williamsc0f7c042017-02-23 20:41:17 -060076 if [ $? -ne 0 ]; then
77 echo "Failed to setup symlinks. Relocate script failed. Abort!"
78 exit 1
79 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080done
81
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082echo done