xref: /OK3568_Linux_fs/yocto/scripts/oe-run-native (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/bash
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Copyright (c) 2016,  Intel Corporation.
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-or-later
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# This script is for running tools from native oe sysroot
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun
12*4882a593Smuzhiyunif [ $# -lt 1 -o "$1" = '--help' -o "$1" = '-h' ] ; then
13*4882a593Smuzhiyun    echo 'oe-run-native: the following arguments are required: <native recipe> <native tool>'
14*4882a593Smuzhiyun    echo 'Usage: oe-run-native native-recipe tool [parameters]'
15*4882a593Smuzhiyun    echo ''
16*4882a593Smuzhiyun    echo 'OpenEmbedded run-native - runs native tools'
17*4882a593Smuzhiyun    echo ''
18*4882a593Smuzhiyun    echo 'arguments:'
19*4882a593Smuzhiyun    echo '  native-recipe       The recipe which provides tool'
20*4882a593Smuzhiyun    echo '  tool                Native tool to run'
21*4882a593Smuzhiyun    echo ''
22*4882a593Smuzhiyun    exit 2
23*4882a593Smuzhiyunfi
24*4882a593Smuzhiyun
25*4882a593Smuzhiyunnative_recipe="$1"
26*4882a593Smuzhiyuntool="$2"
27*4882a593Smuzhiyun
28*4882a593Smuzhiyunif [ "${native_recipe%-native}" = "$native_recipe" ]; then
29*4882a593Smuzhiyun    echo Error: $native_recipe is not a native recipe
30*4882a593Smuzhiyun    echo Error: Use \"oe-run-native -h\" for help
31*4882a593Smuzhiyun    exit 1
32*4882a593Smuzhiyunfi
33*4882a593Smuzhiyun
34*4882a593Smuzhiyunshift
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunSYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
37*4882a593Smuzhiyunif [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
38*4882a593Smuzhiyun        echo "Error: Unable to find oe-find-native-sysroot script"
39*4882a593Smuzhiyun        exit 1
40*4882a593Smuzhiyunfi
41*4882a593Smuzhiyun. $SYSROOT_SETUP_SCRIPT $native_recipe
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunOLD_PATH=$PATH
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun# look for a tool only in native sysroot
46*4882a593SmuzhiyunPATH=$OECORE_NATIVE_SYSROOT/usr/bin:$OECORE_NATIVE_SYSROOT/bin:$OECORE_NATIVE_SYSROOT/usr/sbin:$OECORE_NATIVE_SYSROOT/sbin$(find $OECORE_NATIVE_SYSROOT/usr/bin -maxdepth 1 -name "*-native" -type d -printf ":%p")
47*4882a593Smuzhiyuntool_find=`/usr/bin/which $tool 2>/dev/null`
48*4882a593Smuzhiyun
49*4882a593Smuzhiyunif [ -n "$tool_find" ] ; then
50*4882a593Smuzhiyun    # add old path to allow usage of host tools
51*4882a593Smuzhiyun    PATH=$PATH:$OLD_PATH "$@"
52*4882a593Smuzhiyunelse
53*4882a593Smuzhiyun    echo "Error: Unable to find '$tool' in $PATH"
54*4882a593Smuzhiyun    echo "Error: Have you run 'bitbake $native_recipe -caddto_recipe_sysroot'?"
55*4882a593Smuzhiyun    exit 1
56*4882a593Smuzhiyunfi
57