| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | # $OECORE_NATIVE_SYSROOT is set to the sysroot's base directory, and sets | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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` | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | # . $SYSROOT_SETUP_SCRIPT <recipe> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | if [ "$1" = '--help' -o "$1" = '-h' -o $# -ne 1 ] ; then | 
|  | 34 | echo 'Usage: oe-find-native-sysroot <recipe> [-h|--help]' | 
|  | 35 | echo '' | 
|  | 36 | echo 'OpenEmbedded find-native-sysroot - helper script to set' | 
|  | 37 | echo 'environment variables OECORE_NATIVE_SYSROOT and PSEUDO' | 
|  | 38 | echo 'to the path of the native sysroot directory and pseudo' | 
|  | 39 | echo 'executable binary' | 
|  | 40 | echo '' | 
|  | 41 | echo 'options:' | 
|  | 42 | echo '  recipe              its STAGING_DIR_NATIVE is used as native sysroot' | 
|  | 43 | echo '  -h, --help          show this help message and exit' | 
|  | 44 | echo '' | 
|  | 45 | exit 2 | 
|  | 46 | fi | 
|  | 47 |  | 
|  | 48 | # Global vars | 
|  | 49 | BITBAKE_E="" | 
|  | 50 | set_oe_native_sysroot(){ | 
|  | 51 | echo "Running bitbake -e $1" | 
|  | 52 | BITBAKE_E="`bitbake -e $1`" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 53 | OECORE_NATIVE_SYSROOT=`echo "$BITBAKE_E" | grep ^STAGING_DIR_NATIVE= | cut -d '"' -f2` | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 |  | 
|  | 55 | if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then | 
|  | 56 | # This indicates that there was an error running bitbake -e that | 
|  | 57 | # the user needs to be informed of | 
|  | 58 | echo "There was an error running bitbake to determine STAGING_DIR_NATIVE" | 
|  | 59 | echo "Here is the output from bitbake -e $1" | 
|  | 60 | echo $BITBAKE_E | 
|  | 61 | exit 1 | 
|  | 62 | fi | 
|  | 63 | } | 
|  | 64 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then | 
|  | 66 | BITBAKE=`which bitbake 2> /dev/null` | 
|  | 67 | if [ "x$BITBAKE" != "x" ]; then | 
|  | 68 | if [ "$UID" = "0" ]; then | 
|  | 69 | # Root cannot run bitbake unless sanity checking is disabled | 
|  | 70 | if [ ! -d "./conf" ]; then | 
|  | 71 | echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking" | 
|  | 72 | exit 1 | 
|  | 73 | fi | 
|  | 74 | touch conf/sanity.conf | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 75 | set_oe_native_sysroot $1 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | rm -f conf/sanity.conf | 
|  | 77 | else | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 78 | set_oe_native_sysroot $1 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | fi | 
|  | 80 | else | 
|  | 81 | echo "Error: Unable to locate bitbake command." | 
|  | 82 | echo "Did you forget to source the build environment setup script?" | 
|  | 83 |  | 
|  | 84 | if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then | 
|  | 85 | exit 1 | 
|  | 86 | fi | 
|  | 87 | fi | 
|  | 88 | fi | 
|  | 89 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 90 | if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then | 
|  | 91 | echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist." | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 |  | 
|  | 93 | if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | if [[ $1 =~ .*native.* ]]; then | 
|  | 95 | echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?" | 
|  | 96 | else | 
|  | 97 | echo "Have you run 'bitbake $1 '?" | 
|  | 98 | fi | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | else | 
|  | 100 | echo "This shouldn't happen - something is wrong with your toolchain installation" | 
|  | 101 | fi | 
|  | 102 |  | 
|  | 103 | if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then | 
|  | 104 | exit 1 | 
|  | 105 | fi | 
|  | 106 | fi | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 107 |  | 
|  | 108 | # Set up pseudo command | 
|  | 109 | pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo" | 
|  | 110 | if [ -e "$pseudo" ]; then | 
|  | 111 | echo "PSEUDO=$pseudo" | 
|  | 112 | PSEUDO="$pseudo" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | fi |