toolchain-shar-relocate.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. if ! xargs --version > /dev/null 2>&1; then
  2. echo "xargs is required by the relocation script, please install it first. Abort!"
  3. exit 1
  4. fi
  5. # fix dynamic loader paths in all ELF SDK binaries
  6. native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
  7. dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
  8. if [ "$dl_path" = "" ] ; then
  9. echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
  10. exit 1
  11. fi
  12. executable_files=$($SUDO_EXEC find $native_sysroot -type f \
  13. \( -perm -0100 -o -perm -0010 -o -perm -0001 \) -printf "'%h/%f' ")
  14. if [ "x$executable_files" = "x" ]; then
  15. echo "SDK relocate failed, could not get executalbe files"
  16. exit 1
  17. fi
  18. tdir=`mktemp -d`
  19. if [ x$tdir = x ] ; then
  20. echo "SDK relocate failed, could not create a temporary directory"
  21. exit 1
  22. fi
  23. cat <<EOF >> $tdir/relocate_sdk.sh
  24. #!/bin/sh
  25. for py in python python2 python3
  26. do
  27. PYTHON=\`which \${py} 2>/dev/null\`
  28. if [ \$? -eq 0 ]; then
  29. break;
  30. fi
  31. done
  32. if [ x\${PYTHON} = "x" ]; then
  33. echo "SDK could not be relocated. No python found."
  34. exit 1
  35. fi
  36. \${PYTHON} ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files
  37. EOF
  38. $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh
  39. $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh
  40. rm -rf $tdir
  41. if [ $relocate = 1 ] ; then
  42. $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh
  43. if [ $? -ne 0 ]; then
  44. echo "SDK could not be set up. Relocate script failed. Abort!"
  45. exit 1
  46. fi
  47. fi
  48. # replace @SDKPATH@ with the new prefix in all text files: configs/scripts/etc.
  49. # replace the host perl with SDK perl.
  50. for replace in "$target_sdk_dir -maxdepth 1" "$native_sysroot"; do
  51. $SUDO_EXEC find $replace -type f
  52. done | xargs -n100 file | grep ":.*\(ASCII\|script\|source\).*text" | \
  53. awk -F':' '{printf "\"%s\"\n", $1}' | \
  54. grep -Ev "$target_sdk_dir/(environment-setup-*|relocate_sdk*|${0##*/})" | \
  55. xargs -n100 $SUDO_EXEC sed -i \
  56. -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" \
  57. -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" \
  58. -e "s: /usr/bin/perl: /usr/bin/env perl:g"
  59. if [ $? -ne 0 ]; then
  60. echo "Failed to replace perl. Relocate script failed. Abort!"
  61. exit 1
  62. fi
  63. # change all symlinks pointing to @SDKPATH@
  64. for l in $($SUDO_EXEC find $native_sysroot -type l); do
  65. $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l
  66. if [ $? -ne 0 ]; then
  67. echo "Failed to setup symlinks. Relocate script failed. Abort!"
  68. exit 1
  69. fi
  70. done
  71. echo done