aboutsummaryrefslogtreecommitdiff
path: root/ndk-which
blob: 2eaf93c57731039d2cd78574275e4b90d94f4c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# DEPRECATED
#

# This script shows the path of the active toolchain components within
# the ndk. This was necessary for GCC and binutils, where each ABI had
# its own tools, but is not needed for LLVM-based tools which should be
# used in preference.

usage() {
  echo "USAGE: ndk-which [--abi ABI] TOOL"
  echo "ABI is 'armeabi-v7a', 'arm64-v8a', 'x86', or 'x86_64'"
  echo "TOOL is 'gdb', 'objdump', 'readelf', etc."
  echo
  echo "Note that LLVM replacements for binutils tools work for all ABIs."
  exit 1
}

ABI=armeabi-v7a

while (( "$#" )); do
  case "$1" in
    --abi)
      ABI=$2
      shift 2
      abis='^(armeabi-v7a|arm64-v8a|x86|x86_64)$'
      if [[ ! "$ABI" =~ $abis ]]; then usage; fi
      ;;
    *)
      break
      ;;
  esac
done

TOOL=$1
shift

if [ "$#" != 0 -o "$TOOL" == "" ]; then
  usage
fi

# This tool is installed in prebuilt/linux-x86_64/bin/.
MYNDKDIR=`dirname $0`/../../..

# create a temporary skeleton project so that we can leverage build-local.mk
TMPDIR=/tmp/ndk-which-$$
mkdir -p $TMPDIR/jni
cat >$TMPDIR/jni/Android.mk << "END_OF_FILE"
include $(CLEAR_VARS)
END_OF_FILE

get_build_var_for_abi() {
  if [ -z "$GNUMAKE" ] ; then
    GNUMAKE=make
  fi
  NDK_PROJECT_PATH=$TMPDIR $GNUMAKE --no-print-dir -f $MYNDKDIR/build/core/build-local.mk DUMP_$1 APP_ABI=$2
}

TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $ABI`
rm -Rf $TMPDIR

# fully qualified file name
FQFN=${TOOLCHAIN_PREFIX}$TOOL

# use the host system's 'which' to decide/report if the file exists or not, and is executable
which "$FQFN"