@echo off

setlocal enabledelayedexpansion
setlocal enableextensions

set NOJAVA=nojava
if /i "%1" == "install" set NOJAVA=

call "%~dp0elasticsearch-env.bat" %NOJAVA% || exit /b 1

set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe
if "%SERVICE_ID%" == "" set SERVICE_ID=elasticsearch-service-x64
set ARCH=64-bit

if EXIST "%EXECUTABLE%" goto okExe
echo elasticsearch-service-x64.exe was not found...
exit /B 1

:okExe
set ES_VERSION=${project.version}

if "%SERVICE_LOG_DIR%" == "" set SERVICE_LOG_DIR=%ES_HOME%\logs

if "x%1x" == "xx" goto displayUsage
set SERVICE_CMD=%1
shift
if "x%1x" == "xx" goto checkServiceCmd
set SERVICE_ID=%1

:checkServiceCmd

if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%SERVICE_LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto

if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == start goto doStart
if /i %SERVICE_CMD% == stop goto doStop
if /i %SERVICE_CMD% == manager goto doManagment
echo Unknown option "%SERVICE_CMD%"
exit /B 1

:displayUsage
echo.
echo Usage: elasticsearch-service.bat install^|remove^|start^|stop^|manager [SERVICE_ID]
goto:eof

:doStart
"%EXECUTABLE%" //ES//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto started
echo Failed starting '%SERVICE_ID%' service
exit /B 1
goto:eof
:started
echo The service '%SERVICE_ID%' has been started
goto:eof

:doStop
"%EXECUTABLE%" //SS//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto stopped
echo Failed stopping '%SERVICE_ID%' service
exit /B 1
goto:eof
:stopped
echo The service '%SERVICE_ID%' has been stopped
goto:eof

:doManagment
set EXECUTABLE_MGR=%ES_HOME%\bin\elasticsearch-service-mgr
"%EXECUTABLE_MGR%" //ES//%SERVICE_ID%
if not errorlevel 1 goto managed
echo Failed starting service manager for '%SERVICE_ID%'
exit /B 1
goto:eof
:managed
echo Successfully started service manager for '%SERVICE_ID%'.
goto:eof

:doRemove
rem Remove the service
"%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto removed
echo Failed removing '%SERVICE_ID%' service
exit /B 1
goto:eof
:removed
echo The service '%SERVICE_ID%' has been removed
goto:eof

:doInstall
echo Installing service      :  "%SERVICE_ID%"
echo Using JAVA_HOME (%ARCH%):  "%JAVA_HOME%"

rem Check JVM server dll first
if exist "%JAVA_HOME%\jre\bin\server\jvm.dll" (
	set JVM_DLL=\jre\bin\server\jvm.dll
	goto foundJVM
)

rem Check 'server' JRE (JRE installed on Windows Server)
if exist "%JAVA_HOME%\bin\server\jvm.dll" (
	set JVM_DLL=\bin\server\jvm.dll
	goto foundJVM
) else (
  	echo JAVA_HOME ("%JAVA_HOME%"^) points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%\jre\bin\server" or "%JAVA_HOME%\bin\server"^). Exiting...
  	goto:eof
)

:foundJVM
if not defined ES_TMPDIR (
  for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory"`) do set ES_TMPDIR=%%a
)

