1#!/bin/bash
2#
3# Copyright (C) 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18# This script is useful for learning the path of the active toolchain
19# components within the ndk.
20# Run this script without parameters, for usage hints.
21
22# show usage if no parameter given
23WHICH=$1
24if [ "$WHICH" == "" ]; then
25  echo "USAGE: ndk-which <tool>"
26  echo "where tool is 'gdb', 'gcc', 'objdump', etc."
27  exit 1
28fi
29
30MYNDKDIR=`dirname $0`
31
32# create a temporary skeleton project so that we can leverage build-local.mk
33mkdir -p /tmp/ndk-which/jni
34cat >/tmp/ndk-which/jni/Android.mk << "END_OF_FILE"
35include $(CLEAR_VARS)
36END_OF_FILE
37
38# 'get_build_var_for_abi' was copied from ndk-gdb
39get_build_var_for_abi ()
40{
41    if [ -z "$GNUMAKE" ] ; then
42        GNUMAKE=make
43    fi
44    NDK_PROJECT_PATH=/tmp/ndk-which $GNUMAKE --no-print-dir -f $MYNDKDIR/build/core/build-local.mk DUMP_$1 APP_ABI=$2
45}
46
47TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX armeabi`
48rm -Rf /tmp/ndk-which
49
50# fully qualified file name
51FQFN=${TOOLCHAIN_PREFIX}$WHICH
52
53# use the host system's 'which' to decide/report if the file exists or not, and is executable
54which "$FQFN"
55
56