aboutsummaryrefslogtreecommitdiff
path: root/ndk-which
blob: 44f888c546b4acb7aecb675ddb952afe1c77063c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env 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
}

error() {
  echo "The tool: $1 doesn't exist"
  echo "Possible choices are: "
  count=0
  for file in $2*
  do
    if [[ $file == *$1 ]]
    then
        echo $file
        ((count = count + 1))
    fi
  done
  if [ $count -eq 0 ]
  then
      echo " None "
  fi
  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
}
LLVM_TOOLCHAIN_PREFIX=`get_build_var_for_abi LLVM_TOOLCHAIN_PREFIX $ABI`
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
if [ ! -f $FQFN ]
then
    FQFN=${LLVM_TOOLCHAIN_PREFIX}llvm-$TOOL
    if [ ! -f $FQFN ]
    then
        error $TOOL $LLVM_TOOLCHAIN_PREFIX
    fi
fi
which "$FQFN"