16b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll@echo off
26b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Copyright (C) 2007 The Android Open Source Project
36b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM
46b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Licensed under the Apache License, Version 2.0 (the "License");
56b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM you may not use this file except in compliance with the License.
66b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM You may obtain a copy of the License at
76b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM
86b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM     http://www.apache.org/licenses/LICENSE-2.0
96b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM
106b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Unless required by applicable law or agreed to in writing, software
116b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM distributed under the License is distributed on an "AS IS" BASIS,
126b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM See the License for the specific language governing permissions and
146b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM limitations under the License.
156b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
166b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM don't modify the caller's environment
176b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollsetlocal
186b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
196b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Locate dx.jar in the directory where dx.bat was found and start it.
206b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
216b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Set up prog to be the path of this script, including following symlinks,
226b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM and set up progdir to be the fully-qualified pathname of its directory.
236b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset prog=%~f0
246b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
251e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollrem Check we have a valid Java.exe in the path.
261e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset java_exe=
27c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyif exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
28c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyif exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"
291e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollif not defined java_exe goto :EOF
301e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll
316b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset jarfile=dx.jar
32c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyset "frameworkdir=%~dp0"
33c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyrem frameworkdir must not end with a dir sep.
34c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyset "frameworkdir=%frameworkdir:~0,-1%"
356b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
36c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyif exist "%frameworkdir%\%jarfile%" goto JarFileOk
37c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnelly    set "frameworkdir=%~dp0lib"
386b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
39c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyif exist "%frameworkdir%\%jarfile%" goto JarFileOk
40c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnelly    set "frameworkdir=%~dp0..\framework"
416b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
426b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll:JarFileOk
436b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
44c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellyset "jarpath=%frameworkdir%\%jarfile%"
456b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
466b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset javaOpts=
476b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset args=
486b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
49f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael MollREM By default, give dx a max heap size of 1 gig and a stack size of 1meg.
50f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollrem This can be overridden by using "-JXmx..." and "-JXss..." options below.
51f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset defaultXmx=-Xmx1024M
52f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset defaultXss=-Xss1m
536b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
54f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael MollREM Capture all arguments that are not -J options.
551e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM Note that when reading the input arguments with %1, the cmd.exe
561e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM automagically converts --name=value arguments into 2 arguments "--name"
571e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM followed by "value". Dx has been changed to know how to deal with that.
581e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset params=
596b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
601e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll:firstArg
611e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollif [%1]==[] goto endArgs
621e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset a=%~1
636b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
64f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if [%defaultXmx%]==[] goto notXmx
651e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    if %a:~0,5% NEQ -JXmx goto notXmx
66f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll        set defaultXmx=
676b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    :notXmx
686b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
69f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if [%defaultXss%]==[] goto notXss
70f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if %a:~0,5% NEQ -JXss goto notXss
71f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll        set defaultXss=
72f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    :notXss
73f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll
741e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    if %a:~0,2% NEQ -J goto notJ
751e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        set javaOpts=%javaOpts% -%a:~2%
761e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        shift /1
771e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        goto firstArg
786b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
796b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    :notJ
801e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    set params=%params% %1
811e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    shift /1
821e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    goto firstArg
836b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
846b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll:endArgs
856b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
86f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset javaOpts=%javaOpts% %defaultXmx% %defaultXss%
87c8a65232aab315fc83c970b0e5bd3e48ddc2d192Ray Donnellycall "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params%
886b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
89