dx.bat revision 6b9626d56c3ff84a6db7c15ea8bdcd62d11666d1
1@echo off
2REM Copyright (C) 2007 The Android Open Source Project
3REM
4REM Licensed under the Apache License, Version 2.0 (the "License");
5REM you may not use this file except in compliance with the License.
6REM You may obtain a copy of the License at
7REM
8REM     http://www.apache.org/licenses/LICENSE-2.0
9REM
10REM Unless required by applicable law or agreed to in writing, software
11REM distributed under the License is distributed on an "AS IS" BASIS,
12REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13REM See the License for the specific language governing permissions and
14REM limitations under the License.
15
16REM don't modify the caller's environment
17setlocal
18
19REM Locate dx.jar in the directory where dx.bat was found and start it.
20
21REM Set up prog to be the path of this script, including following symlinks,
22REM and set up progdir to be the fully-qualified pathname of its directory.
23set prog=%~f0
24
25REM Change current directory to where dx is, to avoid issues with directories
26REM containing whitespaces.
27cd /d %~dp0
28
29set jarfile=dx.jar
30set frameworkdir=
31
32if exist %frameworkdir%%jarfile% goto JarFileOk
33    set frameworkdir=lib\
34
35if exist %frameworkdir%%jarfile% goto JarFileOk
36    set frameworkdir=..\framework\
37
38:JarFileOk
39
40set jarpath=%frameworkdir%%jarfile%
41
42set javaOpts=
43set args=
44
45REM By default, give dx a max heap size of 1 gig. This can be overridden
46REM by using a "-JXmx..." option (see below).
47set defaultMx=-Xmx1024M
48
49REM capture all arguments to process them below
50set params=%*
51
52:nextArg
53if "%params%"=="" goto endArgs
54    REM Note: advanced substitions don't work on %1..%N. We need to assign to
55    REM a variable first.
56    REM We also can't use %1..%N directly because an option such as --output=name
57    REM gets automagically converted into %1=--output and %2=name (yes, really!)
58    REM Instead we manually extract the first token from the params variable.
59    for /F "tokens=1*" %%a in ("%params%") do call :getArg "%%a" "%%b"
60
61    if "%defaultMx%"=="" goto notXmx
62    if "%A:~0,5%" NEQ "-JXmx" goto notXmx
63        set defaultMx=
64    :notXmx
65
66    if "%A:~0,2%" NEQ "-J" goto notJ
67        set javaOpts=%javaOpts% -%A:~2%
68        goto nextArg
69
70    :notJ
71        set args=%args% %A%
72        goto nextArg
73
74:getArg
75    REM this subroutine is called by the for /F with the first argument of params
76    REM and the rest of the line. The "goto :eof" actually exits the subroutine.
77    set A=%~1
78    set params=%~2
79    goto :eof
80
81:endArgs
82
83set javaOpts=%javaOpts% %defaultMx%
84
85call java %javaOpts% -Djava.ext.dirs=%frameworkdir% -jar %jarpath% %args%
86