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
25@rem Find java.exe
26if defined JAVA_HOME goto findJavaFromJavaHome
27
28set JAVA_EXE=java.exe
29%JAVA_EXE% -version >NUL 2>&1
30if "%ERRORLEVEL%" == "0" goto init
31
32echo.
33echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
34echo.
35echo Please set the JAVA_HOME variable in your environment to match the
36echo location of your Java installation.
37exit /b 1
38
39:findJavaFromJavaHome
40set JAVA_HOME=%JAVA_HOME:"=%
41set JAVA_EXE=%JAVA_HOME%/bin/java.exe
42
43if exist "%JAVA_EXE%" goto init
44
45echo.
46echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
47echo.
48echo Please set the JAVA_HOME variable in your environment to match the
49echo location of your Java installation.
50exit /b 1
51
52:init
53set jarfile=dx.jar
54set "frameworkdir=%~dp0"
55rem frameworkdir must not end with a dir sep.
56set "frameworkdir=%frameworkdir:~0,-1%"
57
58if exist "%frameworkdir%\%jarfile%" goto JarFileOk
59    set "frameworkdir=%~dp0lib"
60
61if exist "%frameworkdir%\%jarfile%" goto JarFileOk
62    set "frameworkdir=%~dp0..\framework"
63
64:JarFileOk
65
66set "jarpath=%frameworkdir%\%jarfile%"
67
68set javaOpts=
69set args=
70
71REM By default, give dx a max heap size of 1 gig and a stack size of 1meg.
72rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
73set defaultXmx=-Xmx1024M
74set defaultXss=-Xss1m
75
76REM Capture all arguments that are not -J options.
77REM Note that when reading the input arguments with %1, the cmd.exe
78REM automagically converts --name=value arguments into 2 arguments "--name"
79REM followed by "value". Dx has been changed to know how to deal with that.
80set params=
81
82:firstArg
83if [%1]==[] goto endArgs
84set a=%~1
85
86    if [%defaultXmx%]==[] goto notXmx
87    if %a:~0,5% NEQ -JXmx goto notXmx
88        set defaultXmx=
89    :notXmx
90
91    if [%defaultXss%]==[] goto notXss
92    if %a:~0,5% NEQ -JXss goto notXss
93        set defaultXss=
94    :notXss
95
96    if %a:~0,2% NEQ -J goto notJ
97        set javaOpts=%javaOpts% -%a:~2%
98        shift /1
99        goto firstArg
100
101    :notJ
102    set params=%params% %1
103    shift /1
104    goto firstArg
105
106:endArgs
107
108set javaOpts=%javaOpts% %defaultXmx% %defaultXss%
109call "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params%
110
111