oe-find-native-sysroot 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # This program is free software; you can redistribute it and/or modify
  21. # it under the terms of the GNU General Public License version 2 as
  22. # published by the Free Software Foundation.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU General Public License along
  30. # with this program; if not, write to the Free Software Foundation, Inc.,
  31. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  32. if [ "$1" = '--help' -o "$1" = '-h' -o $# -ne 1 ] ; then
  33. echo 'Usage: oe-find-native-sysroot <recipe> [-h|--help]'
  34. echo ''
  35. echo 'OpenEmbedded find-native-sysroot - helper script to set'
  36. echo 'environment variables OECORE_NATIVE_SYSROOT and PSEUDO'
  37. echo 'to the path of the native sysroot directory and pseudo'
  38. echo 'executable binary'
  39. echo ''
  40. echo 'options:'
  41. echo ' recipe its STAGING_DIR_NATIVE is used as native sysroot'
  42. echo ' -h, --help show this help message and exit'
  43. echo ''
  44. exit 2
  45. fi
  46. # Global vars
  47. BITBAKE_E=""
  48. set_oe_native_sysroot(){
  49. echo "Running bitbake -e $1"
  50. BITBAKE_E="`bitbake -e $1`"
  51. OECORE_NATIVE_SYSROOT=`echo "$BITBAKE_E" | grep ^STAGING_DIR_NATIVE= | cut -d '"' -f2`
  52. if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
  53. # This indicates that there was an error running bitbake -e that
  54. # the user needs to be informed of
  55. echo "There was an error running bitbake to determine STAGING_DIR_NATIVE"
  56. echo "Here is the output from bitbake -e $1"
  57. echo $BITBAKE_E
  58. exit 1
  59. fi
  60. }
  61. if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
  62. BITBAKE=`which bitbake 2> /dev/null`
  63. if [ "x$BITBAKE" != "x" ]; then
  64. if [ "$UID" = "0" ]; then
  65. # Root cannot run bitbake unless sanity checking is disabled
  66. if [ ! -d "./conf" ]; then
  67. echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking"
  68. exit 1
  69. fi
  70. touch conf/sanity.conf
  71. set_oe_native_sysroot $1
  72. rm -f conf/sanity.conf
  73. else
  74. set_oe_native_sysroot $1
  75. fi
  76. else
  77. echo "Error: Unable to locate bitbake command."
  78. echo "Did you forget to source the build environment setup script?"
  79. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  80. exit 1
  81. fi
  82. fi
  83. fi
  84. if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then
  85. echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist."
  86. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  87. if [[ $1 =~ .*native.* ]]; then
  88. echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?"
  89. else
  90. echo "Have you run 'bitbake $1 '?"
  91. fi
  92. else
  93. echo "This shouldn't happen - something is wrong with your toolchain installation"
  94. fi
  95. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  96. exit 1
  97. fi
  98. fi
  99. # Set up pseudo command
  100. pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo"
  101. if [ -e "$pseudo" ]; then
  102. echo "PSEUDO=$pseudo"
  103. PSEUDO="$pseudo"
  104. else
  105. echo "PSEUDO $pseudo is not found."
  106. fi