blob: 71f8e2b3afcf83c84c9463c15986ba4584f7f939 [file] [log] [blame]
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +00001#!/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
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000017# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19prog="$0"
20while [ -h "${prog}" ]; do
21 newProg=`/bin/ls -ld "${prog}"`
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000022 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
23 if expr "x${newProg}" : 'x/' >/dev/null; then
24 prog="${newProg}"
25 else
26 progdir=`dirname "${prog}"`
27 prog="${progdir}/${newProg}"
28 fi
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
35cd "${oldwd}"
36
37
Colin Cross568aba32017-12-12 21:27:57 -080038jarfile=smali.jar
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000039libdir="$progdir"
Ben Gruver9b6ec942011-11-16 10:19:56 -080040
41if [ ! -r "$libdir/$jarfile" ]; then
42 # set dx.jar location for the Android tree case
43 libdir=`dirname "$progdir"`/framework
44fi
45
46if [ ! -r "$libdir/$jarfile" ]; then
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000047 echo `basename "$prog"`": can't find $jarfile"
48 exit 1
49fi
50
Ben Gruver9b6ec942011-11-16 10:19:56 -080051
52# By default, give smali a max heap size of 256 mb. This can be overridden
53# by using a "-J" option (see below).
54defaultMx="-Xmx256M"
55
56# The following will extract any initial parameters of the form
57# "-J<stuff>" from the command line and pass them to the Java
58# invocation (instead of to dx). This makes it possible for you to add
59# a command-line parameter such as "-JXmx256M" in your scripts, for
60# example. "java" (with no args) and "java -X" give a summary of
61# available options.
62
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000063javaOpts=""
64
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000065while expr "x$1" : 'x-J' >/dev/null; do
Ben Gruver9b6ec942011-11-16 10:19:56 -080066 opt=`expr "x$1" : 'x-J\(.*\)'`
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000067 javaOpts="${javaOpts} -${opt}"
Ben Gruver9b6ec942011-11-16 10:19:56 -080068 if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then
69 defaultMx="no"
70 fi
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000071 shift
72done
73
Ben Gruver9b6ec942011-11-16 10:19:56 -080074if [ "${defaultMx}" != "no" ]; then
75 javaOpts="${javaOpts} ${defaultMx}"
76fi
77
78if [ "$OSTYPE" = "cygwin" ]; then
79 # For Cygwin, convert the jarfile path into native Windows style.
80 jarpath=`cygpath -w "$libdir/$jarfile"`
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000081else
Ben Gruver9b6ec942011-11-16 10:19:56 -080082 jarpath="$libdir/$jarfile"
JesusFreke@JesusFreke.com87e86492009-11-08 17:57:53 +000083fi
84
85exec java $javaOpts -jar "$jarpath" "$@"