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
256b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM Change current directory to where dx is, to avoid issues with directories
266b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael MollREM containing whitespaces.
276b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollcd /d %~dp0
286b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
291e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollrem Check we have a valid Java.exe in the path.
301e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset java_exe=
311e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollcall ..\tools\lib\find_java.bat
321e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollif not defined java_exe goto :EOF
331e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll
346b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset jarfile=dx.jar
356b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset frameworkdir=
366b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
376b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollif exist %frameworkdir%%jarfile% goto JarFileOk
386b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    set frameworkdir=lib\
396b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
406b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollif exist %frameworkdir%%jarfile% goto JarFileOk
416b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    set frameworkdir=..\framework\
426b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
436b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll:JarFileOk
446b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
456b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset jarpath=%frameworkdir%%jarfile%
466b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
476b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset javaOpts=
486b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Mollset args=
496b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
50f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael MollREM By default, give dx a max heap size of 1 gig and a stack size of 1meg.
51f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollrem This can be overridden by using "-JXmx..." and "-JXss..." options below.
52f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset defaultXmx=-Xmx1024M
53f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset defaultXss=-Xss1m
546b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
55f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael MollREM Capture all arguments that are not -J options.
561e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM Note that when reading the input arguments with %1, the cmd.exe
571e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM automagically converts --name=value arguments into 2 arguments "--name"
581e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael MollREM followed by "value". Dx has been changed to know how to deal with that.
591e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset params=
606b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
611e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll:firstArg
621e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollif [%1]==[] goto endArgs
631e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollset a=%~1
646b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
65f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if [%defaultXmx%]==[] goto notXmx
661e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    if %a:~0,5% NEQ -JXmx goto notXmx
67f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll        set defaultXmx=
686b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    :notXmx
696b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
70f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if [%defaultXss%]==[] goto notXss
71f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    if %a:~0,5% NEQ -JXss goto notXss
72f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll        set defaultXss=
73f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll    :notXss
74f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Moll
751e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    if %a:~0,2% NEQ -J goto notJ
761e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        set javaOpts=%javaOpts% -%a:~2%
771e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        shift /1
781e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll        goto firstArg
796b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
806b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll    :notJ
811e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    set params=%params% %1
821e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    shift /1
831e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Moll    goto firstArg
846b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
856b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll:endArgs
866b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
87f23d9bf98e020bc8e75ddb4c9f16c8d3dddbc229Raphael Mollset javaOpts=%javaOpts% %defaultXmx% %defaultXss%
886b9626d56c3ff84a6db7c15ea8bdcd62d11666d1Raphael Moll
891e4c4bebc1feb4b68155e9c2e7e6f2c056ef8e3bRaphael Mollcall %java_exe% %javaOpts% -Djava.ext.dirs=%frameworkdir% -jar %jarpath% %params%
90