toolchain-shar-relocate.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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
  7. # fix dynamic loader paths in all ELF SDK binaries
  8. # allow symlinks to be accessed via the find command too
  9. native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
  10. dl_paths=$($SUDO_EXEC find $native_sysroot/lib*/ -maxdepth 1 -name "ld-linux*")
  11. if [ "$dl_paths" = "" ] ; then
  12. echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
  13. exit 1
  14. fi
  15. executable_files=$($SUDO_EXEC find $native_sysroot -type f \
  16. \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
  17. if [ "x$executable_files" = "x" ]; then
  18. echo "SDK relocate failed, could not get executalbe files"
  19. exit 1
  20. fi
  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
  26. cat <<EOF >> $tdir/relocate_sdk.sh
  27. #!/bin/sh
  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. if [ x\${PYTHON} = "x" ]; then
  36. echo "SDK could not be relocated. No python found."
  37. exit 1
  38. fi
  39. for dl_path in \$(echo "$dl_paths"); do
  40. \${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir \$dl_path $executable_files
  41. done
  42. EOF
  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. # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
  54. # replace the host perl with SDK perl.
  55. for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
  56. $SUDO_EXEC find $replace -type f
  57. done | xargs -d '\n' -n100 file | \
  58. awk -F': ' '{if (match($2, ".*(ASCII|script|source).*text")) {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##*/}" | \
  63. xargs -n100 $SUDO_EXEC sed -i \
  64. -e "s:$SDK_BUILD_PATH:$target_sdk_dir:g" \
  65. -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
  66. -e "s: /usr/bin/perl: /usr/bin/env perl:g"
  67. if [ $? -ne 0 ]; then
  68. echo "Failed to replace perl. Relocate script failed. Abort!"
  69. exit 1
  70. fi
  71. # change all symlinks pointing to @SDKPATH@
  72. for l in $($SUDO_EXEC find $native_sysroot -type l); do
  73. $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$SDK_BUILD_PATH:$target_sdk_dir:") $l
  74. if [ $? -ne 0 ]; then
  75. echo "Failed to setup symlinks. Relocate script failed. Abort!"
  76. exit 1
  77. fi
  78. done
  79. echo done