1*4882a593Smuzhiyun#!/bin/bash 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# Find a native sysroot to use - either from an in-tree OE build or 4*4882a593Smuzhiyun# from a toolchain installation. It then ensures the variable 5*4882a593Smuzhiyun# $OECORE_NATIVE_SYSROOT is set to the sysroot's base directory, and sets 6*4882a593Smuzhiyun# $PSEUDO to the path of the pseudo binary. 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# This script is intended to be run within other scripts by source'ing 9*4882a593Smuzhiyun# it, e.g: 10*4882a593Smuzhiyun# 11*4882a593Smuzhiyun# SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot` 12*4882a593Smuzhiyun# . $SYSROOT_SETUP_SCRIPT <recipe> 13*4882a593Smuzhiyun# 14*4882a593Smuzhiyun# This script will terminate execution of your calling program unless 15*4882a593Smuzhiyun# you set a variable $SKIP_STRICT_SYSROOT_CHECK to a non-empty string 16*4882a593Smuzhiyun# beforehand. 17*4882a593Smuzhiyun# 18*4882a593Smuzhiyun# Copyright (c) 2010 Linux Foundation 19*4882a593Smuzhiyun# 20*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only 21*4882a593Smuzhiyun# 22*4882a593Smuzhiyun 23*4882a593Smuzhiyunif [ "$1" = '--help' -o "$1" = '-h' -o $# -ne 1 ] ; then 24*4882a593Smuzhiyun echo 'Usage: oe-find-native-sysroot <recipe> [-h|--help]' 25*4882a593Smuzhiyun echo '' 26*4882a593Smuzhiyun echo 'OpenEmbedded find-native-sysroot - helper script to set' 27*4882a593Smuzhiyun echo 'environment variables OECORE_NATIVE_SYSROOT and PSEUDO' 28*4882a593Smuzhiyun echo 'to the path of the native sysroot directory and pseudo' 29*4882a593Smuzhiyun echo 'executable binary' 30*4882a593Smuzhiyun echo '' 31*4882a593Smuzhiyun echo 'options:' 32*4882a593Smuzhiyun echo ' recipe its STAGING_DIR_NATIVE is used as native sysroot' 33*4882a593Smuzhiyun echo ' -h, --help show this help message and exit' 34*4882a593Smuzhiyun echo '' 35*4882a593Smuzhiyun exit 2 36*4882a593Smuzhiyunfi 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun# Global vars 39*4882a593SmuzhiyunBITBAKE_E="" 40*4882a593Smuzhiyunset_oe_native_sysroot(){ 41*4882a593Smuzhiyun echo "Running bitbake -e $1" 42*4882a593Smuzhiyun BITBAKE_E="`bitbake -e $1`" 43*4882a593Smuzhiyun OECORE_NATIVE_SYSROOT=`echo "$BITBAKE_E" | grep ^STAGING_DIR_NATIVE= | cut -d '"' -f2` 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun if [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then 46*4882a593Smuzhiyun # This indicates that there was an error running bitbake -e that 47*4882a593Smuzhiyun # the user needs to be informed of 48*4882a593Smuzhiyun echo "There was an error running bitbake to determine STAGING_DIR_NATIVE" 49*4882a593Smuzhiyun echo "Here is the output from bitbake -e $1" 50*4882a593Smuzhiyun echo $BITBAKE_E 51*4882a593Smuzhiyun exit 1 52*4882a593Smuzhiyun fi 53*4882a593Smuzhiyun} 54*4882a593Smuzhiyun 55*4882a593Smuzhiyunif [ "x$OECORE_NATIVE_SYSROOT" = "x" ]; then 56*4882a593Smuzhiyun BITBAKE=`which bitbake 2> /dev/null` 57*4882a593Smuzhiyun if [ "x$BITBAKE" != "x" ]; then 58*4882a593Smuzhiyun if [ "$UID" = "0" ]; then 59*4882a593Smuzhiyun # Root cannot run bitbake unless sanity checking is disabled 60*4882a593Smuzhiyun if [ ! -d "./conf" ]; then 61*4882a593Smuzhiyun echo "Error: root cannot run bitbake by default, and I cannot find a ./conf directory to be able to disable sanity checking" 62*4882a593Smuzhiyun exit 1 63*4882a593Smuzhiyun fi 64*4882a593Smuzhiyun touch conf/sanity.conf 65*4882a593Smuzhiyun set_oe_native_sysroot $1 66*4882a593Smuzhiyun rm -f conf/sanity.conf 67*4882a593Smuzhiyun else 68*4882a593Smuzhiyun set_oe_native_sysroot $1 69*4882a593Smuzhiyun fi 70*4882a593Smuzhiyun else 71*4882a593Smuzhiyun echo "Error: Unable to locate bitbake command." 72*4882a593Smuzhiyun echo "Did you forget to source the build environment setup script?" 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then 75*4882a593Smuzhiyun exit 1 76*4882a593Smuzhiyun fi 77*4882a593Smuzhiyun fi 78*4882a593Smuzhiyunfi 79*4882a593Smuzhiyun 80*4882a593Smuzhiyunif [ ! -e "$OECORE_NATIVE_SYSROOT/" ]; then 81*4882a593Smuzhiyun echo "Error: $OECORE_NATIVE_SYSROOT doesn't exist." 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then 84*4882a593Smuzhiyun if [[ $1 =~ .*native.* ]]; then 85*4882a593Smuzhiyun echo "Have you run 'bitbake $1 -caddto_recipe_sysroot'?" 86*4882a593Smuzhiyun else 87*4882a593Smuzhiyun echo "Have you run 'bitbake $1 '?" 88*4882a593Smuzhiyun fi 89*4882a593Smuzhiyun else 90*4882a593Smuzhiyun echo "This shouldn't happen - something is wrong with your toolchain installation" 91*4882a593Smuzhiyun fi 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun if [ -z "$SKIP_STRICT_SYSROOT_CHECK" ]; then 94*4882a593Smuzhiyun exit 1 95*4882a593Smuzhiyun fi 96*4882a593Smuzhiyunfi 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun# Set up pseudo command 99*4882a593Smuzhiyunpseudo="$OECORE_NATIVE_SYSROOT/usr/bin/pseudo" 100*4882a593Smuzhiyunif [ -e "$pseudo" ]; then 101*4882a593Smuzhiyun echo "PSEUDO=$pseudo" 102*4882a593Smuzhiyun PSEUDO="$pseudo" 103*4882a593Smuzhiyunfi 104