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