blob: 235a67c95c3a880ed852f70a12513458b2ae7538 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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 Bishop6e60e8b2018-02-01 10:27:11 -05005# $OECORE_NATIVE_SYSROOT is set to the sysroot's base directory, and sets
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006# $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 Bishop6e60e8b2018-02-01 10:27:11 -050012# . $SYSROOT_SETUP_SCRIPT <recipe>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013#
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 Bishop6e60e8b2018-02-01 10:27:11 -050033if [ "$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
46fi
47
48# Global vars
49BITBAKE_E=""
50set_oe_native_sysroot(){
51 echo "Running bitbake -e $1"
52 BITBAKE_E="`bitbake -e $1`"
53 OECORE_NATIVE_SYSROOT=`echo "$BITBAKE_E" | grep ^STAGING_DIR_NATIVE | cut -d '"' -f2`
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 Williamsc124f4f2015-09-15 14:41:29 -050065if [ "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 Bishop6e60e8b2018-02-01 10:27:11 -050075 set_oe_native_sysroot $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 rm -f conf/sanity.conf
77 else
Brad Bishop6e60e8b2018-02-01 10:27:11 -050078 set_oe_native_sysroot $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 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
88fi
89
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then
91 echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist."
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092
93 if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 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 Williamsc124f4f2015-09-15 14:41:29 -050099 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
106fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107
108# Set up pseudo command
109pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo"
110if [ -e "$pseudo" ]; then
111 echo "PSEUDO=$pseudo"
112 PSEUDO="$pseudo"
113else
114 echo "PSEUDO $pseudo is not found."
115fi