blob: b017714df07743b5bc46c216be5dbefc0be381ee [file] [log] [blame]
Patrick Williams03514f12024-04-05 07:04:11 -05001for 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
6done
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008# fix dynamic loader paths in all ELF SDK binaries
Patrick Williams73bd93f2024-02-20 08:07:48 -06009# allow symlinks to be accessed via the find command too
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
Patrick Williams73bd93f2024-02-20 08:07:48 -060011dl_path=$($SUDO_EXEC find $native_sysroot/lib/ -maxdepth 1 -name "ld-linux*")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012if [ "$dl_path" = "" ] ; then
13 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
14 exit 1
15fi
16executable_files=$($SUDO_EXEC find $native_sysroot -type f \
17 \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060018if [ "x$executable_files" = "x" ]; then
19 echo "SDK relocate failed, could not get executalbe files"
20 exit 1
21fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
23tdir=`mktemp -d`
24if [ x$tdir = x ] ; then
25 echo "SDK relocate failed, could not create a temporary directory"
26 exit 1
27fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028cat <<EOF >> $tdir/relocate_sdk.sh
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029#!/bin/sh
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030for py in python python2 python3
31do
32 PYTHON=\`which \${py} 2>/dev/null\`
33 if [ \$? -eq 0 ]; then
34 break;
35 fi
36done
37
38if [ x\${PYTHON} = "x" ]; then
39 echo "SDK could not be relocated. No python found."
40 exit 1
41fi
42\${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files
43EOF
44
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045$SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh
46$SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh
47rm -rf $tdir
48if [ $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
54fi
55
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056# replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
57# replace the host perl with SDK perl.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
Patrick Williamsf1e5d692016-03-30 15:21:19 -050059 $SUDO_EXEC find $replace -type f
60done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \
Andrew Geisslerd1e89492021-02-12 15:35:20 -060061 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 Williamsf1e5d692016-03-30 15:21:19 -050066 xargs -n100 $SUDO_EXEC sed -i \
Patrick Williams213cb262021-08-07 19:21:33 -050067 -e "s:$SDK_BUILD_PATH:$target_sdk_dir:g" \
Patrick Williamsf1e5d692016-03-30 15:21:19 -050068 -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
69 -e "s: /usr/bin/perl: /usr/bin/env perl:g"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071if [ $? -ne 0 ]; then
72 echo "Failed to replace perl. Relocate script failed. Abort!"
73 exit 1
74fi
75
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076# change all symlinks pointing to @SDKPATH@
77for l in $($SUDO_EXEC find $native_sysroot -type l); do
Patrick Williams0ca19cc2021-08-16 14:03:13 -050078 $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 -060079 if [ $? -ne 0 ]; then
80 echo "Failed to setup symlinks. Relocate script failed. Abort!"
81 exit 1
82 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083done
84
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085echo done