oe-find-native-sysroot 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. #
  3. # Find a native sysroot to use - either from an in-tree OE build or
  4. # from a toolchain installation. It then ensures the variable
  5. # $OECORE_NATIVE_SYSROOT is set to the sysroot's base directory, and sets
  6. # $PSEUDO to the path of the pseudo binary.
  7. #
  8. # This script is intended to be run within other scripts by source'ing
  9. # it, e.g:
  10. #
  11. # SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot`
  12. # . $SYSROOT_SETUP_SCRIPT <recipe>
  13. #
  14. # This script will terminate execution of your calling program unless
  15. # you set a variable $SKIP_STRICT_SYSROOT_CHECK to a non-empty string
  16. # beforehand.
  17. #
  18. # Copyright (c) 2010 Linux Foundation
  19. #
  20. # SPDX-License-Identifier: GPL-2.0-only
  21. #
  22. if [ "$1" = '--help' -o "$1" = '-h' -o $# -ne 1 ] ; then
  23. echo 'Usage: oe-find-native-sysroot <recipe> [-h|--help]'
  24. echo ''
  25. echo 'OpenEmbedded find-native-sysroot - helper script to set'
  26. echo 'environment variables OECORE_NATIVE_SYSROOT and PSEUDO'
  27. echo 'to the path of the native sysroot directory and pseudo'
  28. echo 'executable binary'
  29. echo ''
  30. echo 'options:'
  31. echo ' recipe its STAGING_DIR_NATIVE is used as native sysroot'
  32. echo ' -h, --help show this help message and exit'
  33. echo ''
  34. exit 2
  35. fi
  36. # Global vars
  37. BITBAKE_E=""
  38. set_oe_native_sysroot(){
  39. echo "Running bitbake -e $1"
  40. BITBAKE_E="`bitbake -e $1`"
  41. OECORE_NATIVE_SYSROOT=`echo "$BITBAKE_E" | grep ^STAGING_DIR_NATIVE= | cut -d '"' -f2`
  42. if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
  43. # This indicates that there was an error running bitbake -e that
  44. # the user needs to be informed of
  45. echo "There was an error running bitbake to determine STAGING_DIR_NATIVE"
  46. echo "Here is the output from bitbake -e $1"
  47. echo $BITBAKE_E
  48. exit 1
  49. fi
  50. }
  51. if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
  52. BITBAKE=`which bitbake 2> /dev/null`
  53. if [ "x$BITBAKE" != "x" ]; then
  54. if [ "$UID" = "0" ]; then
  55. # Root cannot run bitbake unless sanity checking is disabled
  56. if [ ! -d "./conf" ]; then
  57. echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking"
  58. exit 1
  59. fi
  60. touch conf/sanity.conf
  61. set_oe_native_sysroot $1
  62. rm -f conf/sanity.conf
  63. else
  64. set_oe_native_sysroot $1
  65. fi
  66. else
  67. echo "Error: Unable to locate bitbake command."
  68. echo "Did you forget to source the build environment setup script?"
  69. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  70. exit 1
  71. fi
  72. fi
  73. fi
  74. if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then
  75. echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist."
  76. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  77. if [[ $1 =~ .*native.* ]]; then
  78. echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?"
  79. else
  80. echo "Have you run 'bitbake $1 '?"
  81. fi
  82. else
  83. echo "This shouldn't happen - something is wrong with your toolchain installation"
  84. fi
  85. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  86. exit 1
  87. fi
  88. fi
  89. # Set up pseudo command
  90. pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo"
  91. if [ -e "$pseudo" ]; then
  92. echo "PSEUDO=$pseudo"
  93. PSEUDO="$pseudo"
  94. fi