blob: 6228efcbeec7289924f1ea0d5fbe32ba4cb7f048 [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#
Brad Bishopc342db32019-05-15 21:57:59 -040020# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023if [ "$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
36fi
37
38# Global vars
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039set_oe_native_sysroot(){
Andrew Geissler5082cc72023-09-11 08:41:39 -040040 echo "Getting sysroot..."
41 OECORE_NATIVE_SYSROOT=$(bitbake-getvar -r $1 --value STAGING_DIR_NATIVE)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042}
43
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then
45 BITBAKE=`which bitbake 2> /dev/null`
46 if [ "x$BITBAKE" != "x" ]; then
47 if [ "$UID" = "0" ]; then
48 # Root cannot run bitbake unless sanity checking is disabled
49 if [ ! -d "./conf" ]; then
50 echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking"
51 exit 1
52 fi
53 touch conf/sanity.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054 set_oe_native_sysroot $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 rm -f conf/sanity.conf
56 else
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 set_oe_native_sysroot $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 fi
59 else
60 echo "Error: Unable to locate bitbake command."
61 echo "Did you forget to source the build environment setup script?"
62
63 if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
64 exit 1
65 fi
66 fi
67fi
68
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069if [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then
70 echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist."
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071
72 if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073 if [[ $1 =~ .*native.* ]]; then
74 echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?"
75 else
76 echo "Have you run 'bitbake $1 '?"
77 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 else
79 echo "This shouldn't happen - something is wrong with your toolchain installation"
80 fi
81
82 if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then
83 exit 1
84 fi
85fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -050086
87# Set up pseudo command
88pseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo"
89if [ -e "$pseudo" ]; then
90 echo "PSEUDO=$pseudo"
91 PSEUDO="$pseudo"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050092fi