rem The JVM options parser produces the final JVM options to start
rem Elasticsearch. It does this by incorporating JVM options in the following
rem way:
rem   - first, system JVM options are applied (these are hardcoded options in
rem     the parser)
rem   - second, JVM options are read from jvm.options and
rem     jvm.options.d/*.options
rem   - third, JVM options from ES_JAVA_OPTS are applied
rem   - fourth, ergonomic JVM options are applied

if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%

@setlocal
for /F "usebackq delims=" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_PATH_CONF!" || echo jvm_options_parser_failed"`) do set ES_JAVA_OPTS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%ES_JAVA_OPTS%" & set ES_JAVA_OPTS=%ES_JAVA_OPTS%

if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
  exit /b 1
)

if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%

if "%ES_JAVA_OPTS:~-1%"==";" set ES_JAVA_OPTS=%ES_JAVA_OPTS:~0,-1%

echo %ES_JAVA_OPTS%

@setlocal EnableDelayedExpansion
for %%a in ("%ES_JAVA_OPTS:;=","%") do (
  set var=%%a
  set other_opt=true
  if "!var:~1,4!" == "-Xms" (
    set XMS=!var:~5,-1!
    set other_opt=false
    call:convertxm !XMS! JVM_MS
  )
  if "!var:~1,16!" == "-XX:MinHeapSize=" (
    set XMS=!var:~17,-1!
    set other_opt=false
    call:convertxm !XMS! JVM_MS
  )
  if "!var:~1,4!" == "-Xmx" (
    set XMX=!var:~5,-1!
    set other_opt=false
    call:convertxm !XMX! JVM_MX
  )
  if "!var:~1,16!" == "-XX:MaxHeapSize=" (
    set XMX=!var:~17,-1!
    set other_opt=false
    call:convertxm !XMX! JVM_MX
  )
  if "!var:~1,4!" == "-Xss" (
    set XSS=!var:~5,-1!
    set other_opt=false
    call:convertxk !XSS! JVM_SS
  )
  if "!var:~1,20!" == "-XX:ThreadStackSize=" (
    set XSS=!var:~21,-1!
    set other_opt=false
    call:convertxk !XSS! JVM_SS
  )
  if "!other_opt!" == "true" set OTHER_JAVA_OPTS=!OTHER_JAVA_OPTS!;!var!
)
@endlocal & set JVM_MS=%JVM_MS% & set JVM_MX=%JVM_MX% & set JVM_SS=%JVM_SS% & set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS%

if "%JVM_MS%" == "" (
  echo minimum heap size not set; configure using -Xms via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
if "%JVM_MX%" == "" (
  echo maximum heap size not set; configure using -Xmx via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
if "%JVM_SS%" == "" (
  echo thread stack size not set; configure using -Xss via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS:"=%
set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS:~1%

set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.path.conf="%ES_PATH_CONF%";-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%";-Des.distribution.type="%ES_DISTRIBUTION_TYPE%";-Des.bundled_jdk="%ES_BUNDLED_JDK%"

if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0

if "%SERVICE_DISPLAY_NAME%" == "" set SERVICE_DISPLAY_NAME=Elasticsearch %ES_VERSION% (%SERVICE_ID%)
if "%SERVICE_DESCRIPTION%" == "" set SERVICE_DESCRIPTION=Elasticsearch %ES_VERSION% Windows Service - https://elastic.co

if not "%SERVICE_USERNAME%" == "" (
	if not "%SERVICE_PASSWORD%" == "" (
		set SERVICE_PARAMS=%SERVICE_PARAMS% --ServiceUser "%SERVICE_USERNAME%" --ServicePassword "%SERVICE_PASSWORD%"
	)
)
"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main ++StartParams --quiet --StopClass org.elasticsearch.bootstrap.Elasticsearch --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %OTHER_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%JAVA_HOME%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% ++Environment HOSTNAME="%%COMPUTERNAME%%"

if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_ID%' service
exit /B 1
goto:eof

:installed
echo The service '%SERVICE_ID%' has been installed.
goto:eof

:err
echo JAVA_HOME environment variable must be set!
pause
goto:eof

rem ---
rem Function for converting Xm[s|x] values into MB which Commons Daemon accepts
rem ---
:convertxm
set value=%~1
rem extract last char (unit)
set unit=%value:~-1%
rem assume the unit is specified
set conv=%value:~0,-1%

if "%unit%" == "k" goto kilo
if "%unit%" == "K" goto kilo
if "%unit%" == "m" goto mega
if "%unit%" == "M" goto mega
if "%unit%" == "g" goto giga
if "%unit%" == "G" goto giga

rem no unit found, must be bytes; consider the whole value
set conv=%value%
rem convert to KB
set /a conv=%conv% / 1024
:kilo
rem convert to MB
set /a conv=%conv% / 1024
goto mega
:giga
rem convert to MB
set /a conv=%conv% * 1024
:mega
set "%~2=%conv%"
goto:eof

:convertxk
set value=%~1
rem extract last char (unit)
set unit=%value:~-1%
rem assume the unit is specified
set conv=%value:~0,-1%

if "%unit%" == "k" goto kilo
if "%unit%" == "K" goto kilo
if "%unit%" == "m" goto mega
if "%unit%" == "M" goto mega
if "%unit%" == "g" goto giga
if "%unit%" == "G" goto giga

rem no unit found, must be bytes; consider the whole value
set conv=%value%
rem convert to KB
set /a conv=%conv% / 1024
goto kilo
:mega
rem convert to KB
set /a conv=%conv% * 1024
goto kilo
:giga
rem convert to KB
set /a conv=%conv% * 1024 * 1024
:kilo
set "%~2=%conv%"
goto:eof

endlocal
endlocal

exit /b %ERRORLEVEL%

@echo off

setlocal enabledelayedexpansion
setlocal enableextensions

set NOJAVA=nojava
if /i "%1" == "install" set NOJAVA=

call "%~dp0elasticsearch-env.bat" %NOJAVA% || exit /b 1

set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe
if "%SERVICE_ID%" == "" set SERVICE_ID=elasticsearch-service-x64
set ARCH=64-bit

if EXIST "%EXECUTABLE%" goto okExe
echo elasticsearch-service-x64.exe was not found...
exit /B 1

:okExe
set ES_VERSION=${project.version}

if "%SERVICE_LOG_DIR%" == "" set SERVICE_LOG_DIR=%ES_HOME%\logs

if "x%1x" == "xx" goto displayUsage
set SERVICE_CMD=%1
shift
if "x%1x" == "xx" goto checkServiceCmd
set SERVICE_ID=%1

:checkServiceCmd

if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%SERVICE_LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto

if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == start goto doStart
if /i %SERVICE_CMD% == stop goto doStop
if /i %SERVICE_CMD% == manager goto doManagment
echo Unknown option "%SERVICE_CMD%"
exit /B 1

:displayUsage
echo.
echo Usage: elasticsearch-service.bat install^|remove^|start^|stop^|manager [SERVICE_ID]
goto:eof

:doStart
"%EXECUTABLE%" //ES//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto started
echo Failed starting '%SERVICE_ID%' service
exit /B 1
goto:eof
:started
echo The service '%SERVICE_ID%' has been started
goto:eof

:doStop
"%EXECUTABLE%" //SS//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto stopped
echo Failed stopping '%SERVICE_ID%' service
exit /B 1
goto:eof
:stopped
echo The service '%SERVICE_ID%' has been stopped
goto:eof

:doManagment
set EXECUTABLE_MGR=%ES_HOME%\bin\elasticsearch-service-mgr
"%EXECUTABLE_MGR%" //ES//%SERVICE_ID%
if not errorlevel 1 goto managed
echo Failed starting service manager for '%SERVICE_ID%'
exit /B 1
goto:eof
:managed
echo Successfully started service manager for '%SERVICE_ID%'.
goto:eof

:doRemove
rem Remove the service
"%EXECUTABLE%" //DS//%SERVICE_ID% %LOG_OPTS%
if not errorlevel 1 goto removed
echo Failed removing '%SERVICE_ID%' service
exit /B 1
goto:eof
:removed
echo The service '%SERVICE_ID%' has been removed
goto:eof

:doInstall
echo Installing service      :  "%SERVICE_ID%"
echo Using JAVA_HOME (%ARCH%):  "%JAVA_HOME%"

rem Check JVM server dll first
if exist "%JAVA_HOME%\jre\bin\server\jvm.dll" (
	set JVM_DLL=\jre\bin\server\jvm.dll
	goto foundJVM
)

rem Check 'server' JRE (JRE installed on Windows Server)
if exist "%JAVA_HOME%\bin\server\jvm.dll" (
	set JVM_DLL=\bin\server\jvm.dll
	goto foundJVM
) else (
  	echo JAVA_HOME ("%JAVA_HOME%"^) points to an invalid Java installation (no jvm.dll found in "%JAVA_HOME%\jre\bin\server" or "%JAVA_HOME%\bin\server"^). Exiting...
  	goto:eof
)

:foundJVM
if not defined ES_TMPDIR (
  for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory"`) do set ES_TMPDIR=%%a
)

rem The JVM options parser produces the final JVM options to start
rem Elasticsearch. It does this by incorporating JVM options in the following
rem way:
rem   - first, system JVM options are applied (these are hardcoded options in
rem     the parser)
rem   - second, JVM options are read from jvm.options and
rem     jvm.options.d/*.options
rem   - third, JVM options from ES_JAVA_OPTS are applied
rem   - fourth, ergonomic JVM options are applied

if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%

@setlocal
for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set ES_JAVA_OPTS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%ES_JAVA_OPTS%" & set ES_JAVA_OPTS=%ES_JAVA_OPTS%

if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
  exit /b 1
)

if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%

if "%ES_JAVA_OPTS:~-1%"==";" set ES_JAVA_OPTS=%ES_JAVA_OPTS:~0,-1%

echo %ES_JAVA_OPTS%

@setlocal EnableDelayedExpansion
for %%a in ("%ES_JAVA_OPTS:;=","%") do (
  set var=%%a
  set other_opt=true
  if "!var:~1,4!" == "-Xms" (
    set XMS=!var:~5,-1!
    set other_opt=false
    call:convertxm !XMS! JVM_MS
  )
  if "!var:~1,16!" == "-XX:MinHeapSize=" (
    set XMS=!var:~17,-1!
    set other_opt=false
    call:convertxm !XMS! JVM_MS
  )
  if "!var:~1,4!" == "-Xmx" (
    set XMX=!var:~5,-1!
    set other_opt=false
    call:convertxm !XMX! JVM_MX
  )
  if "!var:~1,16!" == "-XX:MaxHeapSize=" (
    set XMX=!var:~17,-1!
    set other_opt=false
    call:convertxm !XMX! JVM_MX
  )
  if "!var:~1,4!" == "-Xss" (
    set XSS=!var:~5,-1!
    set other_opt=false
    call:convertxk !XSS! JVM_SS
  )
  if "!var:~1,20!" == "-XX:ThreadStackSize=" (
    set XSS=!var:~21,-1!
    set other_opt=false
    call:convertxk !XSS! JVM_SS
  )
  if "!other_opt!" == "true" set OTHER_JAVA_OPTS=!OTHER_JAVA_OPTS!;!var!
)
@endlocal & set JVM_MS=%JVM_MS% & set JVM_MX=%JVM_MX% & set JVM_SS=%JVM_SS% & set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS%

if "%JVM_MS%" == "" (
  echo minimum heap size not set; configure using -Xms via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
if "%JVM_MX%" == "" (
  echo maximum heap size not set; configure using -Xmx via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
if "%JVM_SS%" == "" (
  echo thread stack size not set; configure using -Xss via "%ES_PATH_CONF%/jvm.options.d", or ES_JAVA_OPTS
  goto:eof
)
set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS:"=%
set OTHER_JAVA_OPTS=%OTHER_JAVA_OPTS:~1%

set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.path.conf="%ES_PATH_CONF%";-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%";-Des.distribution.type="%ES_DISTRIBUTION_TYPE%";-Des.bundled_jdk="%ES_BUNDLED_JDK%"

if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0

if "%SERVICE_DISPLAY_NAME%" == "" set SERVICE_DISPLAY_NAME=Elasticsearch %ES_VERSION% (%SERVICE_ID%)
if "%SERVICE_DESCRIPTION%" == "" set SERVICE_DESCRIPTION=Elasticsearch %ES_VERSION% Windows Service - https://elastic.co

if not "%SERVICE_USERNAME%" == "" (
	if not "%SERVICE_PASSWORD%" == "" (
		set SERVICE_PARAMS=%SERVICE_PARAMS% --ServiceUser "%SERVICE_USERNAME%" --ServicePassword "%SERVICE_PASSWORD%"
	)
)
"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main ++StartParams --quiet --StopClass org.elasticsearch.bootstrap.Elasticsearch --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %OTHER_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%JAVA_HOME%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% ++Environment HOSTNAME="%%COMPUTERNAME%%"

if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_ID%' service
exit /B 1
goto:eof

:installed
echo The service '%SERVICE_ID%' has been installed.
goto:eof

:err
echo JAVA_HOME environment variable must be set!
pause
goto:eof

rem ---
rem Function for converting Xm[s|x] values into MB which Commons Daemon accepts
rem ---
:convertxm
set value=%~1
rem extract last char (unit)
set unit=%value:~-1%
rem assume the unit is specified
set conv=%value:~0,-1%

if "%unit%" == "k" goto kilo
if "%unit%" == "K" goto kilo
if "%unit%" == "m" goto mega
if "%unit%" == "M" goto mega
if "%unit%" == "g" goto giga
if "%unit%" == "G" goto giga

rem no unit found, must be bytes; consider the whole value
set conv=%value%
rem convert to KB
set /a conv=%conv% / 1024
:kilo
rem convert to MB
set /a conv=%conv% / 1024
goto mega
:giga
rem convert to MB
set /a conv=%conv% * 1024
:mega
set "%~2=%conv%"
goto:eof

:convertxk
set value=%~1
rem extract last char (unit)
set unit=%value:~-1%
rem assume the unit is specified
set conv=%value:~0,-1%

if "%unit%" == "k" goto kilo
if "%unit%" == "K" goto kilo
if "%unit%" == "m" goto mega
if "%unit%" == "M" goto mega
if "%unit%" == "g" goto giga
if "%unit%" == "G" goto giga

rem no unit found, must be bytes; consider the whole value
set conv=%value%
rem convert to KB
set /a conv=%conv% / 1024
goto kilo
:mega
rem convert to KB
set /a conv=%conv% * 1024
goto kilo
:giga
rem convert to KB
set /a conv=%conv% * 1024 * 1024
:kilo
set "%~2=%conv%"
goto:eof

endlocal
endlocal

exit /b %ERRORLEVEL%

Handle special chars in JAVA_HOME in elasticsearch-service.bat (#52676)


@REM ----------------------------------------------------------------------------
@REM  Copyright 2001-2006 The Apache Software Foundation.
@REM
@REM  Licensed under the Apache License, Version 2.0 (the "License");
@REM  you may not use this file except in compliance with the License.
@REM  You may obtain a copy of the License at
@REM
@REM       http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM  Unless required by applicable law or agreed to in writing, software
@REM  distributed under the License is distributed on an "AS IS" BASIS,
@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@REM  See the License for the specific language governing permissions and
@REM  limitations under the License.
@REM ----------------------------------------------------------------------------
@REM
@REM   Copyright (c) 2001-2006 The Apache Software Foundation.  All rights
@REM   reserved.

@echo off

set ERROR_CODE=0

:init
@REM Decide how to startup depending on the version of windows

@REM -- Win98ME
if NOT "%OS%"=="Windows_NT" goto Win9xArg

@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" @setlocal

@REM -- 4NT shell
if "%eval[2+2]" == "4" goto 4NTArgs

@REM -- Regular WinNT shell
set CMD_LINE_ARGS=%*
goto WinNTGetScriptDir

@REM The 4NT Shell from jp software
:4NTArgs
set CMD_LINE_ARGS=%$
goto WinNTGetScriptDir

:Win9xArg
@REM Slurp the command line arguments.  This loop allows for an unlimited number
@REM of arguments (up to the command line limit, anyway).
set CMD_LINE_ARGS=
:Win9xApp
if %1a==a goto Win9xGetScriptDir
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto Win9xApp

:Win9xGetScriptDir
set SAVEDIR=%CD%
%0\
cd %0\..\..
set BASEDIR=%CD%
cd %SAVEDIR%
set SAVE_DIR=
goto repoSetup

:WinNTGetScriptDir
set BASEDIR=%~dp0\..

:repoSetup
set REPO=

if "%JAVACMD%"=="" set JAVACMD=java

if "%REPO%"=="" set REPO=%BASEDIR%\lib

set CLASSPATH="%BASEDIR%"\conf;"%REPO%"\*

set ENDORSED_DIR=
if NOT "%ENDORSED_DIR%" == "" set CLASSPATH="%BASEDIR%"\%ENDORSED_DIR%\*;%CLASSPATH%

if NOT "%CLASSPATH_PREFIX%" == "" set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH%

@REM Reaching here means variables are defined and arguments have been captured
:endInit

%JAVACMD% %JAVA_OPTS% -Djndi.bind.off="true" -classpath %CLASSPATH% -Dapp.name="forget-me" -Dapp.repo="%REPO%" -Dapp.home="%BASEDIR%" -Dbasedir="%BASEDIR%" org.wso2.carbon.privacy.forgetme.ForgetMeTool %CMD_LINE_ARGS%
if %ERRORLEVEL% NEQ 0 goto error
goto end

:error
if "%OS%"=="Windows_NT" @endlocal
set ERROR_CODE=%ERRORLEVEL%

:end
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" goto endNT

@REM For old DOS remove the set variables from ENV - we assume they were not set
@REM before we started - at least we don't leave any baggage around
set CMD_LINE_ARGS=
goto postExec

:endNT
@REM If error code is set to 1 then the endlocal was done already in :error.
if %ERROR_CODE% EQU 0 @endlocal

:postExec

if "%FORCE_EXIT_ON_ERROR%" == "on" (
  if %ERROR_CODE% NEQ 0 exit %ERROR_CODE%
)

exit /B %ERROR_CODE%

@REM ----------------------------------------------------------------------------
@REM  Copyright 2001-2006 The Apache Software Foundation.
@REM
@REM  Licensed under the Apache License, Version 2.0 (the "License");
@REM  you may not use this file except in compliance with the License.
@REM  You may obtain a copy of the License at
@REM
@REM       http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM  Unless required by applicable law or agreed to in writing, software
@REM  distributed under the License is distributed on an "AS IS" BASIS,
@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@REM  See the License for the specific language governing permissions and
@REM  limitations under the License.
@REM ----------------------------------------------------------------------------
@REM
@REM   Copyright (c) 2001-2006 The Apache Software Foundation.  All rights
@REM   reserved.

@echo off

set ERROR_CODE=0

:init
@REM Decide how to startup depending on the version of windows

@REM -- Win98ME
if NOT "%OS%"=="Windows_NT" goto Win9xArg

@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" @setlocal

@REM -- 4NT shell
if "%eval[2+2]" == "4" goto 4NTArgs

@REM -- Regular WinNT shell
set CMD_LINE_ARGS=%*
goto WinNTGetScriptDir

@REM The 4NT Shell from jp software
:4NTArgs
set CMD_LINE_ARGS=%$
goto WinNTGetScriptDir

:Win9xArg
@REM Slurp the command line arguments.  This loop allows for an unlimited number
@REM of arguments (up to the command line limit, anyway).
set CMD_LINE_ARGS=
:Win9xApp
if %1a==a goto Win9xGetScriptDir
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto Win9xApp

:Win9xGetScriptDir
set SAVEDIR=%CD%
%0\
cd %0\..\..
set BASEDIR=%CD%
cd %SAVEDIR%
set SAVE_DIR=
goto repoSetup

:WinNTGetScriptDir
set BASEDIR=%~dp0\..

:repoSetup
set REPO=

if "%JAVACMD%"=="" set JAVACMD=java

if "%REPO%"=="" set REPO=%BASEDIR%\lib

set CLASSPATH="%BASEDIR%"\conf;"%REPO%"\*

set ENDORSED_DIR=
if NOT "%ENDORSED_DIR%" == "" set CLASSPATH="%BASEDIR%"\%ENDORSED_DIR%\*;%CLASSPATH%

if NOT "%CLASSPATH_PREFIX%" == "" set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH%

FOR %%C in ("%BASEDIR%\..\..\plugins\*.jar") DO set CLASSPATH=!CLASSPATH!;"%BASEDIR%\..\..\plugins\%%~nC%%~xC"

FOR %%C in ("%BASEDIR%\..\..\..\..\lib\*.jar") DO set CLASSPATH=!CLASSPATH!;"%BASEDIR%\..\..\..\..\lib\%%~nC%%~xC"

@REM Reaching here means variables are defined and arguments have been captured
:endInit

%JAVACMD% %JAVA_OPTS% -Djndi.bind.off="true" -classpath %CLASSPATH% -Dapp.name="forget-me" -Dapp.repo="%REPO%" -Dapp.home="%BASEDIR%" -Dbasedir="%BASEDIR%" org.wso2.carbon.privacy.forgetme.ForgetMeTool %CMD_LINE_ARGS%
if %ERRORLEVEL% NEQ 0 goto error
goto end

:error
if "%OS%"=="Windows_NT" @endlocal
set ERROR_CODE=%ERRORLEVEL%

:end
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" goto endNT

@REM For old DOS remove the set variables from ENV - we assume they were not set
@REM before we started - at least we don't leave any baggage around
set CMD_LINE_ARGS=
goto postExec

:endNT
@REM If error code is set to 1 then the endlocal was done already in :error.
if %ERROR_CODE% EQU 0 @endlocal

:postExec

if "%FORCE_EXIT_ON_ERROR%" == "on" (
  if %ERROR_CODE% NEQ 0 exit %ERROR_CODE%
)

exit /B %ERROR_CODE%

Add lib and plugins to classpath

Add lib and plugins to classpath


@echo off
SetLocal ENABLEDELAYEDEXPANSION
echo.Building the TTR Mouse Click Simulator...
echo.
REM MSBuild is always installed in the 32-Bit program files folder
if "!ProgramFiles(x86)!"=="" (
	set "ProgramFiles32Bit=!ProgramFiles!"
) else (
	set "ProgramFiles32Bit=!ProgramFiles(x86)!"
)
set "BuildExe=!ProgramFiles32Bit!\MSBuild\14.0\Bin\MSBuild.exe"

if not exist "!BuildExe!" (
	echo.ERROR: MSBuild not found at "!BuildExe!"!
	pause
	exit /b
)

"!BuildExe!" /v:minimal /p:Configuration=Release "TTMouseclickSimulator\TTMouseclickSimulator.csproj"
if not errorlevel 1 (
	echo.
	echo.Build successful^^!
)
pause

@echo off
SetLocal ENABLEDELAYEDEXPANSION
echo.Building the TTR Mouse Click Simulator...
echo.
REM MSBuild is always installed in the 32-Bit program files folder
if "!ProgramFiles(x86)!"=="" (
	set "ProgramFiles32Bit=!ProgramFiles!"
) else (
	set "ProgramFiles32Bit=!ProgramFiles(x86)!"
)
set "BuildExe=!ProgramFiles32Bit!\MSBuild\14.0\Bin\MSBuild.exe"

if not exist "!BuildExe!" (
	echo.ERROR: MSBuild not found at "!BuildExe!"^^!
	pause
	exit /b
)

"!BuildExe!" /v:minimal /p:Configuration=Release "TTMouseclickSimulator\TTMouseclickSimulator.csproj"
if not errorlevel 1 (
	echo.
	echo.Build successful^^!
)
pause

Use correct escape character.

Use correct escape character.


PUSHD otp
git reset --hard
git clean -d -f -x
NuGet.exe Restore Albireo.Base32.sln
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Albireo.Base32.sln /property:Configuration=Debug /maxcpucount /nodeReuse:false
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Albireo.Base32.sln /property:Configuration=Release /maxcpucount /nodeReuse:false
NuGet.exe Pack Albireo.Base32\Albireo.Base32.csproj -Prop Configuration=Release -Symbols
POPD
PAUSE

Add build script

Add build script


@rem Copyright 2016, Google Inc.
@rem All rights reserved.
@rem
@rem Redistribution and use in source and binary forms, with or without
@rem modification, are permitted provided that the following conditions are
@rem met:
@rem
@rem     * Redistributions of source code must retain the above copyright
@rem notice, this list of conditions and the following disclaimer.
@rem     * Redistributions in binary form must reproduce the above
@rem copyright notice, this list of conditions and the following disclaimer
@rem in the documentation and/or other materials provided with the
@rem distribution.
@rem     * Neither the name of Google Inc. nor the names of its
@rem contributors may be used to endorse or promote products derived from
@rem this software without specific prior written permission.
@rem
@rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@rem A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
@rem OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
@rem SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
@rem LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@rem DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@rem THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
@rem (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@rem OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mkdir artifacts

setlocal
cd third_party/protobuf

powershell -Command "Invoke-WebRequest https://googlemock.googlecode.com/files/gmock-1.7.0.zip -OutFile gmock.zip"
powershell -Command "Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('gmock.zip', '.');"
rename gmock-1.7.0 gmock

cd cmake
cmake -G "%generator%" || goto :error
endlocal

call vsprojects/build_plugins.bat || goto :error

xcopy /Y third_party\protobuf\cmake\Release\protoc.exe artifacts\ || goto :error
xcopy /Y vsprojects\Release\*_plugin.exe artifacts\ || xcopy /Y vsprojects\x64\Release\*_plugin.exe artifacts\ || goto :error

goto :EOF

:error
exit /b 1

@rem Copyright 2016, Google Inc.
@rem All rights reserved.
@rem
@rem Redistribution and use in source and binary forms, with or without
@rem modification, are permitted provided that the following conditions are
@rem met:
@rem
@rem     * Redistributions of source code must retain the above copyright
@rem notice, this list of conditions and the following disclaimer.
@rem     * Redistributions in binary form must reproduce the above
@rem copyright notice, this list of conditions and the following disclaimer
@rem in the documentation and/or other materials provided with the
@rem distribution.
@rem     * Neither the name of Google Inc. nor the names of its
@rem contributors may be used to endorse or promote products derived from
@rem this software without specific prior written permission.
@rem
@rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@rem A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
@rem OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
@rem SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
@rem LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@rem DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@rem THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
@rem (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@rem OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mkdir artifacts

setlocal
cd third_party/protobuf

cd cmake
cmake -G "%generator%" -Dprotobuf_BUILD_TESTS=OFF || goto :error
endlocal

call vsprojects/build_plugins.bat || goto :error

xcopy /Y third_party\protobuf\cmake\Release\protoc.exe artifacts\ || goto :error
xcopy /Y vsprojects\Release\*_plugin.exe artifacts\ || xcopy /Y vsprojects\x64\Release\*_plugin.exe artifacts\ || goto :error

goto :EOF

:error
exit /b 1

remove dead gmock link in protoc artifact build


@echo off

rem
rem  This script runs the nightly build.
rem
rem  Since it is the starting point for the build chain, it must be manually put into
rem  place for the build server to run.
rem

set BUILD_ROOT=C:\builds
set BRANCH=master
set GIT_REPO_ROOT="/git/xtuml"
set PT_HOME=\utilities\bp_build_tools\bridgepoint
set PT_HOME_DRIVE=c:
set XTUMLGEN_HOME=c:\utilities\bp_build_tools\bridgepoint
set MGLS_DLL=c:\utilities\mgls\Mgls.dll
set MGLS_PKGINFO_FILE=c:\utilities\mgls\mgc.pkginfo
echo BUILD_ROOT=%BUILD_ROOT%
echo BRANCH=%BRANCH%
echo GIT_REPO_ROOT=%GIT_REPO_ROOT%
echo PT_HOME=%PT_HOME%
echo PT_HOME_DRIVE=%PT_HOME_DRIVE%
echo XTUMLGEN_HOME=%XTUMLGEN_HOME%
echo MGLS_DLL=%MGLS_DLL%
echo MGLS_PKGINFO_FILE=%MGLS_PKGINFO_FILE%
echo MGLS_LICENSE_FILE=%MGLS_LICENSE_FILE%

C:
chdir %BUILD_ROOT%
pushd .

path c:\cygwin\bin;%Path%

echo Initializing git repositories...
dos2unix -q init_git_repositories.sh
bash init_git_repositories.sh "%BRANCH%" "%GIT_REPO_ROOT%" "yes" > cfg_output.log
echo Done.

echo Initializing the eclipse bases and build tools from SVN...
cp -f %GIT_REPO_ROOT%/internal/utilities/build/init_svn_tools.sh .
dos2unix -q init_svn_tools.sh
bash init_svn_tools.sh "%BRANCH%" "nonrelease" >> cfg_output.log
echo Done.

echo Setting Windows EXE & DLL permissions...
icacls "c:\\utilities\\bp_build_tools" /grant build:(OI)(CI)F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\xtumlmc_build.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\gen_erate.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\libTRANS.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\msvcrt.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\vgal8c.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\gen_erate.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\msvcrt.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\vgalaxy8.vr" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\lib\\libTRANS.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\lib\\vgal8c.dll.dll" /grant build:F
icacls "c:\\utilities\\mgls\\Mgls.dll" /grant build:F
echo Done.

echo Configuring build process...
cp -f %GIT_REPO_ROOT%/internal/utilities/build/configure_build_process.sh .
dos2unix -q configure_build_process.sh
bash configure_build_process.sh %BRANCH% %GIT_REPO_ROOT% nonrelease >> cfg_output.log
echo Done.

echo Processing the build...
chdir %BRANCH%
bash process_build.sh %BRANCH% %GIT_REPO_ROOT% nonrelease > build_output.log
echo Done.

rem Clean up build files
popd
move configure_build_process.sh %BRANCH%
move init_svn_tools.sh %BRANCH%
move %BRANCH%\build_output.log %BRANCH%\log

chdir %BUILD_ROOT%

echo end of run_nightly_build_git.bat

rem Clean up build files
popd
move configure_build_process.sh %BRANCH%
move init_svn_tools.sh %BRANCH%
move %BRANCH%\build_output.log %BRANCH%\log

chdir %BUILD_ROOT%

echo end of run_nightly_build_git.bat

@echo off

rem
rem  This script runs the nightly build.
rem
rem  Since it is the starting point for the build chain, it must be manually put into
rem  place for the build server to run.
rem

set BUILD_ROOT=C:\builds
set BRANCH=master
set GIT_REPO_ROOT="/git/xtuml"
set PT_HOME=\utilities\bp_build_tools\bridgepoint
set PT_HOME_DRIVE=c:
set XTUMLGEN_HOME=c:\utilities\bp_build_tools\bridgepoint
set MGLS_DLL=c:\utilities\mgls\Mgls.dll
set MGLS_PKGINFO_FILE=c:\utilities\mgls\mgc.pkginfo
set MGLS_LICENSE_FILE=1717@wv-lic-01.wv.mentorg.com;1717@wv-lic-02.wv.mentorg.com
echo BUILD_ROOT=%BUILD_ROOT%
echo BRANCH=%BRANCH%
echo GIT_REPO_ROOT=%GIT_REPO_ROOT%
echo PT_HOME=%PT_HOME%
echo PT_HOME_DRIVE=%PT_HOME_DRIVE%
echo XTUMLGEN_HOME=%XTUMLGEN_HOME%
echo MGLS_DLL=%MGLS_DLL%
echo MGLS_PKGINFO_FILE=%MGLS_PKGINFO_FILE%
echo MGLS_LICENSE_FILE=%MGLS_LICENSE_FILE%

C:
chdir %BUILD_ROOT%
pushd .

path c:\cygwin\bin;%Path%

echo "Initializing git repositories..."
dos2unix -q init_git_repositories.sh
bash init_git_repositories.sh "%BRANCH%" "%GIT_REPO_ROOT%" "yes" > cfg_output.log
echo "Done."

echo "Initializing the eclipse bases and build tools from SVN..."
cp -f %GIT_REPO_ROOT%/internal/utilities/build/init_svn_tools.sh .
dos2unix -q init_svn_tools.sh
bash init_svn_tools.sh "%BRANCH%" "nonrelease" >> cfg_output.log
echo "Done."

echo "Setting Windows EXE & DLL permissions..."
icacls "c:\\utilities\\bp_build_tools" /grant build:(OI)(CI)F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\xtumlmc_build.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\gen_erate.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\libTRANS.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\msvcrt.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\mc3020\\bin\\vgal8c.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\gen_erate.exe" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\msvcrt.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\bin\\vgalaxy8.vr" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\lib\\libTRANS.dll" /grant build:F
icacls "c:\\utilities\\bp_build_tools\\bridgepoint\\win32\\client\\lib\\vgal8c.dll" /grant build:F
icacls "c:\\utilities\\mgls\\Mgls.dll" /grant build:F
echo "Done."

echo "Configuring build process..."
cp -f %GIT_REPO_ROOT%/internal/utilities/build/configure_build_process.sh .
dos2unix -q configure_build_process.sh
bash configure_build_process.sh %BRANCH% %GIT_REPO_ROOT% nonrelease >> cfg_output.log
echo "Done."

echo "Processing the build..."
chdir %BRANCH%
bash process_build.sh %BRANCH% %GIT_REPO_ROOT% nonrelease > build_output.log
echo "Done."

rem Clean up build files
popd
move configure_build_process.sh %BRANCH%
move init_svn_tools.sh %BRANCH%
move %BRANCH%\build_output.log %BRANCH%\log

chdir %BUILD_ROOT%

echo "End of run_nightly_build_git.bat"

Update run_nightly_build_git.bat

Update run_nightly_build_git.bat

job #1 - More fixes to work nicely on WinServer 2003


@echo off

cd %APPVEYOR_BUILD_FOLDER%

:: =========================================================
:: Set some defaults. Infer some variables.
::
:: These are set globally
if "%LUA_VER%" NEQ "" (
	set LUA=lua
	set LUA_SHORTV=%LUA_VER:~0,3%
) else (
	set LUA=luajit
	set LJ_SHORTV=%LJ_VER:~0,3%
	set LUA_SHORTV=5.1
)

:: defines LUA_DIR so Cmake can find this Lua install
if "%LUA%"=="luajit" (
	set LUA_DIR=c:\lua\%platform%\lj%LJ_SHORTV%
) else (
	set LUA_DIR=c:\lua\%platform%\%LUA_VER%
)

:: Now we declare a scope
Setlocal EnableDelayedExpansion EnableExtensions

if "%LUAROCKS_VER%" NEQ "HEAD" (
	set LUAROCKS_SHORTV=%LUAROCKS_VER:~0,3%
) else (
	:: Assume 2.2 for the time being. TODO: fix this
	set LUAROCKS_SHORTV=2.2
)

if not defined LUAROCKS_URL set LUAROCKS_URL=http://keplerproject.github.io/luarocks/releases
if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org
if not defined LUA_URL set LUA_URL=http://www.lua.org/ftp
if defined NOCOMPAT (
	set COMPATFLAG=--nocompat
) else (
	set COMPATFLAG=
)
if not defined LUAJIT_GIT_REPO set LUAJIT_GIT_REPO=http://luajit.org/git/luajit-2.0.git
if not defined LUAJIT_URL set LUAJIT_URL=http://luajit.org/download

if not defined LR_EXTERNAL set LR_EXTERNAL=c:\external
if not defined LUAROCKS_INSTALL set LUAROCKS_INSTALL=%LUA_DIR%\LuaRocks
if not defined LR_ROOT set LR_ROOT=%LUAROCKS_INSTALL%\%LUAROCKS_SHORTV%
if not defined LR_SYSTREE set LR_SYSTREE=%LUAROCKS_INSTALL%\systree

if not defined SEVENZIP set SEVENZIP=7z
::
:: =========================================================

:: first create some necessary directories:
mkdir downloads 2>NUL

:: Download and compile Lua (or LuaJIT)
if "%LUA%"=="luajit" (
	if not exist %LUA_DIR% (
		if "%LJ_SHORTV%"=="2.1" (
			:: Clone repository and checkout 2.1 branch
			set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
			if not exist !lj_source_folder! (
				echo Cloning git repo %LUAJIT_GIT_REPO% !lj_source_folder!
				git clone %LUAJIT_GIT_REPO% !lj_source_folder! || call :die "Failed to clone repository"
			) else (
				cd !lj_source_folder!
				git pull || call :die "Failed to update repository"
			)
			cd !lj_source_folder!\src
			git checkout v2.1 || call :die
		) else (
			set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
			if not exist !lj_source_folder! (
				echo Downloading... %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz
				curl --silent --fail --max-time 120 --connect-timeout 30 %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
			)
			cd !lj_source_folder!\src
		)
		:: Compiles LuaJIT
		call msvcbuild.bat

		mkdir %LUA_DIR% 2> NUL
		for %%a in (bin bin\lua bin\lua\jit include lib) do ( mkdir "%LUA_DIR%\%%a" )

		for %%a in (luajit.exe lua51.dll) do ( move "!lj_source_folder!\src\%%a" "%LUA_DIR%\bin" )
		copy "%LUA_DIR%\bin\luajit.exe" "%LUA_DIR%\bin\lua.exe"

		move "!lj_source_folder!\src\lua51.lib" "%LUA_DIR%\lib"
		for %%a in (lauxlib.h lua.h lua.hpp luaconf.h lualib.h luajit.h) do (
			copy "!lj_source_folder!\src\%%a" "%LUA_DIR%\include"
		)

		copy "!lj_source_folder!\src\jit\*.lua" "%LUA_DIR%\bin\lua\jit"

	) else (
		echo LuaJIT %LJ_VER% already installed at %LUA_DIR%
	)
) else (
	if not exist %LUA_DIR% (
		:: Download and compile Lua
		if not exist downloads\lua-%LUA_VER% (
			curl --silent --fail --max-time 120 --connect-timeout 30 %LUA_URL%/lua-%LUA_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
		)

		mkdir downloads\lua-%LUA_VER%\etc 2> NUL
		copy winmake.bat downloads\lua-%LUA_VER%\etc\winmake.bat

		cd downloads\lua-%LUA_VER%
		call etc\winmake %COMPATFLAG%
		call etc\winmake install %LUA_DIR%
	) else (
		echo Lua %LUA_VER% already installed at %LUA_DIR%
	)
)

if not exist %LUA_DIR%\bin\%LUA%.exe call :die "Missing Lua interpreter at %LUA_DIR%\bin\%LUA%.exe"

set PATH=%LUA_DIR%\bin;%PATH%
call !LUA! -v

:: =========================================================
:: LuaRocks
:: =========================================================

if not exist "%LR_ROOT%" (
	:: Downloads and installs LuaRocks
	cd %APPVEYOR_BUILD_FOLDER%

	if %LUAROCKS_VER%==HEAD (
		set lr_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luarocks-%LUAROCKS_VER%-win32
		if not exist !lr_source_folder! (
			git clone https://github.com/keplerproject/luarocks.git --single-branch --depth 1 !lr_source_folder! || call :die "Failed to clone LuaRocks repository"
		) else (
			cd !lr_source_folder!
			git pull || call :die "Failed to update LuaRocks repository"
		)
	) else (
		if not exist downloads\luarocks-%LUAROCKS_VER%-win32.zip (
			echo Downloading LuaRocks...
			curl --silent --fail --max-time 120 --connect-timeout 30 --output downloads\luarocks-%LUAROCKS_VER%-win32.zip %LUAROCKS_URL%/luarocks-%LUAROCKS_VER%-win32.zip
			%SEVENZIP% x -aoa -odownloads downloads\luarocks-%LUAROCKS_VER%-win32.zip
		)
	)

	cd downloads\luarocks-%LUAROCKS_VER%-win32
	call install.bat /LUA %LUA_DIR% /Q /LV %LUA_SHORTV% /P "%LUAROCKS_INSTALL%" /TREE "%LR_SYSTREE%"
)

if not exist "%LR_ROOT%" call :die "LuaRocks not found at %LR_ROOT%"

set PATH=%LR_ROOT%;%LR_SYSTREE%\bin;%PATH%

:: Lua will use just the system rocks
set LUA_PATH=%LR_ROOT%\lua\?.lua;%LR_ROOT%\lua\?\init.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?\init.lua
set LUA_PATH=%LUA_PATH%;.\?.lua;.\?\init.lua
set LUA_CPATH=%LR_SYSTREE%\lib\lua\%LUA_SHORTV%\?.dll;.\?.dll

call luarocks --version || call :die "Error with LuaRocks installation"
call luarocks list

if not exist "%LR_EXTERNAL%" (
	mkdir "%LR_EXTERNAL%"
	mkdir "%LR_EXTERNAL%\lib"
	mkdir "%LR_EXTERNAL%\include"
)

set PATH=%LR_EXTERNAL%;%PATH%

:: Exports the following variables:
:: (beware of whitespace between & and ^ below)
endlocal & set PATH=%PATH%&^
set LR_SYSTREE=%LR_SYSTREE%&^
set LUA_PATH=%LUA_PATH%&^
set LUA_CPATH=%LUA_CPATH%&^
set LR_EXTERNAL=%LR_EXTERNAL%

echo.
echo ======================================================
if "%LUA%"=="luajit" (
	echo Installation of LuaJIT %LJ_VER% and LuaRocks %LUAROCKS_VER% done.
) else (
	echo Installation of Lua %LUA_VER% and LuaRocks %LUAROCKS_VER% done.
	if defined NOCOMPAT echo Lua was built with compatibility flags disabled.
)
echo Platform         - %platform%
echo LUA              - %LUA%
echo LUA_SHORTV       - %LUA_SHORTV%
echo LJ_SHORTV        - %LJ_SHORTV%
echo LUA_PATH         - %LUA_PATH%
echo LUA_CPATH        - %LUA_CPATH%
echo.
echo LR_EXTERNAL      - %LR_EXTERNAL%
echo ======================================================
echo.

goto :eof

:: This blank space is intentional. If you see errors like "The system cannot find the batch label specified 'foo'"
:: then try adding or removing blank lines lines above.
:: Yes, really.
:: http://stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-e

:: helper functions:

:: for bailing out when an error occurred
:die %1
echo %1
exit /B 1
goto :eof

@echo off

cd %APPVEYOR_BUILD_FOLDER%

:: =========================================================
:: Set some defaults. Infer some variables.
::
:: These are set globally
if "%LUA_VER%" NEQ "" (
	set LUA=lua
	set LUA_SHORTV=%LUA_VER:~0,3%
) else (
	set LUA=luajit
	set LJ_SHORTV=%LJ_VER:~0,3%
	set LUA_SHORTV=5.1
)

:: defines LUA_DIR so Cmake can find this Lua install
if "%LUA%"=="luajit" (
	set LUA_DIR=c:\lua\%platform%\lj%LJ_SHORTV%
) else (
	set LUA_DIR=c:\lua\%platform%\%LUA_VER%
)

:: Now we declare a scope
Setlocal EnableDelayedExpansion EnableExtensions

if "%LUAROCKS_VER%" NEQ "HEAD" (
	set LUAROCKS_SHORTV=%LUAROCKS_VER:~0,3%
) else (
	:: Assume 2.2 for the time being. TODO: fix this
	set LUAROCKS_SHORTV=2.2
)

if not defined LUAROCKS_URL set LUAROCKS_URL=http://keplerproject.github.io/luarocks/releases
if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org
if not defined LUA_URL set LUA_URL=http://www.lua.org/ftp
if defined NOCOMPAT (
	set COMPATFLAG=--nocompat
) else (
	set COMPATFLAG=
)
if not defined LUAJIT_GIT_REPO set LUAJIT_GIT_REPO=http://luajit.org/git/luajit-2.0.git
if not defined LUAJIT_URL set LUAJIT_URL=http://luajit.org/download

if not defined LR_EXTERNAL set LR_EXTERNAL=c:\external
if not defined LUAROCKS_INSTALL set LUAROCKS_INSTALL=%LUA_DIR%\LuaRocks
if not defined LR_ROOT set LR_ROOT=%LUAROCKS_INSTALL%\%LUAROCKS_SHORTV%
if not defined LR_SYSTREE set LR_SYSTREE=%LUAROCKS_INSTALL%\systree

if not defined SEVENZIP set SEVENZIP=7z
::
:: =========================================================

:: first create some necessary directories:
mkdir downloads 2>NUL

:: Download and compile Lua (or LuaJIT)
if "%LUA%"=="luajit" (
	if not exist %LUA_DIR% (
		if "%LJ_SHORTV%"=="2.1" (
			:: Clone repository and checkout 2.1 branch
			set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
			if not exist !lj_source_folder! (
				echo Cloning git repo %LUAJIT_GIT_REPO% !lj_source_folder!
				git clone %LUAJIT_GIT_REPO% !lj_source_folder! || call :die "Failed to clone repository"
			) else (
				cd !lj_source_folder!
				git pull || call :die "Failed to update repository"
			)
			cd !lj_source_folder!\src
			git checkout v2.1 || call :die
		) else (
			set lj_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luajit-%LJ_VER%
			if not exist !lj_source_folder! (
				echo Downloading... %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz
				curl --silent --fail --max-time 120 --connect-timeout 30 %LUAJIT_URL%/LuaJIT-%LJ_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
			)
			cd !lj_source_folder!\src
		)
		:: Compiles LuaJIT
		call msvcbuild.bat

		mkdir %LUA_DIR% 2> NUL
		for %%a in (bin bin\lua bin\lua\jit include lib) do ( mkdir "%LUA_DIR%\%%a" )

		for %%a in (luajit.exe lua51.dll) do ( move "!lj_source_folder!\src\%%a" "%LUA_DIR%\bin" )
		copy "%LUA_DIR%\bin\luajit.exe" "%LUA_DIR%\bin\lua.exe"

		move "!lj_source_folder!\src\lua51.lib" "%LUA_DIR%\lib"
		for %%a in (lauxlib.h lua.h lua.hpp luaconf.h lualib.h luajit.h) do (
			copy "!lj_source_folder!\src\%%a" "%LUA_DIR%\include"
		)

		copy "!lj_source_folder!\src\jit\*.lua" "%LUA_DIR%\bin\lua\jit"

	) else (
		echo LuaJIT %LJ_VER% already installed at %LUA_DIR%
	)
) else (
	if not exist %LUA_DIR% (
		:: Download and compile Lua
		if not exist downloads\lua-%LUA_VER% (
			curl --silent --fail --max-time 120 --connect-timeout 30 %LUA_URL%/lua-%LUA_VER%.tar.gz | %SEVENZIP% x -si -so -tgzip | %SEVENZIP% x -si -ttar -aoa -odownloads
		)

		mkdir downloads\lua-%LUA_VER%\etc 2> NUL
		copy %~dp\winmake.bat downloads\lua-%LUA_VER%\etc\winmake.bat

		cd downloads\lua-%LUA_VER%
		call etc\winmake %COMPATFLAG%
		call etc\winmake install %LUA_DIR%
	) else (
		echo Lua %LUA_VER% already installed at %LUA_DIR%
	)
)

if not exist %LUA_DIR%\bin\%LUA%.exe call :die "Missing Lua interpreter at %LUA_DIR%\bin\%LUA%.exe"

set PATH=%LUA_DIR%\bin;%PATH%
call !LUA! -v

:: =========================================================
:: LuaRocks
:: =========================================================

if not exist "%LR_ROOT%" (
	:: Downloads and installs LuaRocks
	cd %APPVEYOR_BUILD_FOLDER%

	if %LUAROCKS_VER%==HEAD (
		set lr_source_folder=%APPVEYOR_BUILD_FOLDER%\downloads\luarocks-%LUAROCKS_VER%-win32
		if not exist !lr_source_folder! (
			git clone https://github.com/keplerproject/luarocks.git --single-branch --depth 1 !lr_source_folder! || call :die "Failed to clone LuaRocks repository"
		) else (
			cd !lr_source_folder!
			git pull || call :die "Failed to update LuaRocks repository"
		)
	) else (
		if not exist downloads\luarocks-%LUAROCKS_VER%-win32.zip (
			echo Downloading LuaRocks...
			curl --silent --fail --max-time 120 --connect-timeout 30 --output downloads\luarocks-%LUAROCKS_VER%-win32.zip %LUAROCKS_URL%/luarocks-%LUAROCKS_VER%-win32.zip
			%SEVENZIP% x -aoa -odownloads downloads\luarocks-%LUAROCKS_VER%-win32.zip
		)
	)

	cd downloads\luarocks-%LUAROCKS_VER%-win32
	call install.bat /LUA %LUA_DIR% /Q /LV %LUA_SHORTV% /P "%LUAROCKS_INSTALL%" /TREE "%LR_SYSTREE%"
)

if not exist "%LR_ROOT%" call :die "LuaRocks not found at %LR_ROOT%"

set PATH=%LR_ROOT%;%LR_SYSTREE%\bin;%PATH%

:: Lua will use just the system rocks
set LUA_PATH=%LR_ROOT%\lua\?.lua;%LR_ROOT%\lua\?\init.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?.lua
set LUA_PATH=%LUA_PATH%;%LR_SYSTREE%\share\lua\%LUA_SHORTV%\?\init.lua
set LUA_PATH=%LUA_PATH%;.\?.lua;.\?\init.lua
set LUA_CPATH=%LR_SYSTREE%\lib\lua\%LUA_SHORTV%\?.dll;.\?.dll

call luarocks --version || call :die "Error with LuaRocks installation"
call luarocks list

if not exist "%LR_EXTERNAL%" (
	mkdir "%LR_EXTERNAL%"
	mkdir "%LR_EXTERNAL%\lib"
	mkdir "%LR_EXTERNAL%\include"
)

set PATH=%LR_EXTERNAL%;%PATH%

:: Exports the following variables:
:: (beware of whitespace between & and ^ below)
endlocal & set PATH=%PATH%&^
set LR_SYSTREE=%LR_SYSTREE%&^
set LUA_PATH=%LUA_PATH%&^
set LUA_CPATH=%LUA_CPATH%&^
set LR_EXTERNAL=%LR_EXTERNAL%

echo.
echo ======================================================
if "%LUA%"=="luajit" (
	echo Installation of LuaJIT %LJ_VER% and LuaRocks %LUAROCKS_VER% done.
) else (
	echo Installation of Lua %LUA_VER% and LuaRocks %LUAROCKS_VER% done.
	if defined NOCOMPAT echo Lua was built with compatibility flags disabled.
)
echo Platform         - %platform%
echo LUA              - %LUA%
echo LUA_SHORTV       - %LUA_SHORTV%
echo LJ_SHORTV        - %LJ_SHORTV%
echo LUA_PATH         - %LUA_PATH%
echo LUA_CPATH        - %LUA_CPATH%
echo.
echo LR_EXTERNAL      - %LR_EXTERNAL%
echo ======================================================
echo.

goto :eof

:: This blank space is intentional. If you see errors like "The system cannot find the batch label specified 'foo'"
:: then try adding or removing blank lines lines above.
:: Yes, really.
:: http://stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-e

:: helper functions:

:: for bailing out when an error occurred
:die %1
echo %1
exit /B 1
goto :eof

Fix wrong location of winmake.bat

Fix wrong location of winmake.bat


@ECHO OFF

SETLOCAL EnableDelayedExpansion

SET ScriptRoot=%~dp0

IF %ScriptRoot:~-1%==\ SET ScriptRoot=%ScriptRoot:~0,-1%

PUSHD "%ScriptRoot%"

SET DeviceName=%1
SET BuildTarget=%2
SET BuildConfiguration=%3
SET BuildVerbosity=%4
SET GccDirectory=%5

IF "%BuildTarget%" == "" SET BuildTarget=build
IF "%BuildConfiguration%" == "" SET BuildConfiguration=release
IF "%BuildVerbosity%" == "" SET BuildVerbosity=quiet

IF NOT EXIST "%ScriptRoot%\Devices\%DeviceName%" (
    ECHO Unsupported device passed: %DeviceName%
    GOTO :EOF
)

IF NOT "%BuildTarget%" == "build" IF NOT "%BuildTarget%" == "cleanbuild" IF NOT "%BuildTarget%" == "clean" (
    ECHO Unsupported target passed: %BuildTarget%
    GOTO :EOF
)

IF NOT "%BuildConfiguration%" == "debug" IF NOT "%BuildConfiguration%" == "release" (
    ECHO Unsupported configuration passed: %BuildConfiguration%
    GOTO :EOF
)

IF NOT EXIST "%GccDirectory%" SET GccDirectory=C:\Program Files (x86)\GNU Tools ARM Embedded\7 2017-q4-major
IF NOT EXIST "%GccDirectory%" SET GccDirectory=C:\Program Files\GNU Tools ARM Embedded\7 2017-q4-major

IF NOT EXIST "%GccDirectory%" (
    ECHO Cannot find GCC. Try passing the directory explicitly like `build.bat device build release normal "C:\Program Files (x86)\GNU Tools ARM Embedded\7 2017-q4-major"`
    GOTO :EOF
)

IF "%GccDirectory:~-1%"=="\" SET "GccDirectory=%GccDirectory:~0,-1%"

SET DeviceBuildConfiguration=%ScriptRoot%\Devices\%DeviceName%\BuildConfiguration.txt

IF NOT EXIST "%DeviceBuildConfiguration%" (
    ECHO Cannot find device configuration at "%DeviceBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%DeviceBuildConfiguration%") DO SET %%A=%%B

IF "%TargetName%" == "" (
    ECHO TargetName not defined in "%DeviceBuildConfiguration%".
    GOTO :EOF
)

SET TargetBuildConfiguration=%ScriptRoot%\Targets\%TargetName%\BuildConfiguration.txt

IF NOT EXIST "%TargetBuildConfiguration%" (
    ECHO Cannot find target configuration at "%TargetBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%TargetBuildConfiguration%") DO SET %%A=%%B

IF "%TargetArchitecture%" == "" (
    ECHO TargetArchitecture not defined in "%TargetBuildConfiguration%".
    GOTO :EOF
)

SET LibraryBuildConfiguration=%ScriptRoot%\Core\%TargetArchitecture%BuildConfiguration.txt

IF NOT EXIST "%LibraryBuildConfiguration%" (
    ECHO Cannot find library configuration at "%LibraryBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%LibraryBuildConfiguration%") DO SET "%%A=%%B"

IF "%NeedCmsis%" == "1" (
    IF NOT EXIST "%ScriptRoot%\CMSIS\ARM.CMSIS.pdsc" (
        ECHO Cannot find CMSIS. Please make sure it is downloaded and extracted to repo_root\CMSIS.
        GOTO :EOF
    )
)

SET AdditionalIncludes=%AdditionalIncludes% -I"%GccDirectory%\lib\gcc\arm-none-eabi\7.2.1\include"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Targets\%TargetName%"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Devices\%DeviceName%"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Core"

SET AdditionalDefines=%AdditionalDefines% -DGCC
SET AdditionalCompilerArguments=-mstructure-size-boundary=8 -fno-exceptions -ffunction-sections -fdata-sections -fshort-wchar -funsigned-char -mlong-calls

IF "%BuildConfiguration%" == "debug" (
    SET AdditionalDefines=%AdditionalDefines% -DDEBUG -D_DEBUG
    SET AdditionalAssemblerArguments=%AdditionalAssemblerArguments% -g
    SET AdditionalCompilerArguments=-O0 -femit-class-debug-always -g3 -ggdb %AdditionalCompilerArguments%
) ELSE (
    SET AdditionalDefines=%AdditionalDefines%
    SET AssemblerCompileArguments=%AdditionalAssemblerArguments%
    SET AdditionalCompilerArguments=%OptimizeLevel% %AdditionalCompilerArguments%
)

SET OutputDirectory=%ScriptRoot%\Build\%BuildConfiguration%\%DeviceName%
SET CoreDirectory=%ScriptRoot%\Core
SET CoreLibraryFile=%CoreDirectory%\TinyCLR_%TargetArchitecture%.lib
SET CoreHeaderFile=%CoreDirectory%\TinyCLR.h

IF "%BuildTarget%" == "cleanbuild" (
    SET DoClean=1
    SET DoBuild=1
) ELSE IF "%BuildTarget%" == "build" (
    SET DoClean=0
    SET DoBuild=1
) ELSE IF "%BuildTarget%" == "clean" (
    SET DoClean=1
    SET DoBuild=0
)

IF "%DoClean%" == "1" IF EXIST "%OutputDirectory%" (
    RMDIR /S /Q "%OutputDirectory%"
)

IF "%DoBuild%" == "1" (
    IF NOT EXIST "%OutputDirectory%" MD "%OutputDirectory%"

    IF NOT EXIST "%CoreLibraryFile%" (
        ECHO Cannot find the core library file. Please make sure it is downloaded and extracted to repo_root\Core\TinyCLR_%TargetArchitecture%.lib.
        GOTO :EOF
    )

    IF NOT EXIST "%CoreHeaderFile%" (
        ECHO Cannot find the core header file. Please make sure it is downloaded and extracted to repo_root\Core\TinyCLR.h.
        GOTO :EOF
    )

    SET CompilePaths="%ScriptRoot%\Targets\%TargetName%", "%ScriptRoot%\Devices\%DeviceName%", "%ScriptRoot%\Main"

    IF NOT "%AdditionalDrivers%" == "" (
        FOR %%A IN (!AdditionalDrivers!) DO SET CompilePaths=!CompilePaths!, "%ScriptRoot%\Drivers\%%A"
    )

    FOR %%A IN (!CompilePaths!) DO (
        PUSHD "%%A"

        FOR /R %%B IN ("*.gcc.s") DO (
            ECHO %%B

            "%GccDirectory%\bin\arm-none-eabi-as.exe" %AdditionalAssemblerArguments% -mcpu=%MCpu% -mlittle-endian %FloatCompileArguments% -o "%OutputDirectory%\%%~nB.obj" "%%B"
        )

        FOR /R %%B IN ("*.cpp") DO (
            ECHO %%B

            "%GccDirectory%\bin\arm-none-eabi-g++.exe" -std=c++11 -xc++ %AdditionalCompilerArguments% -mcpu=%MCpu% -mlittle-endian %FloatCompileArguments% %AdditionalDefines% %AdditionalIncludes% -o "%OutputDirectory%\%%~nB.obj" -c "%%B"
        )

        POPD
    )

    "%GccDirectory%\bin\arm-none-eabi-g++.exe" -mcpu=%MCpu% -mlittle-endian -nostartfiles %FloatCompileArguments% -Xlinker %AdditionalCompilerArguments% -L "%GccLibrary%" -Wl,-static,--gc-sections,--no-wchar-size-warning,-Map="%OutputDirectory%\%DeviceName% Firmware.map" -specs="%GccLibrary%\nano.specs" -T"%ScriptRoot%\Devices\%DeviceName%\Scatterfile.gcc.ldf" "%OutputDirectory%\*.obj" "%CoreLibraryFile%" -o "%OutputDirectory%\%DeviceName% Firmware.axf"

    "%GccDirectory%\bin\arm-none-eabi-objcopy.exe" -S -j ER_FLASH -j ER_RAM_RO -j ER_RAM_RW -O binary "%OutputDirectory%\%DeviceName% Firmware.axf" "%OutputDirectory%\%DeviceName% Firmware.bin"
    "%GccDirectory%\bin\arm-none-eabi-objcopy.exe" -S -R ER_DAT -R ER_CONFIG -O ihex "%OutputDirectory%\%DeviceName% Firmware.axf" "%OutputDirectory%\%DeviceName% Firmware.hex"

    IF NOT "%ImageGenParameters%" == ""  "%ScriptRoot%\imagegen.exe" %ImageGenParameters% "%OutputDirectory%\%DeviceName% Firmware.bin"
)

ECHO Done

POPD

ENDLOCAL

@ECHO OFF

SETLOCAL EnableDelayedExpansion

SET ScriptRoot=%~dp0

IF %ScriptRoot:~-1%==\ SET ScriptRoot=%ScriptRoot:~0,-1%

PUSHD "%ScriptRoot%"

SET DeviceName=%1
SET BuildTarget=%2
SET BuildConfiguration=%3
SET BuildVerbosity=%4
SET GccDirectory=%5

IF "%BuildTarget%" == "" SET BuildTarget=build
IF "%BuildConfiguration%" == "" SET BuildConfiguration=release
IF "%BuildVerbosity%" == "" SET BuildVerbosity=quiet

IF NOT EXIST "%ScriptRoot%\Devices\%DeviceName%" (
    ECHO Unsupported device passed: %DeviceName%
    GOTO :EOF
)

IF NOT "%BuildTarget%" == "build" IF NOT "%BuildTarget%" == "cleanbuild" IF NOT "%BuildTarget%" == "clean" (
    ECHO Unsupported target passed: %BuildTarget%
    GOTO :EOF
)

IF NOT "%BuildConfiguration%" == "debug" IF NOT "%BuildConfiguration%" == "release" (
    ECHO Unsupported configuration passed: %BuildConfiguration%
    GOTO :EOF
)

IF NOT EXIST "%GccDirectory%" SET GccDirectory=C:\Program Files (x86)\GNU Tools ARM Embedded\7 2017-q4-major
IF NOT EXIST "%GccDirectory%" SET GccDirectory=C:\Program Files\GNU Tools ARM Embedded\7 2017-q4-major

IF NOT EXIST "%GccDirectory%" (
    ECHO Cannot find GCC. Try passing the directory explicitly like `build.bat device build release normal "C:\Program Files (x86)\GNU Tools ARM Embedded\7 2017-q4-major"`
    GOTO :EOF
)

IF "%GccDirectory:~-1%"=="\" SET "GccDirectory=%GccDirectory:~0,-1%"

SET DeviceBuildConfiguration=%ScriptRoot%\Devices\%DeviceName%\BuildConfiguration.txt

IF NOT EXIST "%DeviceBuildConfiguration%" (
    ECHO Cannot find device configuration at "%DeviceBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%DeviceBuildConfiguration%") DO SET %%A=%%B

IF "%TargetName%" == "" (
    ECHO TargetName not defined in "%DeviceBuildConfiguration%".
    GOTO :EOF
)

SET TargetBuildConfiguration=%ScriptRoot%\Targets\%TargetName%\BuildConfiguration.txt

IF NOT EXIST "%TargetBuildConfiguration%" (
    ECHO Cannot find target configuration at "%TargetBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%TargetBuildConfiguration%") DO SET %%A=%%B

IF "%TargetArchitecture%" == "" (
    ECHO TargetArchitecture not defined in "%TargetBuildConfiguration%".
    GOTO :EOF
)

SET LibraryBuildConfiguration=%ScriptRoot%\Core\%TargetArchitecture%BuildConfiguration.txt

IF NOT EXIST "%LibraryBuildConfiguration%" (
    ECHO Cannot find library configuration at "%LibraryBuildConfiguration%".
    GOTO :EOF
)

FOR /F "usebackq tokens=1,2 delims=:" %%A IN ("%LibraryBuildConfiguration%") DO SET "%%A=%%B"

IF "%NeedCmsis%" == "1" (
    IF NOT EXIST "%ScriptRoot%\CMSIS\ARM.CMSIS.pdsc" (
        ECHO Cannot find CMSIS. Please make sure it is downloaded and extracted to repo_root\CMSIS.
        GOTO :EOF
    )
)

SET AdditionalIncludes=%AdditionalIncludes% -I"%GccDirectory%\lib\gcc\arm-none-eabi\7.2.1\include"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Targets\%TargetName%"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Devices\%DeviceName%"
SET AdditionalIncludes=%AdditionalIncludes% -I"%ScriptRoot%\Core"

SET AdditionalDefines=%AdditionalDefines% -DGCC
SET AdditionalCompilerArguments=-mstructure-size-boundary=8 -fno-exceptions -ffunction-sections -fdata-sections -fshort-wchar -funsigned-char -mlong-calls

IF "%BuildConfiguration%" == "debug" (
    SET AdditionalDefines=%AdditionalDefines% -DDEBUG -D_DEBUG
    SET AdditionalAssemblerArguments=%AdditionalAssemblerArguments% -g
    SET AdditionalCompilerArguments=-O0 -femit-class-debug-always -g3 -ggdb %AdditionalCompilerArguments%
) ELSE (
    SET AdditionalDefines=%AdditionalDefines%
    SET AssemblerCompileArguments=%AdditionalAssemblerArguments%
    SET AdditionalCompilerArguments=%OptimizeLevel% %AdditionalCompilerArguments%
)

SET OutputDirectory=%ScriptRoot%\Build\%BuildConfiguration%\%DeviceName%
SET CoreDirectory=%ScriptRoot%\Core
SET CoreLibraryFile=%CoreDirectory%\TinyCLR_%TargetArchitecture%.lib
SET CoreHeaderFile=%CoreDirectory%\TinyCLR.h

IF "%BuildTarget%" == "cleanbuild" (
    SET DoClean=1
    SET DoBuild=1
) ELSE IF "%BuildTarget%" == "build" (
    SET DoClean=0
    SET DoBuild=1
) ELSE IF "%BuildTarget%" == "clean" (
    SET DoClean=1
    SET DoBuild=0
)

IF "%DoClean%" == "1" IF EXIST "%OutputDirectory%" (
    RMDIR /S /Q "%OutputDirectory%"
)

IF "%DoBuild%" == "1" (
    IF NOT EXIST "%OutputDirectory%" MD "%OutputDirectory%"

    IF NOT EXIST "%CoreLibraryFile%" (
        ECHO Cannot find the core library file. Please make sure it is downloaded and extracted to repo_root\Core\TinyCLR_%TargetArchitecture%.lib.
        GOTO :EOF
    )

    IF NOT EXIST "%CoreHeaderFile%" (
        ECHO Cannot find the core header file. Please make sure it is downloaded and extracted to repo_root\Core\TinyCLR.h.
        GOTO :EOF
    )

    SET CompilePaths="%ScriptRoot%\Targets\%TargetName%", "%ScriptRoot%\Devices\%DeviceName%", "%ScriptRoot%\Main"

    IF NOT "%AdditionalTargetDrivers%" == "" (
        FOR %%A IN (!AdditionalTargetDrivers!) DO SET CompilePaths=!CompilePaths!, "%ScriptRoot%\Drivers\%%A"
    )

    IF NOT "%AdditionalDeviceDrivers%" == "" (
        FOR %%A IN (!AdditionalDeviceDrivers!) DO SET CompilePaths=!CompilePaths!, "%ScriptRoot%\Drivers\%%A"
    )

    FOR %%A IN (!CompilePaths!) DO (
        PUSHD "%%A"

        FOR /R %%B IN ("*.gcc.s") DO (
            ECHO %%B

            "%GccDirectory%\bin\arm-none-eabi-as.exe" %AdditionalAssemblerArguments% -mcpu=%MCpu% -mlittle-endian %FloatCompileArguments% -o "%OutputDirectory%\%%~nB.obj" "%%B"
        )

        FOR /R %%B IN ("*.cpp") DO (
            ECHO %%B

            "%GccDirectory%\bin\arm-none-eabi-g++.exe" -std=c++11 -xc++ %AdditionalCompilerArguments% -mcpu=%MCpu% -mlittle-endian %FloatCompileArguments% %AdditionalDefines% %AdditionalIncludes% -o "%OutputDirectory%\%%~nB.obj" -c "%%B"
        )

        POPD
    )

    "%GccDirectory%\bin\arm-none-eabi-g++.exe" -mcpu=%MCpu% -mlittle-endian -nostartfiles %FloatCompileArguments% -Xlinker %AdditionalCompilerArguments% -L "%GccLibrary%" -Wl,-static,--gc-sections,--no-wchar-size-warning,-Map="%OutputDirectory%\%DeviceName% Firmware.map" -specs="%GccLibrary%\nano.specs" -T"%ScriptRoot%\Devices\%DeviceName%\Scatterfile.gcc.ldf" "%OutputDirectory%\*.obj" "%CoreLibraryFile%" -o "%OutputDirectory%\%DeviceName% Firmware.axf"

    "%GccDirectory%\bin\arm-none-eabi-objcopy.exe" -S -j ER_FLASH -j ER_RAM_RO -j ER_RAM_RW -O binary "%OutputDirectory%\%DeviceName% Firmware.axf" "%OutputDirectory%\%DeviceName% Firmware.bin"
    "%GccDirectory%\bin\arm-none-eabi-objcopy.exe" -S -R ER_DAT -R ER_CONFIG -O ihex "%OutputDirectory%\%DeviceName% Firmware.axf" "%OutputDirectory%\%DeviceName% Firmware.hex"

    IF NOT "%ImageGenParameters%" == ""  "%ScriptRoot%\imagegen.exe" %ImageGenParameters% "%OutputDirectory%\%DeviceName% Firmware.bin"
)

ECHO Done

POPD

ENDLOCAL

Update script

Update script


@echo off

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64

set CL=/nologo /errorReport:none /Gm- /GF /GS- /MT /W4 /wd4324
set LINK=/errorReport:none /INCREMENTAL:NO

set CL=%CL% /Ox
rem set CL=%CL% /Od /Zi
rem set LINK=%LINK% /DEBUG

cl.exe pkg2zip*.c puff.c /Fepkg2zip.exe

@echo off

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64
cd "%~dp0"

set CL=/nologo /errorReport:none /Gm- /GF /GS- /MT /W4 /wd4324
set LINK=/errorReport:none /INCREMENTAL:NO

set CL=%CL% /Ox
rem set CL=%CL% /Od /Zi
rem set LINK=%LINK% /DEBUG

cl.exe pkg2zip*.c puff.c /Fepkg2zip.exe

make sure we are in correct folder after calling VsDevCmd.bat file


Add root build.cmd script to call Build.proj

Created build launch script for the Build.proj file generated by the MSBuildTasks package


@ECHO OFF

SETLOCAL

SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
SET SOLUTION_PATH=%~dp0src\CodeFormatter.sln

IF EXIST %CACHED_NUGET% goto restore
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:restore
IF EXIST "%~dp0src\packages" goto build
%CACHED_NUGET% restore %SOLUTION_PATH%

:build

"%ProgramFiles(x86)%\MSBuild\14.0\bin\MSBuild.exe" %SOLUTION_PATH% /p:OutDir="%~dp0bin " /nologo /m /v:m /flp:verbosity=normal %*

@ECHO OFF

SETLOCAL

SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
SET SOLUTION_PATH=%~dp0src\CodeFormatter.sln
SET VS2015_BUILD_TOOLS_PATH="%ProgramFiles(x86)%\MSBuild\14.0\bin\MSBuild.exe"

IF NOT EXIST %VS2015_BUILD_TOOLS_PATH% (
  echo In order to build or run this tool you need either Visual Studio 2015 Preview or
  echo Microsoft Build Tools 2015 Preview tools installed.
  echo.
  echo Visit http://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs
  echo to download either.
  goto :eof
)

IF EXIST %CACHED_NUGET% goto restore
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:restore
IF EXIST "%~dp0src\packages" goto build
%CACHED_NUGET% restore %SOLUTION_PATH%

:build

"%ProgramFiles(x86)%\MSBuild\14.0\bin\MSBuild.exe" %SOLUTION_PATH% /p:OutDir="%~dp0bin " /nologo /m /v:m /flp:verbosity=normal %*

Add a helpful message when tools are missing

While you can build the unit tests and run them without Visual Studio
2015 (or the build tools) installed, you need to have it installed to
run the program or build.cmd. Generate a helpful error when these
are missing.


@echo off
set argc=0
for %%x in (%*) do set /A argc+=1
if  %argc%== 0 (
  goto documentation
) else (
  goto parseopts
)
:documentation
echo Usage: %~nx0 [options] [.exs file] [data]
echo.
echo   -v                Prints version and exit
echo   -e command        Evaluates the given command (*)
echo   -r file           Requires the given files/patterns (*)
echo   -S script         Finds and executes the given script (*)
echo   -pr file          Requires the given files/patterns in parallel (*)
echo   -pa path          Prepends the given path to Erlang code path (*)
echo   -pz path          Appends the given path to Erlang code path (*)
echo   --app app         Start the given app and its dependencies (*)
echo   --erl switches    Switches to be passed down to erlang (*)
echo   --name name       Makes and assigns a name to the distributed node
echo   --sname name      Makes and assigns a short name to the distributed node
echo   --cookie cookie   Sets a cookie for this distributed node
echo   --hidden          Makes a hidden node
echo   --detached        Starts the Erlang VM detached from console
echo   --no-halt         Does not halt the Erlang VM after execution
echo.
echo ** Options marked with (*) can be given more than once
echo ** Options given after the .exs file or -- are passed down to the executed code
echo ** Options can be passed to the erlang runtime using ELIXIR_ERL_OPTS or --erl
goto :EOF

:parseopts

rem Parameters for Erlang
set parsErlang=

rem Make sure we keep a copy of all parameters
set allPars=%*

rem Get the original path name from the batch file
set originPath=%~dp0

rem Optional parameters before the "-extra" parameter
set beforeExtra=

rem Recursive loop called for each parameter that parses the cmd line parameters
:startloop
set par=%1
shift
if "%par%"=="" (
  rem if no parameters defined
  goto :expand_erl_libs
)
rem ******* ERLANG PARAMETERS **********************
IF NOT "%par%"=="%par:--detached=%" (Set parsErlang=%parsErlang% -detached)
IF NOT "%par%"=="%par:--hidden=%"   (Set parsErlang=%parsErlang% -hidden)
IF NOT "%par%"=="%par:--cookie=%"   (Set parsErlang=%parsErlang% -setcookie %1 && shift)
IF NOT "%par%"=="%par:--sname=%"    (Set parsErlang=%parsErlang% -sname %1 && shift)
IF NOT "%par%"=="%par:--name=%"     (Set parsErlang=%parsErlang% -name %1 && shift)
IF NOT "%par%"=="%par:--erl=%"      (Set beforeExtra=%beforeExtra% %~1 && shift)
rem ******* elixir parameters **********************
rem Note: we don't have to do anything with options that don't take an argument
IF NOT "%par%"=="%par:-e=%"      (shift)
IF NOT "%par%"=="%par:-r=%"      (shift)
IF NOT "%par%"=="%par:-pr=%"     (shift)
IF NOT "%par%"=="%par:-pa=%"     (shift)
IF NOT "%par%"=="%par:-pz=%"     (shift)
IF NOT "%par%"=="%par:--app=%"   (shift)
IF NOT "%par%"=="%par:--remsh=%" (shift)
goto:startloop

rem ******* assume all pre-params are parsed ********************
:expand_erl_libs
rem ******* expand all ebin paths as Windows does not support the ..\*\ebin wildcard ********************
SETLOCAL enabledelayedexpansion
set ext_libs=
for  /d %%d in ("%originPath%..\lib\*.") do (
  set ext_libs=!ext_libs! -pa "%%~fd\ebin"
)
SETLOCAL disabledelayedexpansion
:run
erl %ext_libs% -noshell %ELIXIR_ERL_OPTS% %parsErlang% -s elixir start_cli %beforeExtra% -extra %*

Remove weird chars from bat, closes #1539


if exist classes rmdir classes /s /q
if exist build rmdir build /s /q
mkdir classes
mkdir build
xcopy /E /y src classes\
"%JAVA_HOME%\bin\java" -cp ../../3rdpartypublic/classext/clojure.jar;../MMCoreJ_wrap/MMCoreJ.jar;../../3rdpartypublic/classext/ij.jar;../mmstudio/MMJ_.jar;../../3rdpartypublic/classext/bsh-2.0b4.jar;./src -Dclojure.compile.path=classes clojure.lang.Compile org.micromanager.acq-engine
xcopy /E /y src build\
xcopy classes\org\micromanager\AcquisitionEngine2010.class build\org\micromanager
"%JAVA_HOME%\bin\jar" cf MMAcqEngine.jar -C build\ .
copy /Y MMAcqEngine.jar ..\bin_Win32\
copy /Y MMAcqEngine.jar ..\bin_x64\
copy /Y MMAcqEngine.jar ..\Install_Win32\micro-manager\plugins\Micro-Manager"
copy /Y MMAcqEngine.jar ..\Install_x64\micro-manager\plugins\Micro-Manager"

if exist classes rmdir classes /s /q
if exist build rmdir build /s /q
mkdir classes
mkdir build
xcopy /E /y src classes\
"%JAVA_HOME%\bin\java" -cp ../../3rdpartypublic/classext/clojure.jar;../MMCoreJ_wrap/MMCoreJ.jar;../../3rdpartypublic/classext/ij.jar;../mmstudio/MMJ_.jar;../../3rdpartypublic/classext/bsh-2.0b4.jar;./src -Dclojure.compile.path=classes clojure.lang.Compile org.micromanager.acq-engine
"%JAVA_HOME%\bin\jar" cf MMAcqEngine.jar -C classes\ .
copy /Y MMAcqEngine.jar ..\bin_Win32\
copy /Y MMAcqEngine.jar ..\bin_x64\
copy /Y MMAcqEngine.jar ..\Install_Win32\micro-manager\plugins\Micro-Manager"
copy /Y MMAcqEngine.jar ..\Install_x64\micro-manager\plugins\Micro-Manager"

Bring back AOT compiling for acquisition engine

git-svn-id: 03a8048b5ee8463be5048a3801110fb50f378627@11162 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd


@echo off
cd %~dp0

SETLOCAL
SET NUGET_VERSION=latest
SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe
SET BUILDCMD_KOREBUILD_VERSION=""
SET BUILDCMD_DNX_VERSION=""

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\Sake goto getdnx
IF %BUILDCMD_KOREBUILD_VERSION%=="" (
    .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
) ELSE (
    .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
)
.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages

:getdnx
IF "%SKIP_DNX_INSTALL%"=="" (
    IF "%BUILDCMD_DNX_VERSION%"=="" (
        BUILDCMD_DNX_VERSION=latest
    )
    CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default
    CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default
) ELSE (
    CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
)

packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

@echo off
cd %~dp0

SETLOCAL
SET NUGET_VERSION=latest
SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe
SET BUILDCMD_KOREBUILD_VERSION=
SET BUILDCMD_DNX_VERSION=

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\Sake goto getdnx
IF "%BUILDCMD_KOREBUILD_VERSION%"=="" (
    .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
) ELSE (
    .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
)
.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages

:getdnx
IF "%BUILDCMD_DNX_VERSION%"=="" (
    SET BUILDCMD_DNX_VERSION=latest
)
IF "%SKIP_DNX_INSTALL%"=="" (
    CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default
    CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default
) ELSE (
    CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
)

packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

Correct typo in `build.cmd`

Correct typo in `build.cmd`


set /p versionNumber=

REM clean up
del builds\im-only-resting-%versionNumber%.zip
rd /q /s builds\im-only-resting-%versionNumber%
rd /q /s builds\im-only-resting

REM preparing staging dir
mkdir staging
copy LICENSE staging
copy NOTICE staging
copy Ior\bin\Release\im-only-resting.exe staging
copy Ior\bin\Release\libtidy.dll staging
copy Ior\bin\Release\Newtonsoft.Json.dll staging
copy Ior\bin\Release\PropertyGridEx.dll staging
copy Ior\bin\Release\RestSharp.dll staging
copy Ior\bin\Release\TidyManaged.dll staging
copy Ior\bin\Release\Utils.dll staging
copy Ior\bin\Release\NLog.config staging
copy Ior\bin\Release\NLog.dll staging
copy Ior\bin\Release\System.Net.Http.dll staging
copy Ior\bin\Release\System.Net.Http.WebRequest.dll staging

REM zip staging files
cd staging
"..\tools\7z\7za.exe" a -tzip "..\builds\im-only-resting-%versionNumber%.zip" *
cd ..

REM extract build
"tools\7z\7za.exe" e "builds\im-only-resting-%versionNumber%.zip" -o"builds\im-only-resting-%versionNumber%"
"tools\7z\7za.exe" e "builds\im-only-resting-%versionNumber%.zip" -o"builds\im-only-resting"

REM clean up
rd /q /s staging

pause

set /p versionNumber=

REM clean up
del builds\im-only-resting-%versionNumber%.zip
rd /q /s builds\im-only-resting-%versionNumber%
rd /q /s builds\im-only-resting

REM preparing staging dir
mkdir staging
copy LICENSE staging
copy NOTICE staging
copy Ior\bin\Release\im-only-resting.exe staging
copy Ior\bin\Release\libtidy.dll staging
copy Ior\bin\Release\Newtonsoft.Json.dll staging
copy Ior\bin\Release\PropertyGridEx.dll staging
copy Ior\bin\Release\RestSharp.dll staging
copy Ior\bin\Release\TidyManaged.dll staging
copy Ior\bin\Release\Utils.dll staging
copy Ior\bin\Release\NLog.config staging
copy Ior\bin\Release\NLog.dll staging
copy Ior\bin\Release\System.Net.Http.dll staging
copy Ior\bin\Release\System.Net.Http.WebRequest.dll staging
copy Ior\bin\Release\SciLexer.dll staging
copy Ior\bin\Release\SciLexer64.dll staging
copy Ior\bin\Release\ScintillaNET.dll staging

REM zip staging files
cd staging
"..\tools\7z\7za.exe" a -tzip "..\builds\im-only-resting-%versionNumber%.zip" *
cd ..

REM extract build
"tools\7z\7za.exe" e "builds\im-only-resting-%versionNumber%.zip" -o"builds\im-only-resting-%versionNumber%"
"tools\7z\7za.exe" e "builds\im-only-resting-%versionNumber%.zip" -o"builds\im-only-resting"

REM clean up
rd /q /s staging

pause

update build script to include scintilla dependencies


@echo off
:: set path to erlang installation

SETLOCAL ENABLEDELAYEDEXPANSION

set ERL_R15B03_1=5.9.3.1
set ERL_R15B03=5.9.3
set ERL_R15B02=5.9.2
set ERL_R15B01=5.9.1
set ERL_R15B=5.9
set ERL_R14B04=5.8.5
set ERL_R14B03=5.8.4
set ERL_R14B02=5.8.3
set ERL_R14B01=5.8.2
set ERL_R14B=5.8.1
set ERL_R14A=5.8
set ERL_R13B04=5.7.5
set ERL_R13B03=5.7.4
set ERL_R13B02=5.7.3
set ERL_R13B01=5.7.2
set ERL_ALL=%ERL_R15B03_1% %ERL_R15B03% %ERL_R15B02% %ERL_R15B01% %ERL_R15B% %ERL_R14B04% %ERL_R14B03% %ERL_R14B02% %ERL_R14B01% %ERL_R14B% %ERL_R14A% %ERL_R13B04% %ERL_R13B03% %ERL_R13B02% %ERL_R13B01%
if not defined ERLANG_HOME (
    FOR %%c in (%ERL_ALL%) DO (
        FOR %%p in ("C:\Program Files\erl%%c" "C:\Program Files (x86)\erl%%c") DO (
            set FULL_PATH=%%p
            if exist !FULL_PATH! (
                set ERLANG_HOME=%%p
                goto found
            )
        )
    )
)

:found

echo ERLANG_HOME=%ERLANG_HOME%

ENDLOCAL & set ERLANG_HOME=%ERLANG_HOME%

@echo off
:: set path to erlang installation

SETLOCAL ENABLEDELAYEDEXPANSION

set ERL_R16B=5.10.1
set ERL_R15B03_1=5.9.3.1
set ERL_R15B03=5.9.3
set ERL_R15B02=5.9.2
set ERL_R15B01=5.9.1
set ERL_R15B=5.9
set ERL_R14B04=5.8.5
set ERL_R14B03=5.8.4
set ERL_R14B02=5.8.3
set ERL_R14B01=5.8.2
set ERL_R14B=5.8.1
set ERL_R14A=5.8
set ERL_R13B04=5.7.5
set ERL_R13B03=5.7.4
set ERL_R13B02=5.7.3
set ERL_R13B01=5.7.2
set ERL_ALL=%ERL_R16B% %ERL_R15B03_1% %ERL_R15B03% %ERL_R15B02% %ERL_R15B01% %ERL_R15B% %ERL_R14B04% %ERL_R14B03% %ERL_R14B02% %ERL_R14B01% %ERL_R14B% %ERL_R14A% %ERL_R13B04% %ERL_R13B03% %ERL_R13B02% %ERL_R13B01%
if not defined ERLANG_HOME (
    FOR %%c in (%ERL_ALL%) DO (
        FOR %%p in ("%ProgramFiles%\erl%%c" "%ProgramFiles(x86)%\erl%%c") DO (
            set FULL_PATH=%%p
            if exist !FULL_PATH! (
                set ERLANG_HOME=%%p
                goto found
            )
        )
    )
)

:found

echo ERLANG_HOME=%ERLANG_HOME%

ENDLOCAL & set ERLANG_HOME=%ERLANG_HOME%

windows: add support for R16B in the batch scripts


Create load.bat

Create load.bat


@echo off

rem ==========================================================================
rem Shortcuts for various tasks, emulating UNIX "make" on Windows.
rem It is primarly intended as a shortcut for compiling / installing
rem psutil and running tests (just run "make.bat test").
rem This script is modeled after my Windows installation which uses:
rem - mingw32 for Python 2.4 and 2.5
rem - Visual studio 2008 for Python 2.6, 2.7, 3.2
rem - Visual studio 2010 for Python 3.3+
rem By default C:\Python27\python.exe is used.
rem To use another Python version run:
rem     set PYTHON=C:\Python24\python.exe & make.bat test
rem ==========================================================================

if "%PYTHON%" == "" (
    set PYTHON=C:\Python27\python.exe
)
if "%TSCRIPT%" == "" (
    set TSCRIPT=test\test_psutil.py
)
set PATH=C:\MinGW\bin;%PATH%

if "%1" == "help" (
    :help
    echo Run `make ^<target^>` where ^<target^> is one of:
    echo   build         compile without installing
    echo   build-exes    create exe installers in dist directory
    echo   clean         clean build files
    echo   install       compile and install
    echo   memtest       run memory leak tests
    echo   test          run tests
    echo   test-process  run process related tests
    echo   test-system   run system APIs related tests
    echo   uninstall     uninstall
    echo   upload-exes   upload exe installers on pypi
    goto :eof
)

if "%1" == "clean" (
    :clean
    for /r %%R in (__pycache__) do if exist %%R (rmdir /S /Q %%R)
    for /r %%R in (*.pyc) do if exist %%R (del /s %%R)
    for /r %%R in (*.pyd) do if exist %%R (del /s %%R)
    for /r %%R in (*.orig) do if exist %%R (del /s %%R)
    for /r %%R in (*.bak) do if exist %%R (del /s %%R)
    for /r %%R in (*.rej) do if exist %%R (del /s %%R)
    if exist psutil.egg-info (rmdir /S /Q psutil.egg-info)
    if exist build (rmdir /S /Q build)
    if exist dist (rmdir /S /Q dist)
    goto :eof
)

if "%1" == "build" (
    :build
    if %PYTHON%==C:\Python24\python.exe (
        %PYTHON% setup.py build -c mingw32
    ) else if %PYTHON%==C:\Python25\python.exe (
        %PYTHON% setup.py build -c mingw32
    ) else (
        %PYTHON% setup.py build
    )
    if %errorlevel% neq 0 goto :error
    goto :eof
)

if "%1" == "install" (
    :install
    if %PYTHON%==C:\Python24\python.exe (
        %PYTHON% setup.py build -c mingw32 install
    ) else if %PYTHON%==C:\Python25\python.exe (
        %PYTHON% setup.py build -c mingw32 install
    ) else (
        %PYTHON% setup.py build install
    )
    goto :eof
)

if "%1" == "uninstall" (
    :uninstall
    for %%A in ("%PYTHON%") do (
        set folder=%%~dpA
    )
    for /F "delims=" %%i in ('dir /b %folder%\Lib\site-packages\*psutil*') do (
        rmdir /S /Q %folder%\Lib\site-packages\%%i
    )
    goto :eof
)

if "%1" == "test" (
    :test
    call :install
    %PYTHON% %TSCRIPT%
    goto :eof
)

if "%1" == "test-process" (
    :test
    call :install
    %PYTHON% -m unittest -v test.test_psutil.TestProcess
    goto :eof
)

if "%1" == "test-system" (
    :test
    call :install
    %PYTHON% -m unittest -v test.test_psutil.TestSystem
    goto :eof
)

if "%1" == "memtest" (
    :memtest
    call :install
    %PYTHON% test\test_memory_leaks.py
    goto :eof
)

if "%1" == "build-exes" (
    :build-exes
    call :clean
    C:\Python26\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    C:\Python27\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    C:\Python33\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    goto :eof
)

if "%1" == "upload-exes" (
    :upload-exes
    C:\Python26\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    C:\Python27\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    C:\Python33\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    goto :eof
)

goto :help

:error
    echo last command returned an error; exiting
    exit /b %errorlevel%

@echo off

rem ==========================================================================
rem Shortcuts for various tasks, emulating UNIX "make" on Windows.
rem It is primarly intended as a shortcut for compiling / installing
rem psutil ("make.bat build", "make.bat install") and running tests
rem ("make.bat test").
rem
rem This script is modeled after my Windows installation which uses:
rem - mingw32 for Python 2.4 and 2.5
rem - Visual studio 2008 for Python 2.6, 2.7, 3.2
rem - Visual studio 2010 for Python 3.3+
rem
rem By default C:\Python27\python.exe is used.
rem To compile for a specific Python version run:
rem
rem     set PYTHON=C:\Python24\python.exe & make.bat build
rem
rem If you compile by using mingw on Python 2.4 and 2.5 you need to patch
rem distutils first: http://stackoverflow.com/questions/13592192
rem ==========================================================================

if "%PYTHON%" == "" (
    set PYTHON=C:\Python27\python.exe
)
if "%TSCRIPT%" == "" (
    set TSCRIPT=test\test_psutil.py
)
set PATH=C:\MinGW\bin;%PATH%

if "%1" == "help" (
    :help
    echo Run `make ^<target^>` where ^<target^> is one of:
    echo   build         compile without installing
    echo   build-exes    create exe installers in dist directory
    echo   clean         clean build files
    echo   install       compile and install
    echo   memtest       run memory leak tests
    echo   test          run tests
    echo   test-process  run process related tests
    echo   test-system   run system APIs related tests
    echo   uninstall     uninstall
    echo   upload-exes   upload exe installers on pypi
    goto :eof
)

if "%1" == "clean" (
    :clean
    for /r %%R in (__pycache__) do if exist %%R (rmdir /S /Q %%R)
    for /r %%R in (*.pyc) do if exist %%R (del /s %%R)
    for /r %%R in (*.pyd) do if exist %%R (del /s %%R)
    for /r %%R in (*.orig) do if exist %%R (del /s %%R)
    for /r %%R in (*.bak) do if exist %%R (del /s %%R)
    for /r %%R in (*.rej) do if exist %%R (del /s %%R)
    if exist psutil.egg-info (rmdir /S /Q psutil.egg-info)
    if exist build (rmdir /S /Q build)
    if exist dist (rmdir /S /Q dist)
    goto :eof
)

if "%1" == "build" (
    :build
    if %PYTHON%==C:\Python24\python.exe (
        %PYTHON% setup.py build -c mingw32
    ) else if %PYTHON%==C:\Python25\python.exe (
        %PYTHON% setup.py build -c mingw32
    ) else (
        %PYTHON% setup.py build
    )
    if %errorlevel% neq 0 goto :error
    goto :eof
)

if "%1" == "install" (
    :install
    if %PYTHON%==C:\Python24\python.exe (
        %PYTHON% setup.py build -c mingw32 install
    ) else if %PYTHON%==C:\Python25\python.exe (
        %PYTHON% setup.py build -c mingw32 install
    ) else (
        %PYTHON% setup.py build install
    )
    goto :eof
)

if "%1" == "uninstall" (
    :uninstall
    for %%A in ("%PYTHON%") do (
        set folder=%%~dpA
    )
    for /F "delims=" %%i in ('dir /b %folder%\Lib\site-packages\*psutil*') do (
        rmdir /S /Q %folder%\Lib\site-packages\%%i
    )
    goto :eof
)

if "%1" == "test" (
    :test
    call :install
    %PYTHON% %TSCRIPT%
    goto :eof
)

if "%1" == "test-process" (
    :test
    call :install
    %PYTHON% -m unittest -v test.test_psutil.TestProcess
    goto :eof
)

if "%1" == "test-system" (
    :test
    call :install
    %PYTHON% -m unittest -v test.test_psutil.TestSystem
    goto :eof
)

if "%1" == "memtest" (
    :memtest
    call :install
    %PYTHON% test\test_memory_leaks.py
    goto :eof
)

if "%1" == "build-exes" (
    :build-exes
    call :clean
    C:\Python26\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    C:\Python27\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    C:\Python33\python.exe setup.py build bdist_wininst & if %errorlevel% neq 0 goto :error
    goto :eof
)

if "%1" == "upload-exes" (
    :upload-exes
    C:\Python26\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    C:\Python27\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    C:\Python33\python.exe setup.py bdist_wininst upload  & if %errorlevel% neq 0 goto :error
    goto :eof
)

goto :help

:error
    echo last command returned an error; exiting
    exit /b %errorlevel%

update INSTALL and make.bat instructions