xref: /aosp_15_r20/external/google-smali/scripts/smali (revision 37f5703ca959d1ce24046e7595880d209e15c133)
1#!/bin/bash
2#
3# Copyright (C) 2007 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# As per the Apache license requirements, this file has been modified
18# from its original state.
19#
20# Such modifications are Copyright (C) 2010 Ben Gruver, and are released
21# under the original license
22
23# This script is a wrapper for smali.jar, so you can simply call "smali",
24# instead of java -jar smali.jar. It is heavily based on the "dx" script
25# from the Android SDK
26
27# Set up prog to be the path of this script, including following symlinks,
28# and set up progdir to be the fully-qualified pathname of its directory.
29prog="$0"
30while [ -h "${prog}" ]; do
31    newProg=`/bin/ls -ld "${prog}"`
32    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
33    if expr "x${newProg}" : 'x/' >/dev/null; then
34        prog="${newProg}"
35    else
36        progdir=`dirname "${prog}"`
37        prog="${progdir}/${newProg}"
38    fi
39done
40oldwd=`pwd`
41progdir=`dirname "${prog}"`
42cd "${progdir}"
43progdir=`pwd`
44prog="${progdir}"/`basename "${prog}"`
45cd "${oldwd}"
46
47
48jarfile=android-smali.jar
49libdir="$progdir"
50
51if [ ! -r "$libdir/$jarfile" ]; then
52    # set location for the Android tree case
53    libdir=`dirname "$progdir"`/framework
54fi
55
56if [ ! -r "$libdir/$jarfile" ]; then
57    echo `basename "$prog"`": can't find $jarfile"
58    exit 1
59fi
60
61javaOpts=""
62
63# If you want DX to have more memory when executing, uncomment the following
64# line and adjust the value accordingly. Use "java -X" for a list of options
65# you can pass here.
66#
67javaOpts="-Xmx512M"
68
69# Alternatively, this will extract any parameter "-Jxxx" from the command line
70# and pass them to Java (instead of to dx). This makes it possible for you to
71# add a command-line parameter such as "-JXmx256M" in your ant scripts, for
72# example.
73while expr "x$1" : 'x-J' >/dev/null; do
74    opt=`expr "$1" : '-J\(.*\)'`
75    javaOpts="${javaOpts} -${opt}"
76    shift
77done
78
79if [ "$OSTYPE" = "cygwin" ] ; then
80    jarpath=`cygpath -w  "$libdir/$jarfile"`
81else
82    jarpath="$libdir/$jarfile"
83fi
84
85exec java $javaOpts -jar "$jarpath" "$@"
86