1*344a7f5eSAndroid Build Coastguard Worker#!/bin/bash 2*344a7f5eSAndroid Build Coastguard Worker# 3*344a7f5eSAndroid Build Coastguard Worker# Copyright (C) 2007 The Android Open Source Project 4*344a7f5eSAndroid Build Coastguard Worker# 5*344a7f5eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*344a7f5eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*344a7f5eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*344a7f5eSAndroid Build Coastguard Worker# 9*344a7f5eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*344a7f5eSAndroid Build Coastguard Worker# 11*344a7f5eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*344a7f5eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*344a7f5eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*344a7f5eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*344a7f5eSAndroid Build Coastguard Worker# limitations under the License. 16*344a7f5eSAndroid Build Coastguard Worker 17*344a7f5eSAndroid Build Coastguard Worker# Set up prog to be the path of this script, including following symlinks, 18*344a7f5eSAndroid Build Coastguard Worker# and set up progdir to be the fully-qualified pathname of its directory. 19*344a7f5eSAndroid Build Coastguard Workerprog="$0" 20*344a7f5eSAndroid Build Coastguard Workerwhile [ -h "${prog}" ]; do 21*344a7f5eSAndroid Build Coastguard Worker newProg=`/bin/ls -ld "${prog}"` 22*344a7f5eSAndroid Build Coastguard Worker newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 23*344a7f5eSAndroid Build Coastguard Worker if expr "x${newProg}" : 'x/' >/dev/null; then 24*344a7f5eSAndroid Build Coastguard Worker prog="${newProg}" 25*344a7f5eSAndroid Build Coastguard Worker else 26*344a7f5eSAndroid Build Coastguard Worker progdir=`dirname "${prog}"` 27*344a7f5eSAndroid Build Coastguard Worker prog="${progdir}/${newProg}" 28*344a7f5eSAndroid Build Coastguard Worker fi 29*344a7f5eSAndroid Build Coastguard Workerdone 30*344a7f5eSAndroid Build Coastguard Workeroldwd=`pwd` 31*344a7f5eSAndroid Build Coastguard Workerprogdir=`dirname "${prog}"` 32*344a7f5eSAndroid Build Coastguard Workercd "${progdir}" 33*344a7f5eSAndroid Build Coastguard Workerprogdir=`pwd` 34*344a7f5eSAndroid Build Coastguard Workerprog="${progdir}"/`basename "${prog}"` 35*344a7f5eSAndroid Build Coastguard Workercd "${oldwd}" 36*344a7f5eSAndroid Build Coastguard Worker 37*344a7f5eSAndroid Build Coastguard Workerjarfile=dx.jar 38*344a7f5eSAndroid Build Coastguard Workerlibdir="$progdir" 39*344a7f5eSAndroid Build Coastguard Worker 40*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 41*344a7f5eSAndroid Build Coastguard Worker # set dx.jar location for the SDK case 42*344a7f5eSAndroid Build Coastguard Worker libdir="$libdir/lib" 43*344a7f5eSAndroid Build Coastguard Workerfi 44*344a7f5eSAndroid Build Coastguard Worker 45*344a7f5eSAndroid Build Coastguard Worker 46*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 47*344a7f5eSAndroid Build Coastguard Worker # set dx.jar location for the Android tree case 48*344a7f5eSAndroid Build Coastguard Worker libdir=`dirname "$progdir"`/framework 49*344a7f5eSAndroid Build Coastguard Workerfi 50*344a7f5eSAndroid Build Coastguard Worker 51*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 52*344a7f5eSAndroid Build Coastguard Worker echo `basename "$prog"`": can't find $jarfile" 53*344a7f5eSAndroid Build Coastguard Worker exit 1 54*344a7f5eSAndroid Build Coastguard Workerfi 55*344a7f5eSAndroid Build Coastguard Worker 56*344a7f5eSAndroid Build Coastguard Worker# By default, give dx a max heap size of 1 gig. This can be overridden 57*344a7f5eSAndroid Build Coastguard Worker# by using a "-J" option (see below). 58*344a7f5eSAndroid Build Coastguard WorkerdefaultMx="-Xmx1024M" 59*344a7f5eSAndroid Build Coastguard Worker 60*344a7f5eSAndroid Build Coastguard Worker# The following will extract any initial parameters of the form 61*344a7f5eSAndroid Build Coastguard Worker# "-J<stuff>" from the command line and pass them to the Java 62*344a7f5eSAndroid Build Coastguard Worker# invocation (instead of to dx). This makes it possible for you to add 63*344a7f5eSAndroid Build Coastguard Worker# a command-line parameter such as "-JXmx256M" in your scripts, for 64*344a7f5eSAndroid Build Coastguard Worker# example. "java" (with no args) and "java -X" give a summary of 65*344a7f5eSAndroid Build Coastguard Worker# available options. 66*344a7f5eSAndroid Build Coastguard Worker 67*344a7f5eSAndroid Build Coastguard WorkerjavaOpts="" 68*344a7f5eSAndroid Build Coastguard Worker 69*344a7f5eSAndroid Build Coastguard Workerwhile expr "x$1" : 'x-J' >/dev/null; do 70*344a7f5eSAndroid Build Coastguard Worker opt=`expr "x$1" : 'x-J\(.*\)'` 71*344a7f5eSAndroid Build Coastguard Worker javaOpts="${javaOpts} -${opt}" 72*344a7f5eSAndroid Build Coastguard Worker if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then 73*344a7f5eSAndroid Build Coastguard Worker defaultMx="no" 74*344a7f5eSAndroid Build Coastguard Worker fi 75*344a7f5eSAndroid Build Coastguard Worker shift 76*344a7f5eSAndroid Build Coastguard Workerdone 77*344a7f5eSAndroid Build Coastguard Worker 78*344a7f5eSAndroid Build Coastguard Workerif [ "${defaultMx}" != "no" ]; then 79*344a7f5eSAndroid Build Coastguard Worker javaOpts="${javaOpts} ${defaultMx}" 80*344a7f5eSAndroid Build Coastguard Workerfi 81*344a7f5eSAndroid Build Coastguard Worker 82*344a7f5eSAndroid Build Coastguard Workerif [ "$OSTYPE" = "cygwin" ]; then 83*344a7f5eSAndroid Build Coastguard Worker # For Cygwin, convert the jarfile path into native Windows style. 84*344a7f5eSAndroid Build Coastguard Worker jarpath=`cygpath -w "$libdir/$jarfile"` 85*344a7f5eSAndroid Build Coastguard Workerelse 86*344a7f5eSAndroid Build Coastguard Worker jarpath="$libdir/$jarfile" 87*344a7f5eSAndroid Build Coastguard Workerfi 88*344a7f5eSAndroid Build Coastguard Worker 89*344a7f5eSAndroid Build Coastguard Workerexec java $javaOpts -jar "$jarpath" "$@" 90