oe-find-native-sysroot 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. set_oe_native_sysroot(){
  38. echo "Getting sysroot..."
  39. OECORE_NATIVE_SYSROOT=$(bitbake-getvar -r $1 --value STAGING_DIR_NATIVE)
  40. }
  41. if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
  42. BITBAKE=`which bitbake 2> /dev/null`
  43. if [ "x$BITBAKE" != "x" ]; then
  44. if [ "$UID" = "0" ]; then
  45. # Root cannot run bitbake unless sanity checking is disabled
  46. if [ ! -d "./conf" ]; then
  47. echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking"
  48. exit 1
  49. fi
  50. touch conf/sanity.conf
  51. set_oe_native_sysroot $1
  52. rm -f conf/sanity.conf
  53. else
  54. set_oe_native_sysroot $1
  55. fi
  56. else
  57. echo "Error: Unable to locate bitbake command."
  58. echo "Did you forget to source the build environment setup script?"
  59. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  60. exit 1
  61. fi
  62. fi
  63. fi
  64. if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then
  65. echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist."
  66. if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
  67. if [[ $1 =~ .*native.* ]]; then
  68. echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?"
  69. else
  70. echo "Have you run 'bitbake $1 '?"
  71. fi
  72. else
  73. echo "This shouldn't happen - something is wrong with your toolchain installation"
  74. fi
  75. if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
  76. exit 1
  77. fi
  78. fi
  79. # Set up pseudo command
  80. pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo"
  81. if [ -e "$pseudo" ]; then
  82. echo "PSEUDO=$pseudo"
  83. PSEUDO="$pseudo"
  84. fi