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