setlocal

set nocache=0

if not exist thirdparty.cached set nocache=1
if not exist %BOOST_ROOT% set nocache=1

if %nocache% == 1 (
	pushd C:\Libraries
	appveyor DownloadFile https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.7z
	7z x boost_1_68_0.7z | find "ing archive"
	cd boost_1_68_0
	call .\bootstrap.bat
	call .\b2.exe --prefix=%BOOST_ROOT% toolset=msvc-14.0 variant=release link=static threading=multi runtime-link=static define=BOOST_USE_WINAPI_VERSION=0x0501 cxxflags="/Zc:threadSafeInit- " --with-date_time --with-filesystem --with-locale --with-regex --with-system --with-thread -q -d0 install
	xcopy /e /i /y /q %BOOST_ROOT%\include\boost-1_68\boost %BOOST_ROOT%\boost
	popd
	if %ERRORLEVEL% NEQ 0 goto ERROR

	call .\build.bat thirdparty
	if %ERRORLEVEL% NEQ 0 goto ERROR

	date /t > thirdparty.cached & time /t >> thirdparty.cached
	echo.
	echo Thirdparty libraries installed.
	echo.
	goto EXIT
) else (
	echo.
	echo Last build date of cache is
	type thirdparty.cached
	echo.
	goto EXIT
)

:ERROR
set EXITCODE=%ERRORLEVEL%

:EXIT
exit /b %EXITCODE%

setlocal

set boost_build_options=toolset=msvc-14.0^
 variant=release^
 link=static^
 threading=multi^
 runtime-link=static^
 define=BOOST_USE_WINAPI_VERSION=0x0501^
 cxxflags="/Zc:threadSafeInit- "^
 --with-date_time^
 --with-filesystem^
 --with-locale^
 --with-regex^
 --with-system^
 --with-thread

set nocache=0

if not exist thirdparty.cached set nocache=1
if not exist %BOOST_ROOT% set nocache=1

if %nocache% == 1 (
	pushd C:\Libraries
	appveyor DownloadFile https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.7z
	7z x boost_1_68_0.7z | find "ing archive"
	cd boost_1_68_0
	call .\bootstrap.bat
	call .\b2.exe --prefix=%BOOST_ROOT% %boost_build_options% -q -d0 install
	xcopy /e /i /y /q %BOOST_ROOT%\include\boost-1_68\boost %BOOST_ROOT%\boost
	popd
	if %ERRORLEVEL% NEQ 0 goto ERROR

	call .\build.bat thirdparty
	if %ERRORLEVEL% NEQ 0 goto ERROR

	date /t > thirdparty.cached & time /t >> thirdparty.cached
	echo.
	echo Thirdparty libraries installed.
	echo.
) else (
	echo.
	echo Last build date of cache is
	type thirdparty.cached
	echo.
)

if defined RIME_PLUGINS (
   for %%s in (%RIME_PLUGINS%) do call :install_plugin %%s
)

goto EXIT

:ERROR
set EXITCODE=%ERRORLEVEL%

:EXIT
exit /b %EXITCODE%

:install_plugin
set slug=%1
echo "plugin: %slug%"
set plugin_project=%slug:*/=%
set plugin_dir=plugins/%plugin_project:librime-=%
git clone --depth 1 "https://github.com/%slug%.git" %plugin_dir%
if exist %plugin_dir%\appveyor.install.bat (
  call %plugin_dir%\appveyor.install.bat
)
exit /b

install RIME_PLUGINS [skip travis]

feat(appveyor): install RIME_PLUGINS  [skip travis]


@echo on

mkdir build-cpp
if errorlevel 1 exit 1

cd build-cpp
cmake .. ^
      -GNinja %
      -DCMAKE_BUILD_TYPE=Release %
      -DCMAKE_CXX_FLAGS="$CXXFLAGS" %
      -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% %
      -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% %
      -DBUILD_TESTING=OFF %
      -DWITH_API_ONLY=OFF %
      -DWITH_ETW=OFF %
      -DWITH_EXAMPLES=OFF %
      -DWITH_OTLP=ON %
      -DWITH_OTLP_GRPC=ON

cmake --build . --config Release --target install
if errorlevel 1 exit 1

@echo on

mkdir build-cpp
if errorlevel 1 exit 1

cd build-cpp
cmake .. ^
      -GNinja %
      -DCMAKE_BUILD_TYPE=Release %
      -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% %
      -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% %
      -DBUILD_TESTING=OFF %
      -DWITH_API_ONLY=OFF %
      -DWITH_ETW=OFF %
      -DWITH_EXAMPLES=OFF %
      -DWITH_OTLP=ON %
      -DWITH_OTLP_GRPC=ON

cmake --build . --config Release --target install
if errorlevel 1 exit 1

Fix bld.bat

Fix bld.bat


@echo on

cargo clean
cargo test
cargo build --release

mkdir chocolatey
cp heatseeker.nuspec chocolatey\

mkdir chocolatey\tools
cp LICENSE chocolatey\tools\
cp README.md chocolatey\tools\README

mkdir chocolatey\tools\bin
cp target\release\hs.exe chocolatey\tools\bin

cpack chocolatey\heatseeker.nuspec

@echo on

cargo clean || exit /b 1
cargo test || exit /b 1
cargo build --release || exit /b 1

mkdir chocolatey || exit /b 1
copy heatseeker.nuspec chocolatey\ || exit /b 1

mkdir chocolatey\tools || exit /b 1
copy LICENSE chocolatey\tools\ || exit /b 1
copy README.md chocolatey\tools\README || exit /b 1

mkdir chocolatey\tools\bin || exit /b 1
copy target\release\hs.exe chocolatey\tools\bin || exit /b 1

cpack chocolatey\heatseeker.nuspec || exit /b 1

Tweak create-nupkg.bat

Tweak create-nupkg.bat


echo off
IF EXIST dist del /Q dist\*.*

if "%1"=="" goto default_value:
set pythonexe="%1"
goto custom_python:

:default_value:
IF NOT EXIST c:\Python34 GOTO checkinstall64:

:checkinstall:
IF EXIST c:\Python34vir GOTO nexta:
mkdir c:\Python34vir

:nexta:
IF EXIST c:\Python34vir\install GOTO fullsetupa:
c:\Python34\Scripts\virtualenv c:\Python34vir\install --system-site-packages
if %errorlevel% neq 0 exit /b %errorlevel%

:fullsetupa:
echo #######################################################
c:\Python34vir\install\Scripts\python -u setup.py install
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:checkinstall64:
IF EXIST c:\Python34_64vir GOTO nextb:
mkdir c:\Python34_64vir

:nextb:
IF EXIST c:\Python34_64vir\install GOTO fullsetupb:
c:\Python34_x64\Scripts\virtualenv c:\Python34_64vir\install --system-site-packages
if %errorlevel% neq 0 exit /b %errorlevel%

:fullsetupb:
echo #######################################################
c:\Python34_64vir\install\Scripts\python -u setup.py install
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup33:
IF NOT EXIST c:\Python33 GOTO setup33_64:
set pythonexe="c:\Python33\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py bdist_wininst
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup33_64:
IF NOT EXIST c:\Python33_x64 GOTO setup34:
set pythonexe="c:\Python33_x64\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py sdist --formats=gztar,zip --verbose
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py build bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup34:
IF NOT EXIST c:\Python34 GOTO setup34_x64_msi_wheel:
set pythonexe="c:\Python34\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py build bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:utpy34_64:
set pythonexe="c:\Python34_x64\python"
%pythonexe% -u setup.py clean_space
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u setup.py unittests
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup34_x64_msi_wheel:
set pythonexe="c:\Python34_x64\python"
:custom_python:
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py sdist --formats=gztar,zip --verbose
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_msi
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_wheel
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:documentation:
%pythonexe% -u setup.py build_sphinx
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:copyfiles:
if not exist dist\html mkdir dist\html
xcopy /E /C /I /Y _doc\sphinxdoc\build\html dist\html
if %errorlevel% neq 0 exit /b %errorlevel%

echo off
IF EXIST dist del /Q dist\*.*

if "%1"=="" goto default_value:
set pythonexe="%1"
goto custom_python:

:default_value:
IF NOT EXIST c:\Python34 GOTO checkinstall64:

:checkinstall:
IF EXIST c:\Python34vir GOTO nexta:
mkdir c:\Python34vir

:nexta:
IF EXIST c:\Python34vir\install GOTO fullsetupa:
c:\Python34\Scripts\virtualenv c:\Python34vir\install --system-site-packages
if %errorlevel% neq 0 exit /b %errorlevel%

:fullsetupa:
echo #######################################################
c:\Python34vir\install\Scripts\python -u setup.py install
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:checkinstall64:
IF EXIST c:\Python34_64vir GOTO nextb:
mkdir c:\Python34_64vir

:nextb:
IF EXIST c:\Python34_64vir\install GOTO fullsetupb:
c:\Python34_x64\Scripts\virtualenv c:\Python34_64vir\install --system-site-packages
if %errorlevel% neq 0 exit /b %errorlevel%

:fullsetupb:
echo #######################################################
c:\Python34_64vir\install\Scripts\python -u setup.py install
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup33:
IF NOT EXIST c:\Python33 GOTO setup33_64:
set pythonexe="c:\Python33\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py bdist_wininst
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup33_64:
IF NOT EXIST c:\Python33_x64 GOTO setup34:
set pythonexe="c:\Python33_x64\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py sdist --formats=gztar,zip --verbose
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py build bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup34:
IF NOT EXIST c:\Python34 GOTO utpy34_64:
set pythonexe="c:\Python34\python"
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py build bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:utpy34_64:
set pythonexe="c:\Python34_x64\python"
%pythonexe% -u setup.py clean_space
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u setup.py unittests
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:setup34_x64_msi_wheel:
set pythonexe="c:\Python34_x64\python"
:custom_python:
%pythonexe% setup.py clean_pyd
%pythonexe% setup.py sdist --formats=gztar,zip --verbose
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_wininst --plat-name=win-amd64
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_msi
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% setup.py bdist_wheel
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:documentation:
%pythonexe% -u setup.py build_sphinx
if %errorlevel% neq 0 exit /b %errorlevel%
echo #######################################################

:copyfiles:
if not exist dist\html mkdir dist\html
xcopy /E /C /I /Y _doc\sphinxdoc\build\html dist\html
if %errorlevel% neq 0 exit /b %errorlevel%

fix setup batch

fix setup batch


set DEST=install
set SRC=deps\install
xcopy %SRC%\bin\osg*-osg.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgDB.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgGA.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgText.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgUtil.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgViewer.dll %DEST% /Y
xcopy %SRC%\bin\*-OpenThreads.dll %DEST% /Y

xcopy %SRC%\bin\osgPlugins* %DEST% /Y /S

xcopy %SRC%\osvr-ver.txt %SRC%\bin\osvrClientKit.dll %SRC%\bin\osvrClient.dll %SRC%\bin\osvrTransform.dll %SRC%\bin\osvrUtil.dll %DEST% /Y

xcopy redist\*.* %DEST% /Y

set /p VER=<%SRC%\osvr-ver.txt
move install OSVR-Tracker-View-built-with-%VER%
7za a OSVR-Tracker-View-built-with-%VER%.7z OSVR-Tracker-View-built-with-%VER%\*

set DEST=install
set SRC=deps\install
xcopy %SRC%\bin\osg*-osg.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgDB.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgGA.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgText.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgUtil.dll %DEST% /Y
xcopy %SRC%\bin\osg*-osgViewer.dll %DEST% /Y
xcopy %SRC%\bin\*-OpenThreads.dll %DEST% /Y

xcopy %SRC%\bin\osgPlugins*.* %DEST% /Y /S
for %%F in (%SRC%\osvr-ver.txt,%SRC%\bin\osvrClientKit.dll,%SRC%\bin\osvrClient.dll,%SRC%\bin\osvrTransform.dll,%SRC%\bin\osvrUtil.dll) do ( xcopy %%F %DEST% /Y )

xcopy redist\*.* %DEST% /Y

set /p VER=<%SRC%\osvr-ver.txt
set OUTPUT=OSVR-Tracker-View-built-with-%VER%-viewer-%BUILD_NUMBER%
move install %OUTPUT%
7za a %OUTPUT%.7z %OUTPUT%\*

Update postbuild script to try to include all the things that we need.


@echo off
rem ----------------------------------------------------------------------------
rem
rem This variable should be set to the directory where is installed ProActive
rem

IF NOT DEFINED PA_SCHEDULER set PA_SCHEDULER=%CD%\..\..

rem ----------------------------------------------------------------------------

if NOT DEFINED JAVA_HOME goto javahome
if "%JAVA_HOME%" == "" goto javahome

rem ----
rem Set up the classpath using classes dir or jar files
rem

IF DEFINED CLASSPATHEXT (
	SET CLASSPATH=%CLASSPATHEXT%
) ELSE (
	SET CLASSPATH=.
)

rem Check if classes exists and is not empty
IF EXIST "%PA_SCHEDULER%\classes\scheduler" (
	SET CLASSPATH=%CLASSPATH%;%PA_SCHEDULER%\classes\resource-manager;%PA_SCHEDULER%\classes\scheduler
	SET JARS=%PA_SCHEDULER%\lib\
	FOR %%j IN ("%PA_SCHEDULER%\lib\*.jar") DO SET JARS=!JARS!;%%j
rem Use jar index to avoid 'command too long'
	SET JARS=!JARS!;%PA_SCHEDULER%\lib\ProActive\ProActive.jar
	FOR %%j IN ("%PA_SCHEDULER%\lib\common\*.jar") DO SET JARS=!JARS!;%%j
) ELSE (
	FOR %%j IN ("%PA_SCHEDULER%\dist\lib\*.jar") DO SET JARS=!JARS!;%%j
	SET CLASSPATH=%CLASSPATH%;%PA_SCHEDULER%\dist\lib\.jar
)

SET CLASSPATH=%CLASSPATH%;%JARS%

set JAVA_CMD="%JAVA_HOME%\bin\java.exe" -Dproactive.home="%PA_SCHEDULER%" -Dpa.scheduler.home="%PA_SCHEDULER%" -Dpa.rm.home="%PA_SCHEDULER%" -Djava.security.manager -Djava.security.policy="%PA_SCHEDULER%\config\scheduler.java.policy" -Dlog4j.configuration="%PA_SCHEDULER%/config/scheduler-log4j"

rem Adding java tools to the path
SET OK=1
FOR /F "delims=;" %%i IN ("%PATH%") DO (
IF /I "%%i" == "%JAVA_HOME%\bin" SET OK=0
)
IF /I %OK%==1 SET PATH=%JAVA_HOME%\bin;%PATH%

goto end

:javahome
echo.
echo The environment variable JAVA_HOME must be set the current jdk distribution
echo installed on your computer.
echo Use
echo    set JAVA_HOME=<the directory where is the JDK>
goto end

:end

@echo off
rem ----------------------------------------------------------------------------
rem
rem This variable should be set to the directory where is installed ProActive
rem

IF NOT DEFINED PA_SCHEDULER set PA_SCHEDULER=%CD%\..\..

rem ----------------------------------------------------------------------------

if NOT DEFINED JAVA_HOME goto javahome
if "%JAVA_HOME%" == "" goto javahome

rem ----
rem Set up the classpath using classes dir or jar files
rem

IF DEFINED CLASSPATHEXT (
	SET CLASSPATH=%CLASSPATHEXT%
) ELSE (
	SET CLASSPATH=.
)

rem Jars needed by the scheduler not included in the ProActive.jar jarindex
set ADD_JARS="client.jar derby.jar derbytools.jar isorelax.jar js.jar msv.jar ProActive_resource-manager.jar ProActive_scheduler.jar ProActive_tests.jar relaxngDatatype.jar rngpack-1.1a.jar script-api.jar script-js.jar xsdlib.jar"

rem Check if classes exists and is not empty
IF EXIST "%PA_SCHEDULER%\classes\scheduler" (
	SET CLASSPATH=%CLASSPATH%;%PA_SCHEDULER%\classes\resource-manager;%PA_SCHEDULER%\classes\scheduler
	SET JARS=%PA_SCHEDULER%\lib\
	FOR %%j IN ("%PA_SCHEDULER%\lib\*.jar") DO SET JARS=!JARS!;%%j
rem Use jar index to avoid 'command too long'
	SET JARS=!JARS!;%PA_SCHEDULER%\lib\ProActive\ProActive.jar
	FOR %%j IN ("%PA_SCHEDULER%\lib\common\*.jar") DO SET JARS=!JARS!;%%j
) ELSE (
	SET JARS=!JARS!;%PA_SCHEDULER%\dist\lib\ProActive.jar
	FOR %%j IN %ADD_JARS% DO SET JARS=!JARS!;%PA_SCHEDULER%\dist\lib\%%j
)

SET CLASSPATH=%CLASSPATH%;%JARS%

set JAVA_CMD="%JAVA_HOME%\bin\java.exe" -Dproactive.home="%PA_SCHEDULER%" -Dpa.scheduler.home="%PA_SCHEDULER%" -Dpa.rm.home="%PA_SCHEDULER%" -Djava.security.manager -Djava.security.policy="%PA_SCHEDULER%\config\scheduler.java.policy" -Dlog4j.configuration="%PA_SCHEDULER%/config/scheduler-log4j"

rem Adding java tools to the path
SET OK=1
FOR /F "delims=;" %%i IN ("%PATH%") DO (
IF /I "%%i" == "%JAVA_HOME%\bin" SET OK=0
)
IF /I %OK%==1 SET PATH=%JAVA_HOME%\bin;%PATH%

goto end

:javahome
echo.
echo The environment variable JAVA_HOME must be set the current jdk distribution
echo installed on your computer.
echo Use
echo    set JAVA_HOME=<the directory where is the JDK>
goto end

:end

Reduce command line size for windows init.bat.

git-svn-id: 27916816d6cfa57849e9a885196bf7392b80e1ac@10093 28e8926c-6b08-0410-baaa-805c5e19b8d6


@ECHO OFF

REM Bail-out: MSBuild & Visual Studio
REM - Perf impact & our settings may cause unexpected behaviour
IF DEFINED MSBuildExtensionsPath EXIT /B
IF DEFINED VisualStudioVersion EXIT /B

REM Bail-out: MinGW & MSYS
REM - In some scenarios our script doesn't execute correctly
IF DEFINED MSYSTEM EXIT /B

REM Bail-out: Cygwin Setup
REM - Environment changes on autorebase causes DOSKEY to crash
IF DEFINED CYGWINROOT EXIT /B

REM So that we can safely run via AutoRun without infinite recursion
REM Key Path: HKEY_CURRENT_USER\Software\Microsoft\Command Processor
REM Use something like: IF NOT DEFINED SetupEnv Path\To\SetupEnv.Cmd
SET SetupEnv=Yes

REM Paths to applications we reference later for additional setup
IF DEFINED ProgramFiles(x86) (
    SET AnsiConPath="%ProgramFiles(x86)%\ANSICON\ansicon.exe"
) ELSE (
    SET AnsiConPath="%ProgramFiles%\ANSICON\ansicon.exe"
)

REM Output a message that our configuration is being applied
REM
REM Unfortunately, some apps spawn a cmd instance and then parse the output as
REM a string. The less durable ones will choke if there's any unexpected output
REM (e.g. MySQL Workbench's version check of mysqldump).
REM ECHO.
REM ECHO Making Command Prompt suck slightly less ...

REM Uncomment to enable verbose mode (but note the above)
REM SET SetupEnvVerbose=Yes
IF DEFINED SetupEnvVerbose ECHO.
IF DEFINED SetupEnvVerbose ECHO Configuring Command Processor:

REM Switch to user profile directory if the current path is the Windows
REM System32 directory. This probably means we were launched elevated.
IF /I "%CD%" == "%SystemRoot%\System32" (
    CD /D "%USERPROFILE%"
)

REM Inject Clink for a more pleasant experience
IF EXIST "%CLINK_DIR%" (
    IF DEFINED SetupEnvVerbose ECHO * [Clink] Injecting ...
    IF /I "%PROCESSOR_ARCHITECTURE%" == "x86" (
        "%CLINK_DIR%\clink_x86.exe" inject -q --profile "~\clink"
    ) ELSE IF /I "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
        IF DEFINED PROCESSOR_ARCHITEW6432 (
            "%CLINK_DIR%\clink_x86.exe" inject -q --profile "~\clink"
        ) ELSE (
            "%CLINK_DIR%\clink_x64.exe" inject -q --profile "~\clink"
        )
    ) ELSE (
        IF DEFINED SetupEnvVerbose ECHO * [Clink] Unsupported processor architecture.
    )
) ELSE (
    IF DEFINED SetupEnvVerbose ECHO * [Clink] Unable to find at path specified by CLINK_DIR.
)

REM Inject ANSICON if we're not running under ConEmu
IF NOT DEFINED ConEmuANSI (
    IF EXIST %AnsiConPath% (
        IF DEFINED SetupEnvVerbose ECHO * [ANSICON] Injecting ...
        IF !ANSICON_VER! == ^!ANSICON_VER^! %AnsiConPath% -p
    ) ELSE (
        IF DEFINED SetupEnvVerbose ECHO * [ANSICON] Unable to find at path specified by AnsiConPath.
    )
)
SET AnsiConPath=

REM Configure a more informative prompt if we're running under ConEmu
IF DEFINED ConEmuDir (
    IF DEFINED SetupEnvVerbose ECHO * [Prompt] Configuring ...
    IF "%ConEmuIsAdmin%" == "ADMIN" (
        PROMPT $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[91m$P$E[90m$G$E[m$S$E]9;12$E\
    ) ELSE (
        PROMPT $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[92m$P$E[90m$G$E[m$S$E]9;12$E\
    )
)

REM Because I'm tired of forgetting this is not a *nix shell
IF DEFINED SetupEnvVerbose ECHO * [DOSKEY] Setting macros ...
DOSKEY clear=cls $*
DOSKEY ls=dir $*
DOSKEY man=help $*
DOSKEY which=where $*

REM Final clean-up
SET SetupEnvVerbose=

@ECHO OFF

REM Bail-out: MSBuild & Visual Studio
REM Performance impact & may cause unexpected behaviour
IF DEFINED MSBuildExtensionsPath EXIT /B
IF DEFINED VisualStudioVersion EXIT /B

REM Bail-out: MinGW & MSYS
REM In some scenarios our script doesn't execute correctly
IF DEFINED MSYSTEM EXIT /B

REM Bail-out: Cygwin Setup
REM Environment changes on autorebase cause DOSKEY to crash
IF DEFINED CYGWINROOT EXIT /B

REM ###########################################################################
REM ###                         Initialisation                              ###
REM ###########################################################################

REM So that we can safely run via AutoRun without infinite recursion
REM Key Path: HKEY_CURRENT_USER\Software\Microsoft\Command Processor
REM Use something like: IF NOT DEFINED SetupEnv Path\To\SetupEnv.cmd
SET SetupEnv=Yes

REM Uncomment to enable verbose mode
REM
REM This should only be used for debugging as it can interfere with programs
REM which spawn a CMD instance and parse the output.
REM SET SetupEnvVerbose=Yes
IF DEFINED SetupEnvVerbose ECHO.
IF DEFINED SetupEnvVerbose ECHO Configuring Command Processor:

REM Switch to the user's profile directory if the current path is the Windows
REM System32 directory. This probably means we launched as an elevated process.
IF /I "%CD%" == "%SystemRoot%\System32" (
    CD /D "%USERPROFILE%"
)

REM ###########################################################################
REM ###                              Clink                                  ###
REM ###########################################################################

WHERE /Q "clink.cmd"
IF ERRORLEVEL 0 (
    REM Found in %PATH% (likely installed via Scoop or similar)
    SET ClinkPath="clink.cmd"
    GOTO ClinkRun
)
IF EXIST "%CLINK_DIR%" (
    REM Found via %CLINK_DIR% (set via Clink's own installer)
    SET ClinkPath="%CLINK_DIR%\clink.bat"
    GOTO ClinkRun
)
GOTO ClinkSkip

:ClinkRun
IF DEFINED SetupEnvVerbose ECHO * [Clink] Injecting ...
CALL "%ClinkPath%" inject --autorun --profile ~\clink
SET ClinkPath=
GOTO ClinkEnd

:ClinkSkip
IF DEFINED SetupEnvVerbose ECHO * [Clink] Not found.

:ClinkEnd

REM ###########################################################################
REM ###                             ANSICON                                 ###
REM ###########################################################################

REM ConEmu provides its own ANSI support
IF DEFINED ConEmuANSI GOTO AnsiConEnd

WHERE /Q "ansicon.exe"
IF ERRORLEVEL 1 (
    GOTO AnsiConSkip
)

IF DEFINED SetupEnvVerbose ECHO * [ANSICON] Injecting ...
IF !ANSICON_VER! == ^!ANSICON_VER^! "ansicon.exe" -p
GOTO AnsiConEnd

:AnsiConSkip
IF DEFINED SetupEnvVerbose ECHO * [ANSICON] Not found.

:AnsiConEnd

REM ###########################################################################
REM ###                             ConEmu                                  ###
REM ###########################################################################

REM Check we're running under ConEmu
IF NOT DEFINED ConEmuDir GOTO ConEmuEnd

REM Setup a more informative prompt
IF DEFINED SetupEnvVerbose ECHO * [ConEmu] Configuring prompt ...
IF "%ConEmuIsAdmin%" == "ADMIN" (
    PROMPT $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[91m$P$E[90m$G$E[m$S$E]9;12$E\
) ELSE (
    PROMPT $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[92m$P$E[90m$G$E[m$S$E]9;12$E\
)

:ConEmuEnd

REM ###########################################################################
REM ###                             DOSKEY                                  ###
REM ###########################################################################

WHERE /Q "doskey.exe"
IF ERRORLEVEL 1 (
    GOTO DosKeySkip
)

REM Because I'm tired of forgetting this is not a *nix shell
IF DEFINED SetupEnvVerbose ECHO * [DOSKEY] Configuring ...
DOSKEY clear=cls $*
DOSKEY ls=dir $*
DOSKEY man=help $*
DOSKEY which=where $*
GOTO DosKeyEnd

:DosKeySkip
IF DEFINED SetupEnvVerbose ECHO * [DOSKEY] Not found.

:DosKeyEnd

REM ###########################################################################
REM ###                               End                                   ###
REM ###########################################################################

REM Remove script variables
SET SetupEnvVerbose=

Rework SetupEnv.cmd for new Clink support & other tweaks


::  This file is included by the quickstart script file "..\..\bw.bat" so that
::  we may keep this script under version control in the svn repository.

@ECHO off
SETLOCAL

ECHO.
ECHO.
ECHO   Bedework Calendar System
ECHO   ------------------------
ECHO.

SET PRG=%0
SET saveddir=%CD%
SET QUICKSTART_HOME=%saveddir%

SET ANT_HOME=%QUICKSTART_HOME%\apache-ant-1.7.0

SET CLASSPATH="%ANT_HOME%\lib\ant-launcher.jar"
SET CLASSPATH=%CLASSPATH%;"%QUICKSTART_HOME%\bedework\build\quickstart\antlib"
:: SET CLASSPATH=%CLASSPATH%;"%QUICKSTART_HOME%\bedework\applib\log4j-1.2.8.jar"

:: Default some parameters
SET BWCONFIGS=
SET bwc=default
SET BWCONFIG=
SET offline=
SET quickstart=

:: Projects we will build
SET pkgdefault=yes
SET bedework=
SET carddav=
SET caldav=
SET client=
SET monitor=
SET naming=
SET tzsvr=
SET webdav=

SET action=

:: check for command-line arguments and branch on them
IF "%1noargs" == "noargs" GOTO usage
GOTO branch

:quickstart
  ECHO     Preparing quickstart build ...
  SET quickstart="yes"
  SHIFT
  GOTO branch

:bwchome
  :: Define location of configs
  SHIFT
  SET BWCONFIGS=%1
  SHIFT
  GOTO branch

:bwc
  SHIFT
  SET bwc=%1
  SHIFT
  GOTO branch

:offline
  ECHO     Setting to offline mode; libraries will not be downloaded ...
  SET offline="-Dorg.bedework.offline.build=yes"
  SHIFT
  GOTO branch

:: PROJECTS

:carddav
  SET carddav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:caldav
  SET caldav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:client
  SET client="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:webdav
  SET webdav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:monitor
  SET monitor="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:naming
  SET naming="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:tzsvr
  SET tzsvr="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:reindex
  ECHO     Calling the reindexer
  SET INDEXER=%QUICKSTART_HOME%\bedework\dist\temp\shellscr\indexer

  if exist %INDEXER% goto indexerok
    ECHO The indexer directory %INDEXER% does not exist. You probably need to do a rebuild.
    GOTO:EOF

  :indexerok
  cd %INDEXER%
  bwrun.bat reindex-nostart -user admin -indexlocprefix ..\..\..\..\..\

  GOTO:EOF

:zoneinfo
   ECHO    zoneinfo target is not supported on Windows
   GOTO:EOF

:jbossNotice
  ECHO *************************************************************
  ECHO The jboss configuration has been removed from the quickstart.
  ECHO It is now the default.  Remove the '-bwc jboss' option.
  ECHO *************************************************************
  GOTO:EOF

:doneWithArgs

IF "%bwc%" == "jboss" GOTO jbossNotice

IF NOT "%quickstart%empty" == "empty" GOTO checkBwConfig
IF NOT "%BWCONFIGS%empty" == "empty" GOTO DoneQB
SET BWCONFIGS=%HOMEPATH%\bwbuild
GOTO doneQB

:checkBwConfig

  SET BWCONFIGS=%QUICKSTART_HOME%\bedework\config\bwbuild

:doneQB
  SET BEDEWORK_CONFIGS_HOME=%BWCONFIGS%
  SET BEDEWORK_CONFIG=%BWCONFIGS%\%bwc%

  IF EXIST "%BEDEWORK_CONFIGS_HOME%\.platform" GOTO foundDotPlatform
  ECHO *******************************************************
  ECHO Error: Configurations directory %BEDEWORK_CONFIGS_HOME%
  ECHO is missing directory '.platform'.
  ECHO *******************************************************
  GOTO:EOF
:foundDotPlatform

  IF EXIST "%BEDEWORK_CONFIG%\build.properties" GOTO foundBuildProperties
  ECHO *******************************************************
  ECHO Error: Configuration %BEDEWORK_CONFIG%
  ECHO does not exist or is not a Bedework configuration.
  ECHO *******************************************************
  GOTO:EOF
:foundBuildProperties

  IF NOT "%JAVA_HOME%empty"=="empty" GOTO javaOk
  ECHO *******************************************************
  ECHO Error: JAVA_HOME is not defined correctly for Bedework.
  ECHO *******************************************************
  GOTO:EOF
:javaOk

:runBedework
  :: Make available for ant
  SET BWCONFIG=-Dorg.bedework.user.build.properties=%BEDEWORK_CONFIG%\build.properties

  ECHO.
  ECHO     BWCONFIGS = %BWCONFIGS%
  ECHO     BWCONFIG = %BWCONFIG%
  ECHO.

  IF NOT "%caldav%empty" == "empty"  cd %QUICKSTART_HOME%\bedework\projects\caldav
  IF NOT "%carddav%empty" == "empty" cd %QUICKSTART_HOME%\bedework-carddav
  IF NOT "%client%empty" == "empty"  cd %QUICKSTART_HOME%\bwclient
  IF NOT "%monitor%empty" == "empty" cd %QUICKSTART_HOME%\MonitorApp
  IF NOT "%naming%empty" == "empty"  cd %QUICKSTART_HOME%\bwnaming
  IF NOT "%tzsvr%empty" == "empty"   cd %QUICKSTART_HOME%\bwtzsvr
  IF NOT "%webdav%empty" == "empty"  cd %QUICKSTART_HOME%\bedework\projects\webdav

  "%JAVA_HOME%\bin\java.exe" -classpath %CLASSPATH% %offline% -Dant.home="%ANT_HOME%" org.apache.tools.ant.launch.Launcher "%BWCONFIG%" %1

  GOTO:EOF

:: Iterate over the command line arguments;
:: DOS Batch labels can't contain hyphens, so convert them
:: (otherwise, we could just "GOTO %1")
:branch
IF "%1" == "-quickstart" GOTO quickstart
IF "%1" == "-bwchome" GOTO bwchome
IF "%1" == "-bwc" GOTO bwc
IF "%1" == "-offline" GOTO offline
IF "%1" == "-reindex" GOTO reindex
IF "%1" == "-zoneinfo" GOTO zoneinfo
IF "%1" == "-carddav" GOTO carddav
IF "%1" == "-caldav" GOTO caldav
IF "%1" == "-client" GOTO client
IF "%1" == "-webdav" GOTO webdav
IF "%1" == "-monitor" GOTO monitor
IF "%1" == "-naming" GOTO naming
IF "%1" == "-tzsvr" GOTO tzsvr
GOTO doneWithArgs

:usage
  ECHO    Usage:
  ECHO.
  ECHO    bw [CONFIG-SOURCE] [CONFIG] [PROJECT] [ -offline ] [ target ]
  ECHO    bw ACTION
  ECHO.
  ECHO    Where:
  ECHO.
  ECHO    CONFIG-SOURCE optionally defines the location of configurations and is one or none of
  ECHO     -quickstart      to use the configurations within the quickstart
  ECHO                      e.g. "bw -quickstart start"
  ECHO     -bwchome path    to specify the location of the bwbuild directory
  ECHO.
  ECHO     The default is to look in the user home for the "bwbuild" directory.
  ECHO.
  ECHO    CONFIG optionally defines the configuration to build
  ECHO      -bwc configname      e.g. "-bwc mysql"
  ECHO.
  ECHO    -offline     Build without attempting to retrieve library jars
  ECHO    target       Ant target to execute (e.g. "start")
  ECHO.
  ECHO.
  ECHO.
  ECHO    PROJECT optionally defines the package to build and is none or more of
  ECHO     -carddav     Target is for the CardDAV build
  ECHO     -monitor     Target is for the bedework monitor application
  ECHO     -naming      Target is for the abstract naming api
  ECHO     The default is a calendar build
  ECHO.
  ECHO    Invokes ant to build or deploy the Bedework system. Uses a configuration
  ECHO    directory which contains one directory per configuration.
  ECHO.
  ECHO    Within each configuration directory we expect a file called
  ECHO    build.properties which should point to the property and options file
  ECHO    needed for the deploy process.
  ECHO.
  ECHO    In general these files will be in the same directory as build.properties.
  ECHO    The environment variable BEDEWORK_CONFIG contains the path to the current
  ECHO    configuration directory and can be used to build a path to the other files.
  ECHO.
  ECHO   ACTION defines an action to take usually in the context of the quickstart.
  ECHO    In a deployed system many of these actions are handled directly by a
  ECHO    deployed application. ACTION may be one of
  ECHO      -reindex - runs the indexer directly out of the quickstart bedework
  ECHO                 dist directory to rebuild the lucene indexes
REM   Don't support zoneinfo command on Windows for now
REM   ECHO      -zoneinfo - builds zoneinfo data for the timezones server
REM   ECHO                  requires -version and -tzdata parameters
  ECHO.
  ECHO.
  ECHO.

::  This file is included by the quickstart script file "..\..\bw.bat" so that
::  we may keep this script under version control in the svn repository.

@ECHO off
SETLOCAL

ECHO.
ECHO.
ECHO   Bedework Calendar System
ECHO   ------------------------
ECHO.

SET PRG=%0
SET saveddir=%CD%
SET QUICKSTART_HOME=%saveddir%

SET ANT_HOME=%QUICKSTART_HOME%\apache-ant-1.7.0

SET CLASSPATH="%ANT_HOME%\lib\ant-launcher.jar"
SET CLASSPATH=%CLASSPATH%;"%QUICKSTART_HOME%\bedework\build\quickstart\antlib"
:: SET CLASSPATH=%CLASSPATH%;"%QUICKSTART_HOME%\bedework\applib\log4j-1.2.8.jar"

:: Default some parameters
SET BWCONFIGS=
SET bwc=default
SET BWCONFIG=
SET offline=
SET quickstart=

SET ant_listener=
SET ant_xmllogfile=
SET ant_logger=

SET ant_loglevel="-quiet"
SET bw_loglevel=""

:: Projects we will build
SET pkgdefault=yes
SET bedework=
SET carddav=
SET caldav=
SET client=
SET monitor=
SET naming=
SET tzsvr=
SET webdav=

SET action=

:: check for command-line arguments and branch on them
IF "%1noargs" == "noargs" GOTO usage
GOTO branch

:quickstart
  ECHO     Preparing quickstart build ...
  SET quickstart="yes"
  SHIFT
  GOTO branch

:bwchome
  :: Define location of configs
  SHIFT
  SET BWCONFIGS=%1
  SHIFT
  GOTO branch

:bwc
  SHIFT
  SET bwc=%1
  SHIFT
  GOTO branch

:offline
  ECHO     Setting to offline mode; libraries will not be downloaded ...
  SET offline="-Dorg.bedework.offline.build=yes"
  SHIFT
  GOTO branch

:: ----------------------- Log level

:log-silent
  SET ant_loglevel="-quiet"
  SET bw_loglevel="-Dorg.bedework.build.silent=true"
  SHIFT
  GOTO branch

:log-quiet
  SET ant_loglevel="-quiet"
  SET bw_loglevel=""
  SHIFT
  GOTO branch

:log-inform
  SET ant_loglevel=""
  SET bw_loglevel="-Dorg.bedework.build.inform=true"
  SHIFT
  GOTO branch

:log-verbose
  SET ant_loglevel="-verbose"
  SET bw_loglevel="-Dorg.bedework.build.inform=true -Dorg.bedework.build.noisy=true"
  SHIFT
  GOTO branch

:ant-debug
  SET ant_loglevel="-debug"
  SHIFT
  GOTO branch

:build-debug
  SET bw_loglevel="-Dorg.bedework.build.inform=true -Dorg.bedework.build.noisy=true -Dorg.bedework.build.debug=true "
  SHIFT
  GOTO branch

:: PROJECTS

:carddav
  SET carddav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:caldav
  SET caldav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:client
  SET client="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:webdav
  SET webdav="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:monitor
  SET monitor="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:naming
  SET naming="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:tzsvr
  SET tzsvr="yes"
  SET pkgdefault=
  SHIFT
  GOTO branch

:reindex
  ECHO     Calling the reindexer
  SET INDEXER=%QUICKSTART_HOME%\bedework\dist\temp\shellscr\indexer

  if exist %INDEXER% goto indexerok
    ECHO The indexer directory %INDEXER% does not exist. You probably need to do a rebuild.
    GOTO:EOF

  :indexerok
  cd %INDEXER%
  bwrun.bat reindex-nostart -user admin -indexlocprefix ..\..\..\..\..\

  GOTO:EOF

:zoneinfo
   ECHO    zoneinfo target is not supported on Windows
   GOTO:EOF

:jbossNotice
  ECHO *************************************************************
  ECHO The jboss configuration has been removed from the quickstart.
  ECHO It is now the default.  Remove the '-bwc jboss' option.
  ECHO *************************************************************
  GOTO:EOF

:doneWithArgs

IF "%bwc%" == "jboss" GOTO jbossNotice

IF NOT "%quickstart%empty" == "empty" GOTO checkBwConfig
IF NOT "%BWCONFIGS%empty" == "empty" GOTO DoneQB
SET BWCONFIGS=%HOMEPATH%\bwbuild
GOTO doneQB

:checkBwConfig

  SET BWCONFIGS=%QUICKSTART_HOME%\bedework\config\bwbuild

:doneQB
  SET BEDEWORK_CONFIGS_HOME=%BWCONFIGS%
  SET BEDEWORK_CONFIG=%BWCONFIGS%\%bwc%

  IF EXIST "%BEDEWORK_CONFIGS_HOME%\.platform" GOTO foundDotPlatform
  ECHO *******************************************************
  ECHO Error: Configurations directory %BEDEWORK_CONFIGS_HOME%
  ECHO is missing directory '.platform'.
  ECHO *******************************************************
  GOTO:EOF
:foundDotPlatform

  IF EXIST "%BEDEWORK_CONFIG%\build.properties" GOTO foundBuildProperties
  ECHO *******************************************************
  ECHO Error: Configuration %BEDEWORK_CONFIG%
  ECHO does not exist or is not a Bedework configuration.
  ECHO *******************************************************
  GOTO:EOF
:foundBuildProperties

  IF NOT "%JAVA_HOME%empty"=="empty" GOTO javaOk
  ECHO *******************************************************
  ECHO Error: JAVA_HOME is not defined correctly for Bedework.
  ECHO *******************************************************
  GOTO:EOF
:javaOk

:runBedework
  :: Make available for ant
  SET BWCONFIG=-Dorg.bedework.user.build.properties=%BEDEWORK_CONFIG%\build.properties

  ECHO.
  ECHO     BWCONFIGS = %BWCONFIGS%
  ECHO     BWCONFIG = %BWCONFIG%
  ECHO.

  IF NOT "%caldav%empty" == "empty"  cd %QUICKSTART_HOME%\bedework\projects\caldav
  IF NOT "%carddav%empty" == "empty" cd %QUICKSTART_HOME%\bedework-carddav
  IF NOT "%client%empty" == "empty"  cd %QUICKSTART_HOME%\bwclient
  IF NOT "%monitor%empty" == "empty" cd %QUICKSTART_HOME%\MonitorApp
  IF NOT "%naming%empty" == "empty"  cd %QUICKSTART_HOME%\bwnaming
  IF NOT "%tzsvr%empty" == "empty"   cd %QUICKSTART_HOME%\bwtzsvr
  IF NOT "%webdav%empty" == "empty"  cd %QUICKSTART_HOME%\bedework\projects\webdav

  "%JAVA_HOME%\bin\java.exe" -classpath %CLASSPATH% %offline% -Dant.home="%ANT_HOME%" org.apache.tools.ant.launch.Launcher "%BWCONFIG%" %1

  GOTO:EOF

:: Iterate over the command line arguments;
:: DOS Batch labels can't contain hyphens, so convert them
:: (otherwise, we could just "GOTO %1")
:branch
IF "%1" == "-quickstart" GOTO quickstart
IF "%1" == "-bwchome" GOTO bwchome
IF "%1" == "-bwc" GOTO bwc
IF "%1" == "-offline" GOTO offline
IF "%1" == "-reindex" GOTO reindex
IF "%1" == "-zoneinfo" GOTO zoneinfo

IF "%1" == "-log-silent" GOTO log-silent
IF "%1" == "-log-quiet" GOTO log-quiet
IF "%1" == "-log-inform" GOTO log-inform
IF "%1" == "-log-verbose" GOTO log-verbose
IF "%1" == "-ant-debug" GOTO ant-debug
IF "%1" == "-build-debug" GOTO build-debug

IF "%1" == "-carddav" GOTO carddav
IF "%1" == "-caldav" GOTO caldav
IF "%1" == "-client" GOTO client
IF "%1" == "-webdav" GOTO webdav
IF "%1" == "-monitor" GOTO monitor
IF "%1" == "-naming" GOTO naming
IF "%1" == "-tzsvr" GOTO tzsvr
GOTO doneWithArgs

:usage
  ECHO    Usage:
  ECHO.
  ECHO    bw [CONFIG-SOURCE] [CONFIG] [PROJECT] [ -offline ] [ target ]
  ECHO    bw ACTION
  ECHO.
  ECHO    Where:
  ECHO.
  ECHO    CONFIG-SOURCE optionally defines the location of configurations and is one or none of
  ECHO     -quickstart      to use the configurations within the quickstart
  ECHO                      e.g. "bw -quickstart start"
  ECHO     -bwchome path    to specify the location of the bwbuild directory
  ECHO.
  ECHO     The default is to look in the user home for the "bwbuild" directory.
  ECHO.
  ECHO    CONFIG optionally defines the configuration to build
  ECHO      -bwc configname      e.g. "-bwc mysql"
  ECHO.
  ECHO    -offline     Build without attempting to retrieve library jars
  ECHO    target       Ant target to execute (e.g. "start")
  ECHO.
  ECHO.
  ECHO.
  ECHO    PROJECT optionally defines the package to build and is none or more of
  ECHO     -carddav     Target is for the CardDAV build
  ECHO     -monitor     Target is for the bedework monitor application
  ECHO     -naming      Target is for the abstract naming api
  ECHO     The default is a calendar build
  ECHO.
  ECHO    Invokes ant to build or deploy the Bedework system. Uses a configuration
  ECHO    directory which contains one directory per configuration.
  ECHO.
  ECHO    Within each configuration directory we expect a file called
  ECHO    build.properties which should point to the property and options file
  ECHO    needed for the deploy process.
  ECHO.
  ECHO    In general these files will be in the same directory as build.properties.
  ECHO    The environment variable BEDEWORK_CONFIG contains the path to the current
  ECHO    configuration directory and can be used to build a path to the other files.
  ECHO.
  ECHO   ACTION defines an action to take usually in the context of the quickstart.
  ECHO    In a deployed system many of these actions are handled directly by a
  ECHO    deployed application. ACTION may be one of
  ECHO      -reindex - runs the indexer directly out of the quickstart bedework
  ECHO                 dist directory to rebuild the lucene indexes
REM   Don't support zoneinfo command on Windows for now
REM   ECHO      -zoneinfo - builds zoneinfo data for the timezones server
REM   ECHO                  requires -version and -tzdata parameters
  ECHO.
  ECHO.
  ECHO.

Add loglevel options to windows build

Add loglevel options to windows build


mkdir c:\projects\plib-build

if "%APPVEYOR_REPO_BRANCH%"=="appveyor_test" (
        set BOOST_ARGS=-DPLIB_TESTS_STATIC=ON -DBOOST_ROOT=C:\Libraries\boost_1_59_0
)

if "%USE_MINGW%"=="1" (
        cd c:\projects\plib-build
        set PATH=C:\MinGW\bin;C:\Program Files (x86)\CMake\bin
        set BUILD_TYPE=-DCMAKE_BUILD_TYPE=%configuration%

        cmake %BUILD_TYPE% -G"%CMAKE_GENERATOR%" %BOOST_ARGS% c:\projects\plib
        mingw32-make
        ctest
) else (
        if "%USE_MSYS%"=="1" (
                set PATH=C:\msys2\bin;C:\Program Files (x86)\CMake\bin
                c:\msys2\bin\bash c:\projects\plib\contrib\appveyor\build_msys.sh
        )
)

mkdir c:\projects\plib-build

if "%APPVEYOR_REPO_BRANCH%"=="appveyor_test" (
        set BOOST_ARGS=-DPLIB_TESTS_STATIC=ON -DBOOST_ROOT=C:\Libraries\boost_1_59_0
)

if "%USE_MINGW%"=="1" (
        cd c:\projects\plib-build
        set PATH="C:\MinGW\bin;C:\Program Files (x86)\CMake\bin"
        set BUILD_TYPE="-DCMAKE_BUILD_TYPE=%configuration%"

        cmake %BUILD_TYPE% -G"%CMAKE_GENERATOR%" %BOOST_ARGS% c:\projects\plib
        mingw32-make
        ctest
) else (
        if "%USE_MSYS%"=="1" (
                set PATH="C:\msys2\bin;C:\Program Files (x86)\CMake\bin"
                c:\msys2\bin\bash c:\projects\plib\contrib\appveyor\build_msys.sh
        )
)

appveyor: Use quotes for PATH environment variable


@ECHO OFF
REM ********************************************************************************
REM This script is for debugging chocolatey packaging issues.  it will uninstall
REM the existing chocolatey package.  It can be used before or after (most times
REM both) the install.bat
REM
REM Usage:  uninstall.bat
REM ********************************************************************************

cuninst -y {{GITHUB_PROJECT_NAME}}.portable

Add comments to uninstall.bat.

Add comments to uninstall.bat.


fsi^
  --optimize+^
  --lib:NHol^
  --use:system.fsx^
  --use:lib.fs^
  --use:fusion.fs^
  --use:basics.fs^
  --use:nets.fs^
  --use:printer.fs^
  --use:preterm.fs^
  --use:parser.fs^
  --use:equal.fs^
  --use:bool.fs^
  --use:drule.fs^
  --use:tactics.fs^
  --use:itab.fs^
  --use:simp.fs^
  --use:theorems.fs^
  --use:ind_defs.fs^
  --use:class.fs^
  --use:trivia.fs^
  --use:canon.fs^
  --use:meson.fs^
  --use:quot.fs^
  --use:pair.fs^
  --use:nums.fs^
  --use:recursion.fs^
  --use:arith.fs^
  --use:wf.fs^
  --use:calc_num.fs^
  --use:normalizer.fs^
  --use:grober.fs^
  --use:ind_types.fs^
  --use:lists.fs^
  --use:realax.fs^
  --use:calc_int.fs^
  --use:realarith.fs^
  --use:real.fs^
  --use:calc_rat.fs^
  --use:int.fs^
  --use:sets.fs^
  --use:iterate.fs^
  --use:cart.fs^
  --use:define.fs^
  --use:help.fs^
  --use:database.fs

fsi^
  --lib:NHol^
  --use:system.fsx^
  --use:lib.fs^
  --use:fusion.fs^
  --use:basics.fs^
  --use:nets.fs^
  --use:printer.fs^
  --use:preterm.fs^
  --use:parser.fs^
  --use:equal.fs^
  --use:bool.fs^
  --use:drule.fs^
  --use:tactics.fs^
  --use:itab.fs^
  --use:simp.fs^
  --use:theorems.fs^
  --use:ind_defs.fs^
  --use:class.fs^
  --use:trivia.fs^
  --use:canon.fs^
  --use:meson.fs^
  --use:quot.fs^
  --use:pair.fs^
  --use:nums.fs^
  --use:recursion.fs^
  --use:arith.fs^
  --use:wf.fs^
  --use:calc_num.fs^
  --use:normalizer.fs^
  --use:grober.fs^
  --use:ind_types.fs^
  --use:lists.fs^
  --use:realax.fs^
  --use:calc_int.fs^
  --use:realarith.fs^
  --use:real.fs^
  --use:calc_rat.fs^
  --use:int.fs^
  --use:sets.fs^
  --use:iterate.fs^
  --use:cart.fs^
  --use:define.fs^
  --use:help.fs^
  --use:database.fs

Remove optimization flag, for now. This'll help provide better error information whilst we're working out remaining bugs.


Update TuneJar.bat

Update TuneJar.bat


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

:: This script outputs the path to the executable that is created by
:: build.bat for the given configuration ("debug" or "release").
::
:: Having this file in this location, with this name, enables the current
:: experimental 'flutter run' support for desktop.
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set FLUTTER_CONFIG=%1

set PROJECT_NAME=Runner
set EXE_NAME=Flutter Desktop Example

set BASE_DIR=%~dp0
set FLUTTER_APP_DIR=%BASE_DIR%..\
set PRODUCTS_DIR=%FLUTTER_APP_DIR%build\windows\x86\

if "%FLUTTER_CONFIG%"=="release" (
  set BUILD_CONFIG=Release
) else (
  set BUILD_CONFIG=Debug
)

echo %PRODUCTS_DIR%%BUILD_CONFIG%\%PROJECT_NAME%\%EXE_NAME%.exe

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

:: This script outputs the path to the executable that is created by
:: build.bat for the given configuration ("debug" or "release").
::
:: Having this file in this location, with this name, enables the current
:: experimental 'flutter run' support for desktop.
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set FLUTTER_CONFIG=%1

set PROJECT_NAME=Runner
set EXE_NAME=Flutter Desktop Example

set BASE_DIR=%~dp0
set FLUTTER_APP_DIR=%BASE_DIR%..\
set PRODUCTS_DIR=%FLUTTER_APP_DIR%build\windows\x64\

if "%FLUTTER_CONFIG%"=="release" (
  set BUILD_CONFIG=Release
) else (
  set BUILD_CONFIG=Debug
)

echo %PRODUCTS_DIR%%BUILD_CONFIG%\%PROJECT_NAME%\%EXE_NAME%.exe

Fix name_output.bat typo (#334)

Fix name_output.bat typo (#334)

The build directory is x64, not x86.


@echo off

cd %APPVEYOR_BUILD_FOLDER%

:: Downloand and install blast to C:\blast

set ZIP_URL=https://github.com/npge/npge/releases/download/0.3.0/npge_0.3.0_win32.zip

if not exist c:\blast\blastn.exe (
    curl --silent --fail --max-time 120 --connect-timeout 30 -L --output npge_0.3.0_win32.zip %ZIP_URL%
    7z x npge_0.3.0_win32.zip
    mkdir c:\blast 2>NUL
    copy npge-0.3.0\blastn.exe c:\blast
    copy npge-0.3.0\makeblastdb.exe c:\blast
    copy npge-0.3.0\vcomp100.dll c:\blast
) else (
    echo BLAST already installed at c:\blast
)

set PATH=c:\blast;%PATH%
echo c:\blast added to PATH

add c:\blast to PATH

appveyor: add c:\blast to PATH


@ECHO OFF

ECHO Compiling pony-game...
REM Link to Windows Kits and native libraries.
REM http://tutorial.ponylang.org/appendices/compiler-args.html
ponyc -p "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64" -p "Bin\PonyGameNative\x64\Debug" -o Bin\PonyGame Source\PonyGame

ECHO Copying native libs...
COPY "Bin\PonyGameNative\x64\Debug\PonyGameNative.dll" "Bin\PonyGame"

PAUSE

ADDED: Build - Pause at the end of build batch file.


setlocal
rem Put curl on the PATH
set PATH=C:\Program Files\Git\mingw64\bin;%PATH%
set VERSION=2.0.5
mkdir %TEMP%\hlint
curl -o%TEMP%\hlint\hlint-%VERSION%.zip -L --insecure https://github.com/ndmitchell/hlint/releases/download/v%VERSION%/hlint-%VERSION%.zip
7z x %TEMP%\hlint\hlint-%VERSION%.zip -o%TEMP%\hlint -y
%TEMP%\hlint\hlint-%VERSION%\hlint.exe %*

setlocal
rem Put curl on the PATH
set PATH=C:\Program Files\Git\mingw64\bin;%PATH%
set VERSION=2.0.5
mkdir %TEMP%\hlint
curl -o%TEMP%\hlint\hlint.zip -L --insecure https://github.com/ndmitchell/hlint/releases/download/v%VERSION%/hlint-%VERSION%-x86_64-windows.zip
7z x %TEMP%\hlint\hlint.zip -o%TEMP%\hlint -y
%TEMP%\hlint\hlint-%VERSION%\hlint.exe %*

Update the Appveyor script to fetch with the full architecture name


@echo off
setlocal

set "async=true"
set "freq=120"

goto :parsePackage

:: functions

:help

:: TODO: put something here.

goto :eof

:usage

call :help 1>&2
exit /b 1

goto :eof

:: end functions

:parsePackage

if "%~1" == "" goto usage
set "package=%~1"
shift

:parseArgs

if "%~1" == "" goto doneParsing

if /i "%~1" == "-?" goto help
if /i "%~1" == "-h" goto help
if /i "%~1" == "--help" goto help

if /i "%~1" == "-f" (
    shift
    set "freq=%~1"
)

if /i "%~1" == "--freq" (
    shift
    set "freq=%~1"
)

if /i "%~1" == "--forward" (
    shift
    set "forwardArgs=%~1"
)

if /i "%~1" == "--stop-after" (
    shift
    set "duration=%~1"
)

if /i "%~1" == "--sync" set "async=false"

shift
goto parseArgs

:doneParsing

@echo off
setlocal

set "async=true"
set "freq=120"

goto :parsePackage

:: functions

:help

type "%~dp0help\popcornd.txt"

goto :eof

:usage

call :help 1>&2
exit /b 1

goto :eof

:: end functions

:parsePackage

if "%~1" == "" goto usage
set "package=%~1"
shift

:parseArgs

if "%~1" == "" goto doneParsing

if /i "%~1" == "-?" goto help
if /i "%~1" == "-h" goto help
if /i "%~1" == "--help" goto help

if /i "%~1" == "-f" (
    shift
    set "freq=%~1"
)

if /i "%~1" == "--freq" (
    shift
    set "freq=%~1"
)

if /i "%~1" == "--forward" (
    shift
    set "forwardArgs=%~1"
)

if /i "%~1" == "--stop-after" (
    shift
    set "duration=%~1"
)

if /i "%~1" == "--sync" set "async=false"

shift
goto parseArgs

:doneParsing

add help for popcornd.cmd

add help for popcornd.cmd


@echo off

set VCPKG_PANIC=on
set VCPKG_ROOT=c:\Users\jim\src\vcpkg

rem for %%i in (x64-windows x64-windows-static x86-windows x86-windows-static) DO (
rem     %VCPKG_ROOT%\vcpkg install --triplet=%i% openssl curl
rem )

rem x86_64-pc-windows-gnu i686-pc-windows-gnu
for %%i in (x86_64-pc-windows-msvc i686-pc-windows-msvc) DO (
    set RUSTFLAGS=-Ctarget-feature=+crt-static
    set VCPKGRS_DYNAMIC=
    echo %%i static
    cargo run --target %%i
    cargo clean
    set RUSTFLAGS=
    set VCPKGRS_DYNAMIC=1
    echo %%i dynamic
    cargo run --target %%i
    cargo clean
)

echo linux
bash -l -c "cargo run"

@echo off

set VCPKG_PANIC=on
set VCPKG_ROOT=c:\Users\jim\src\vcpkg

rem
for %%i in (x86_64-pc-windows-msvc i686-pc-windows-msvc x86_64-pc-windows-gnu i686-pc-windows-gnu) DO (
    set VCPKG_ALL_STATIC=on
    set VCPKG_ALL_DYNAMIC=
    echo %%i static
    cargo run --target %%i
    cargo clean
    set VCPKG_ALL_STATIC=
    set VCPKG_ALL_DYNAMIC=on
    echo %%i dynamic
    cargo run --target %%i
    cargo clean
)

echo linux
bash -l -c "cargo run"

use new style env vars in test.cmd

use new style env vars in test.cmd


setlocal
if not exist docker (
  git clone https://github.com/docker/docker
)
if not exist binary (
  mkdir binary
)
set BINDIR=%cd%
set image=docker
pushd docker
if not "%1x"=="x" (
  git fetch origin pull/%1/head:pr%1
  git checkout pr%1
  set image=dockerpr%1
)
docker build -t %image% -f Dockerfile.windows .
docker run --rm -v "%BINDIR%:c:\target" %image% sh -c 'cd /c/go/src/github.com/docker/docker; hack/make.sh binary; ec=$?; if [ $ec -eq 0 ]; then robocopy /c/go/src/github.com/docker/docker/bundles/$(cat VERSION)/binary-client /c/target/binary; robocopy /c/go/src/github.com/docker/docker/bundles/$(cat VERSION)/binary-daemon /c/target/binary; fi; exit $ec'
popd
dir binary

setlocal
if not exist docker (
  git clone https://github.com/docker/docker
)
if not exist binary (
  mkdir binary
)
set BINDIR=%cd%
set image=docker
pushd docker
if not "%1x"=="x" (
  git fetch origin pull/%1/head:pr%1
  git checkout pr%1
  set image=dockerpr%1
)
rem workaround from https://github.com/docker/docker/pull/26722
docker tag microsoft/windowsservercore:latest windowsservercore:latest
docker build -t %image% -f Dockerfile.windows .
docker run --rm -v "%BINDIR%:c:\target" %image% sh -c 'cd /c/go/src/github.com/docker/docker; hack/make.sh binary; ec=$?; if [ $ec -eq 0 ]; then robocopy /c/go/src/github.com/docker/docker/bundles/$(cat VERSION)/binary-client /c/target/binary; robocopy /c/go/src/github.com/docker/docker/bundles/$(cat VERSION)/binary-daemon /c/target/binary; fi; exit $ec'
popd
dir binary

Create tag windowsservercore

Create tag windowsservercore

Signed-off-by: Stefan Scherer <2fe843265e65a9540d5df64f4bed2ee6b7ca283e@icloud.com>


@echo off
REM $Id: phd.bat,v 1.3 2008-12-02 21:27:09 kalle Exp $

@"@php_bin@" "@bin_dir@\build.php" %*

@echo off
REM $Id: phd.bat,v 1.4 2009-03-20 12:53:41 bjori Exp $

@"@php_bin@" "@bin_dir@\build.php" %*

Fix newlines (Nicholas Sloan)

Fix newlines (Nicholas Sloan)


Fix newlines (Nicholas Sloan)

Fix newlines (Nicholas Sloan)

git-svn-id: 84b5c82ecc7932ed0fd81274a5b44f356df90ae1@277516 c90b9560-bf6c-de11-be94-00142212c4b1


:<<"::IGNORE_THIS_LINE"
@echo off
goto :CMDSCRIPT
::IGNORE_THIS_LINE

# Script to stitch panoramic videos produced by Samsung Gear360 (and others?).
#
# For help (hopefully) see:
# https://github.com/ultramango/gear360pano
#
# Names:
# dec, DEC, decoding - means video -> images
# enc, ENC, encoding - means stitched images -> video
#
# Trick with Win/Linux from here:
# http://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash

################################ Linux part here ################################

#############
### Constants

# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-which-directory-it-is-stored-in
DIR=$(dirname `which $0`)
FRAMESTEMPDIRSUFF="frames"
OUTTEMPDIRSUFF="out"
OUTDIR="$DIR/html/data"
# Options, default is the quality option, overridable by speed parameter
FFMPEGQUALITYDEC="-q:v 2"
FFMPEGQUALITYENC="-c:v libx265 -x265-params crf=18"
IMAGETMPLDEC="image%05d.jpg"
IMAGETMPLENC="image%05d_pano.jpg"
PTOTMPL4K="gear360video4k.pto"
PTOTMPL2K="gear360video2k.pto"
# This is a default, it will/should be overwritten anyway
PTOTMPL="$DIR/${PTOTMPL4K}"
TMPAUDIO="tmpaudio.aac"
TMPVIDEO="tmpvideo.mp4"
# Throttle parallel processing to give some room for other processes
# See: https://www.gnu.org/software/parallel/parallel_tutorial.html#Limiting-the-resources
PARALLELEXTRAOPTS="--load 99% --noswap --memfree 500M"
# Debug, yes = print debug messages
DEBUG="no"

#############
### Functions

# Debug, arguments:
# 1. Text to print
print_debug() {
  if [ "$DEBUG" == "yes" ]; then
    echo "DEBUG: $@"
  fi
}

# Clean-up function
clean_up() {
  echo "Removing temporary directories..."
  if [ -d "$FRAMESTEMPDIR" ]; then
    print_debug "Removing frames directory: $FRAMESTEMPDIR"
    rm -rf "$FRAMESTEMPDIR"
  fi
  if [ -d "$OUTTEMPDIR" ]; then
    print_debug "Removing output directory: $OUTTEMPDIR"
    rm -rf "$OUTTEMPDIR"
  fi
}

# Function to run a command and check the result
# http://stackoverflow.com/questions/5195607/checking-bash-exit-status-of-several-commands-efficiently
run_command() {
  # Remove empty arguments (it will confuse the executed command)
  local cmd=("$@")
  for i in "${!cmd[@]}"; do
    [ -n "${cmd[$i]}" ] || unset "cmd[$i]"
  done

  print_debug "Running command: " "${cmd[@]}"
  "${cmd[@]}"
  local status=$?
  if [ $status -ne 0 ]; then
    # We failed, inform the user and clean-up
    echo "Error while running $1" >&2
    if [ $1 != "notify-send" ]; then
       # Display error in a nice graphical popup if available
       run_command notify-send -a $0 "Error while running $1"
    fi
    clean_up
    exit 1
  fi
  return $status
}

# Print help for the user
print_help() {
  echo -e "\nSmall script to stitch raw panoramic videos."
  echo "Raw meaning two fisheye images side by side."
  echo -e "Script originally writen for Samsung Gear 360.\n"
  echo -e "Usage:\n$0 [options] infile [outfile]\n"
  echo "Where infile is a panoramic video file, output"
  echo "parameter is optional. Video file will be written"
  echo "to a file with appended _pano, ex.: dummy.mp4 will"
  echo -e "be stitched to dummy_pano.mp4.\n"
  echo "-o|--output DIR will set the output directory of panoramas"
  echo "                default: html/data"
  echo "-p|--parallel   use GNU Parallel to speed-up processing"
  echo "-s|--speed      optimise for speed (lower quality)"
  echo "-t|--temp DIR   set temporary directory (default: system's"
  echo "                temporary directory)"
  echo "-h|--help       prints this help"
}

check_preconditions() {
  # Check if we have the software to do it
  # http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
  local error=0

  type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg required but it's not installed. Will abort."; error=1; }
  type multiblend >/dev/null 2>&1 || { echo >&2 "multiblend required but it's not installed. Will abort."; error=1; }

  # Use parallel? Check if we have it
  # https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
  if [ ! -z "${USEPARALLEL+x}" ]; then
    type parallel >/dev/null 2>&1 || { echo >&2 "GNU Parallel use enabled but it's not installed. Will abort."; error=1; }
  fi

  if [ $error -ne 0 ]; then
    exit 1
  fi
}

######################
### "Main" starts here

# Check required argument(s)
if [ -z "${1+x}" ]; then
  print_help
  run_command notify-send -a $0 "Please provide an input file."
  exit 1
fi

# Process command line options. Source (modified):
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
  -h|--help)
    print_help
    shift
    exit 0
    ;;
  -o|--output)
    OUTDIR="$2"
    if [ ! -d "$2" ]; then
      echo "Given output ($2) is not a directory, cannot continue"
      exit 1
    fi
    shift
    shift
    ;;
  -p|--parallel)
    # Switch to use parallel
    USEPARALLEL=1
    print_debug "Use of GNU Parallel enabled"
    shift
    ;;
  -t|--temp)
    if [ -d "$2" ]; then
      TEMPDIRPREFIX="$2"
    else
      echo "Given temporary ($2) is not a directory, using default"
    fi
    shift
    shift
    ;;
  -s|--speed)
    FFMPEGQUALITYDEC=""
    FFMPEGQUALITYENC="-vcodec libx264"
    shift
    ;;
  *)
    break
    ;;
esac
done

# Output name as second argument plus output directory
if [ -z "${2+x}" ]; then
  # If invoked by nautilus open-with, we need to remember the proper directory in the outname
  OUTNAME=$OUTDIR/`basename "${1%.*}"`_pano.mp4
  print_debug "Output filename: $OUTNAME"
else
  OUTNAME=$OUTDIR/`basename $2`
fi

# Check if software is installed
check_preconditions

# Start counting time
STARTTS=`date +%s`

# Handle temporary directories
if [ -n "$TEMPDIRPREFIX" ]; then
  # On some systems not using '-p .' (temp in current dir) might cause problems
  FRAMESTEMPDIR=`mktemp -d -p $TEMPDIRPREFIX`
  OUTTEMPDIR=`mktemp -d -p $TEMPDIRPREFIX`
else
  FRAMESTEMPDIR=`mktemp -d`
  OUTTEMPDIR=`mktemp -d`
fi

# Extract frames from video
run_command notify-send -a $0 "Starting panoramic video stitching..."
echo "Extracting frames from video (this might take a while)..."
# Note: anything in quotes will be treated as one single option
run_command "ffmpeg" "-y" "-i" "$1" $FFMPEGQUALITYDEC "$FRAMESTEMPDIR/$IMAGETMPLDEC"

# Detect video size (http://trac.ffmpeg.org/wiki/FFprobeTips)
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width "$1")
SRCVIDEOSIZE=${streams_stream_0_width}:${streams_stream_0_height}
print_debug "Input video size: ${SRCVIDEOSIZE}"

# Detect video size and select appriopriate pto file
case $SRCVIDEOSIZE in
  3840:1920)
    PTOTMPL=$PTOTMPL4K
    ;;
  2560:1280)
    PTOTMPL=$PTOTMPL2K
    ;;
  *)
    PTOTMPL=$PTOTMPL4K
    ;;
esac
print_debug "PTO template: ${PTOTMPL}"

# Stitch frames
echo "Stitching frames..."
if [ -z "${USEPARALLEL+x}" ]; then
  # No parallel
  for panofile in $FRAMESTEMPDIR/*.jpg; do
    echo Frame: $panofile
    run_command "$DIR/gear360pano.cmd" -r -m -o "$OUTTEMPDIR" "$panofile" "$PTOTMPL"
  done
else
  # Use parallel
  export -f print_debug
  export -f run_command
  ls -1 $FRAMESTEMPDIR/*.jpg | parallel $PARALLELEXTRAOPTS --bar run_command "$DIR/gear360pano.cmd" -r -m -o "$OUTTEMPDIR" {} "$PTOTMPL"
fi

# Put stitched frames together
echo "Recoding the video..."
# Detect source FPS (probe streams until some sane fps found, naive but should work)
for streamno in {0..5}; do
  SRCFPSSTR=`ffprobe -v fatal -of default=noprint_wrappers=1:nokey=1 -select_streams $streamno -show_entries stream=r_frame_rate "$1"`
  print_debug "Stream: $streamno FPS: $SRCFPSSTR"
  if [ $SRCFPSSTR != "0/0" ]; then
    break;
  fi
done
if [ $streamno -eq 5 ]; then
  print_debug "Couldn't find FPS, assuming 30000/1001"
  SRCFPSSTR="30000/1001"
fi

print_debug "Input video FPS: ${SRCFPSSTR}"

# Re-encode video back with stitched images
run_command ffmpeg -y -f image2 -i "$OUTTEMPDIR/$IMAGETMPLENC" -r "${SRCFPSSTR}" -s "${SRCVIDEOSIZE}" $FFMPEGQUALITYENC "$OUTTEMPDIR/$TMPVIDEO"

# Check if there's audio present (https://stackoverflow.com/questions/21446804/find-if-video-file-has-audio-present-in-it)
SRCHASAUDIO=`ffprobe -v fatal -of default=nw=1:nk=1 -show_streams -select_streams a -show_entries stream=codec_type "$1"`
print_debug "Input video has audio: ${SRCHASAUDIO}"

if [ -n "$SRCHASAUDIO" ]; then
  echo "Extracting audio..."
  run_command notify-send -a $0 "Extracting audio from source video..."
  run_command ffmpeg -y -i "$1" -vn -acodec copy "$OUTTEMPDIR/$TMPAUDIO"

  echo "Merging audio..."
  run_command notify-send -a $0 "Merging audio with final video..."
  run_command ffmpeg -y -i "$OUTTEMPDIR/$TMPVIDEO" -i "$OUTTEMPDIR/$TMPAUDIO" -c:v copy -c:a aac -strict experimental "$OUTNAME"
else
  print_debug "No audio detected (timelapse video?), continuing..."
  mv "$OUTTEMPDIR/$TMPVIDEO" "$OUTNAME"
fi

# Remove temporary directories
clean_up

# Inform user about the result
ENDTS=`date +%s`
RUNTIME=$((ENDTS-STARTTS))
echo Video written to $OUTNAME, took: $RUNTIME s
run_command notify-send -a $0 "'Conversion complete. Video written to $OUTNAME, took: $RUNTIME s'"
exit 0

################################ Windows part here
# TODO: update to match Linux functionality

:CMDSCRIPT

set FFMPEGPATH=c:\Program Files\ffmpeg\bin
set FRAMESTEMPDIR=frames
set OUTTEMPDIR=frames_stitched
set PTOTMPL=gear360video.pto
rem %% is an escape character (note: this will fail on wine's cmd.exe)
set IMAGETMPLDEC=image%%05d.jpg
set IMAGETMPLENC=image%%05d_pano.jpg
set TMPAUDIO=tmpaudio.aac
set TMPVIDEO=tmpvideo.mp4
set DEBUG=""

rem Check arguments
IF [%1] == [] GOTO NOARGS

:SETNAMEOK
rem Check ffmpeg...
if exist "%FFMPEGPATH%/ffmpeg.exe" goto FFMPEGOK
goto NOFFMPEG

:FFMPEGOK
rem Create temporary directories
mkdir %FRAMESTEMPDIR%
mkdir %OUTTEMPDIR%

rem Execute commands (as simple as it is)
echo Converting video to images...
"%FFMPEGPATH%/ffmpeg.exe" -y -i %1 %FRAMESTEMPDIR%/%IMAGETMPLDEC%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

rem Stitching
echo Stitching frames...
for %%f in (%FRAMESTEMPDIR%/*.jpg) do (
rem For whatever reason (this has to be at the beginning of the line!)
  echo Processing frame %FRAMESTEMPDIR%\%%f
rem TODO: There should be some error checking
  call gear360pano.cmd /m /o %OUTTEMPDIR% %FRAMESTEMPDIR%\%%f %PTOTMPL%
)

echo "Reencoding video..."
"%FFMPEGPATH%/ffmpeg.exe" -y -f image2 -i %OUTTEMPDIR%/%IMAGETMPLENC% -r 30 -s 3840:1920 -vcodec libx264 %OUTTEMPDIR%/%TMPVIDEO%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

echo "Extracting audio..."
"%FFMPEGPATH%/ffmpeg.exe" -y -i %1 -vn -acodec copy %OUTTEMPDIR%/%TMPAUDIO%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

echo "Merging audio..."

rem Check if second argument present, if not, set some default for output filename
rem This is here, because for whatever reason OUTNAME gets overriden by
rem the last iterated filename if this is at the beginning (for loop is buggy?)
if not [%2] == [] goto SETNAMEOK
set OUTNAME="%~n1_pano.mp4"

:SETNAMEOK
"%FFMPEGPATH%/ffmpeg.exe" -y -i %OUTTEMPDIR%/%TMPVIDEO% -i %OUTTEMPDIR%/%TMPAUDIO% -c:v copy -c:a aac -strict experimental %OUTNAME%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

rem Clean-up (f - force, read-only & dirs, q - quiet)
del /f /q %FRAMESTEMPDIR%
del /f /q %OUTTEMPDIR%

echo Video written to %OUTNAME%
goto eof

:NOARGS
echo Script to stitch raw video panorama files, raw
echo meaning two fisheye images side by side.
echo.
echo Script originally writen for Samsung Gear 360.
echo.
echo Usage:
echo %0 [options] inputfile [outputfile]
echo.
echo Where inputfile is a panorama file from camera,
echo output parameter is optional
goto eof

:NOFFMPEG
echo ffmpeg was not found in %FFMPEGPATH%, download from: https://ffmpeg.zeranoe.com/builds/
echo and unpack to program files directory
goto eof

:FFMPEGERROR
echo ffmpeg failed, video not created
goto eof

:PRINT_DEBUG
if %DEBUG% == "yes" (
  echo DEBUG: %1 %2 %3 %4 %5 %6 %7 %8 %9
)

exit /b 0

:eof

:<<"::IGNORE_THIS_LINE"
@echo off
goto :CMDSCRIPT
::IGNORE_THIS_LINE

# Script to stitch panoramic videos produced by Samsung Gear360 (and others?).
#
# For help (hopefully) see:
# https://github.com/ultramango/gear360pano
#
# Names:
# dec, DEC, decoding - means video -> images
# enc, ENC, encoding - means stitched images -> video
#
# Trick with Win/Linux from here:
# http://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash

################################ Linux part here ################################

#############
### Constants

# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-which-directory-it-is-stored-in
DIR=$(dirname `which $0`)
FRAMESTEMPDIRSUFF="frames"
OUTTEMPDIRSUFF="out"
OUTDIR="$DIR/html/data"
# Options, default is the quality option, overridable by speed parameter
FFMPEGQUALITYDEC="-q:v 2"
FFMPEGQUALITYENC="-c:v libx265 -x265-params crf=18"
IMAGETMPLDEC="image%05d.jpg"
IMAGETMPLENC="image%05d_pano.jpg"
PTOTMPL4K="gear360video4k.pto"
PTOTMPL2K="gear360video2k.pto"
# This is a default, it will/should be overwritten anyway
PTOTMPL="$DIR/${PTOTMPL4K}"
TMPAUDIO="tmpaudio.aac"
TMPVIDEO="tmpvideo.mp4"
# Throttle parallel processing to give some room for other processes
# See: https://www.gnu.org/software/parallel/parallel_tutorial.html#Limiting-the-resources
PARALLELEXTRAOPTS="--load 99% --noswap --memfree 500M"
# Debug, yes = print debug messages
DEBUG="no"

#############
### Functions

# Debug, arguments:
# 1. Text to print
print_debug() {
  if [ "$DEBUG" == "yes" ]; then
    echo "DEBUG: $@"
  fi
}

# Clean-up function
clean_up() {
  echo "Removing temporary directories..."
  if [ -d "$FRAMESTEMPDIR" ]; then
    print_debug "Removing frames directory: $FRAMESTEMPDIR"
    rm -rf "$FRAMESTEMPDIR"
  fi
  if [ -d "$OUTTEMPDIR" ]; then
    print_debug "Removing output directory: $OUTTEMPDIR"
    rm -rf "$OUTTEMPDIR"
  fi
}

# Function to run a command and check the result
# http://stackoverflow.com/questions/5195607/checking-bash-exit-status-of-several-commands-efficiently
run_command() {
  # Remove empty arguments (it will confuse the executed command)
  local cmd=("$@")
  for i in "${!cmd[@]}"; do
    [ -n "${cmd[$i]}" ] || unset "cmd[$i]"
  done

  print_debug "Running command: " "${cmd[@]}"
  "${cmd[@]}"
  local status=$?
  if [ $status -ne 0 ]; then
    # We failed, inform the user and clean-up
    echo "Error while running $1" >&2
    if [ $1 != "notify-send" ]; then
       # Display error in a nice graphical popup if available
       run_command notify-send -a $0 "Error while running $1"
    fi
    clean_up
    exit 1
  fi
  return $status
}

# Print help for the user
print_help() {
  echo -e "\nSmall script to stitch raw panoramic videos."
  echo "Raw meaning two fisheye images side by side."
  echo -e "Script originally writen for Samsung Gear 360.\n"
  echo -e "Usage:\n$0 [options] infile [outfile]\n"
  echo "Where infile is a panoramic video file, output"
  echo "parameter is optional. Video file will be written"
  echo "to a file with appended _pano, ex.: dummy.mp4 will"
  echo -e "be stitched to dummy_pano.mp4.\n"
  echo "-o|--output DIR will set the output directory of panoramas"
  echo "                default: html/data"
  echo "-p|--parallel   use GNU Parallel to speed-up processing"
  echo "-s|--speed      optimise for speed (lower quality)"
  echo "-t|--temp DIR   set temporary directory (default: system's"
  echo "                temporary directory)"
  echo "-h|--help       prints this help"
}

check_preconditions() {
  # Check if we have the software to do it
  # http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
  local error=0

  type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg required but it's not installed. Will abort."; error=1; }
  type multiblend >/dev/null 2>&1 || { echo >&2 "multiblend required but it's not installed. Will abort."; error=1; }

  # Use parallel? Check if we have it
  # https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
  if [ ! -z "${USEPARALLEL+x}" ]; then
    type parallel >/dev/null 2>&1 || { echo >&2 "GNU Parallel use enabled but it's not installed. Will abort."; error=1; }
  fi

  if [ $error -ne 0 ]; then
    exit 1
  fi
}

######################
### "Main" starts here

# Check required argument(s)
if [ -z "${1+x}" ]; then
  print_help
  run_command notify-send -a $0 "Please provide an input file."
  exit 1
fi

# Process command line options. Source (modified):
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
  -h|--help)
    print_help
    shift
    exit 0
    ;;
  -o|--output)
    OUTDIR="$2"
    if [ ! -d "$2" ]; then
      echo "Given output ($2) is not a directory, cannot continue"
      exit 1
    fi
    shift
    shift
    ;;
  -p|--parallel)
    # Switch to use parallel
    USEPARALLEL=1
    print_debug "Use of GNU Parallel enabled"
    shift
    ;;
  -t|--temp)
    if [ -d "$2" ]; then
      TEMPDIRPREFIX="$2"
    else
      echo "Given temporary ($2) is not a directory, using default"
    fi
    shift
    shift
    ;;
  -s|--speed)
    FFMPEGQUALITYDEC=""
    FFMPEGQUALITYENC="-vcodec libx264"
    shift
    ;;
  *)
    break
    ;;
esac
done

# Output name as second argument plus output directory
if [ -z "${2+x}" ]; then
  # If invoked by nautilus open-with, we need to remember the proper directory in the outname
  OUTNAME=$OUTDIR/`basename "${1%.*}"`_pano.mp4
  print_debug "Output filename: $OUTNAME"
else
  OUTNAME=$OUTDIR/`basename $2`
fi

# Check if software is installed
check_preconditions

# Start counting time
STARTTS=`date +%s`

# Handle temporary directories
if [ -n "$TEMPDIRPREFIX" ]; then
  # On some systems not using '-p .' (temp in current dir) might cause problems
  FRAMESTEMPDIR=`mktemp -d -p $TEMPDIRPREFIX`
  OUTTEMPDIR=`mktemp -d -p $TEMPDIRPREFIX`
else
  FRAMESTEMPDIR=`mktemp -d`
  OUTTEMPDIR=`mktemp -d`
fi

# Extract frames from video
run_command notify-send -a $0 "Starting panoramic video stitching..."
echo "Extracting frames from video (this might take a while)..."
# Note: anything in quotes will be treated as one single option
run_command "ffmpeg" "-y" "-i" "$1" $FFMPEGQUALITYDEC "$FRAMESTEMPDIR/$IMAGETMPLDEC"

# Detect video size (http://trac.ffmpeg.org/wiki/FFprobeTips)
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width "$1")
SRCVIDEOSIZE=${streams_stream_0_width}:${streams_stream_0_height}
print_debug "Input video size: ${SRCVIDEOSIZE}"

# Detect video size and select appriopriate pto file
case $SRCVIDEOSIZE in
  3840:1920)
    PTOTMPL=$PTOTMPL4K
    ;;
  2560:1280)
    PTOTMPL=$PTOTMPL2K
    ;;
  *)
    PTOTMPL=$PTOTMPL4K
    ;;
esac
print_debug "PTO template: ${PTOTMPL}"

# Stitch frames
echo "Stitching frames..."
if [ -z "${USEPARALLEL+x}" ]; then
  # No parallel
  find $FRAMESTEMPDIR -type f -name '*.jpg' | xargs -Ipanofile run_command "$DIR/gear360pano.cmd" -r -m -o "$OUTTEMPDIR" "panofile" "$PTOTMPL"
else
  # Use parallel
  export -f print_debug
  export -f run_command
  #ls -1 $FRAMESTEMPDIR/*.jpg | parallel $PARALLELEXTRAOPTS --bar run_command "$DIR/gear360pano.cmd" -r -m -o "$OUTTEMPDIR" {} "$PTOTMPL"
  find $FRAMESTEMPDIR -type f -name '*.jpg' | parallel $PARALLELEXTRAOPTS --bar run_command "$DIR/gear360pano.cmd" -r -m -o "$OUTTEMPDIR" {} "$PTOTMPL"
fi

# Put stitched frames together
echo "Recoding the video..."
# Detect source FPS (probe streams until some sane fps found, naive but should work)
for streamno in {0..5}; do
  SRCFPSSTR=`ffprobe -v fatal -of default=noprint_wrappers=1:nokey=1 -select_streams $streamno -show_entries stream=r_frame_rate "$1"`
  print_debug "Stream: $streamno FPS: $SRCFPSSTR"
  if [ $SRCFPSSTR != "0/0" ]; then
    break;
  fi
done
if [ $streamno -eq 5 ]; then
  print_debug "Couldn't find FPS, assuming 30000/1001"
  SRCFPSSTR="30000/1001"
fi

print_debug "Input video FPS: ${SRCFPSSTR}"

# Re-encode video back with stitched images
run_command ffmpeg -y -f image2 -i "$OUTTEMPDIR/$IMAGETMPLENC" -r "${SRCFPSSTR}" -s "${SRCVIDEOSIZE}" $FFMPEGQUALITYENC "$OUTTEMPDIR/$TMPVIDEO"

# Check if there's audio present (https://stackoverflow.com/questions/21446804/find-if-video-file-has-audio-present-in-it)
SRCHASAUDIO=`ffprobe -v fatal -of default=nw=1:nk=1 -show_streams -select_streams a -show_entries stream=codec_type "$1"`
print_debug "Input video has audio: ${SRCHASAUDIO}"

if [ -n "$SRCHASAUDIO" ]; then
  echo "Extracting audio..."
  run_command notify-send -a $0 "Extracting audio from source video..."
  run_command ffmpeg -y -i "$1" -vn -acodec copy "$OUTTEMPDIR/$TMPAUDIO"

  echo "Merging audio..."
  run_command notify-send -a $0 "Merging audio with final video..."
  run_command ffmpeg -y -i "$OUTTEMPDIR/$TMPVIDEO" -i "$OUTTEMPDIR/$TMPAUDIO" -c:v copy -c:a aac -strict experimental "$OUTNAME"
else
  print_debug "No audio detected (timelapse video?), continuing..."
  mv "$OUTTEMPDIR/$TMPVIDEO" "$OUTNAME"
fi

# Remove temporary directories
clean_up

# Inform user about the result
ENDTS=`date +%s`
RUNTIME=$((ENDTS-STARTTS))
echo Video written to $OUTNAME, took: $RUNTIME s
run_command notify-send -a $0 "'Conversion complete. Video written to $OUTNAME, took: $RUNTIME s'"
exit 0

################################ Windows part here
# TODO: update to match Linux functionality

:CMDSCRIPT

set FFMPEGPATH=c:\Program Files\ffmpeg\bin
set FRAMESTEMPDIR=frames
set OUTTEMPDIR=frames_stitched
set PTOTMPL=gear360video.pto
rem %% is an escape character (note: this will fail on wine's cmd.exe)
set IMAGETMPLDEC=image%%05d.jpg
set IMAGETMPLENC=image%%05d_pano.jpg
set TMPAUDIO=tmpaudio.aac
set TMPVIDEO=tmpvideo.mp4
set DEBUG=""

rem Check arguments
IF [%1] == [] GOTO NOARGS

:SETNAMEOK
rem Check ffmpeg...
if exist "%FFMPEGPATH%/ffmpeg.exe" goto FFMPEGOK
goto NOFFMPEG

:FFMPEGOK
rem Create temporary directories
mkdir %FRAMESTEMPDIR%
mkdir %OUTTEMPDIR%

rem Execute commands (as simple as it is)
echo Converting video to images...
"%FFMPEGPATH%/ffmpeg.exe" -y -i %1 %FRAMESTEMPDIR%/%IMAGETMPLDEC%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

rem Stitching
echo Stitching frames...
for %%f in (%FRAMESTEMPDIR%/*.jpg) do (
rem For whatever reason (this has to be at the beginning of the line!)
  echo Processing frame %FRAMESTEMPDIR%\%%f
rem TODO: There should be some error checking
  call gear360pano.cmd /m /o %OUTTEMPDIR% %FRAMESTEMPDIR%\%%f %PTOTMPL%
)

echo "Reencoding video..."
"%FFMPEGPATH%/ffmpeg.exe" -y -f image2 -i %OUTTEMPDIR%/%IMAGETMPLENC% -r 30 -s 3840:1920 -vcodec libx264 %OUTTEMPDIR%/%TMPVIDEO%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

echo "Extracting audio..."
"%FFMPEGPATH%/ffmpeg.exe" -y -i %1 -vn -acodec copy %OUTTEMPDIR%/%TMPAUDIO%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

echo "Merging audio..."

rem Check if second argument present, if not, set some default for output filename
rem This is here, because for whatever reason OUTNAME gets overriden by
rem the last iterated filename if this is at the beginning (for loop is buggy?)
if not [%2] == [] goto SETNAMEOK
set OUTNAME="%~n1_pano.mp4"

:SETNAMEOK
"%FFMPEGPATH%/ffmpeg.exe" -y -i %OUTTEMPDIR%/%TMPVIDEO% -i %OUTTEMPDIR%/%TMPAUDIO% -c:v copy -c:a aac -strict experimental %OUTNAME%
if %ERRORLEVEL% EQU 1 GOTO FFMPEGERROR

rem Clean-up (f - force, read-only & dirs, q - quiet)
del /f /q %FRAMESTEMPDIR%
del /f /q %OUTTEMPDIR%

echo Video written to %OUTNAME%
goto eof

:NOARGS
echo Script to stitch raw video panorama files, raw
echo meaning two fisheye images side by side.
echo.
echo Script originally writen for Samsung Gear 360.
echo.
echo Usage:
echo %0 [options] inputfile [outputfile]
echo.
echo Where inputfile is a panorama file from camera,
echo output parameter is optional
goto eof

:NOFFMPEG
echo ffmpeg was not found in %FFMPEGPATH%, download from: https://ffmpeg.zeranoe.com/builds/
echo and unpack to program files directory
goto eof

:FFMPEGERROR
echo ffmpeg failed, video not created
goto eof

:PRINT_DEBUG
if %DEBUG% == "yes" (
  echo DEBUG: %1 %2 %3 %4 %5 %6 %7 %8 %9
)

exit /b 0

:eof

fix 'argument list too long'

fix 'argument list too long'


build fix

build fix


:: Task API for Nuke
:: Create and launch from Nuke working directory
::
:: This file is called whenever a user launches Nuke
::
:: Arguments:
::   %1: Name of task, e.g. comp, roto
::
:: Example:
::   $ p999_Meindbender_Sync
::   $ sh010
::   $ nuke comp

@echo off

:: if user doesn't have app installed
:: if Not exist "C:\Program Files\The Foundry\NUKE\Nuke10.0v2\Nuke10.0.exe" goto :missing_app

:: if user forgot to set project or asset
if "%MINDBENDER_PROJECTPATH%"=="" goto :missing_set_project
if "%MINDBENDER_ASSET%"=="" goto :missing_set_asset

:: If user forgets to include task with "maya"..
if "%1"=="" goto :missing_task

if not exist "%1" goto :missing_taskfolder

set MINDBENDER_WORKDIR=%cd%\%1\%USERNAME%\nuke
if Not exist %MINDBENDER_WORKDIR% (
    echo Creating folders for task "%1"..

    :: Arvid, redigera gärna den här Nuke mapp strukturen
    mkdir %MINDBENDER_WORKDIR%\nk
    mkdir %MINDBENDER_WORKDIR%\scripts
    mkdir %MINDBENDER_WORKDIR%\cache
    mkdir %MINDBENDER_WORKDIR%\render
    rem etc..
)

:: Initialisation files
set NUKE_PATH=%MINDBENDER_CORE%\mindbender\nuke\nuke_path;%NUKE_PATH%
set PYBLISHPLUGINPATH=%MINDBENDER_CORE%\mindbender\plugins\nuke;%PYBLISHPLUGINPATH%

:: Set filepath for open script window
pushd %MINDBENDER_WORKDIR%\nk

:: Launch (local) Nuke
echo Launching NukeX @ %MINDBENDER_WORKDIR%..
start "NukeX" "C:\Program Files\The Foundry\NUKE\Nuke10.0v2\Nuke10.0" --nukex

popd
goto :eof

:missing_task
    Echo Which task? E.g. "comp", "roto"
:missing_set_project
    Echo You must set a project before Launch
    Exit /B
:missing_set_asset
    Echo You have a project set %MINDBENDER_PROJECTPATH%
    Echo You must set a Asset before Launch
    Exit /B
:missing_app
    Echo You dont have the app installed on your workstation, or could be you dont have correct version
    Exit /B
:missing_taskfolder
    echo ERROR: Unrecognised command "%1"
    exit /B

:: Task API for Nuke
:: Create and launch from Nuke working directory
::
:: This file is called whenever a user launches Nuke
::
:: Arguments:
::   %1: Name of task, e.g. comp, roto
::
:: Example:
::   $ p999_Meindbender_Sync
::   $ sh010
::   $ nuke comp

@echo off

:: if user doesn't have app installed
:: if Not exist "C:\Program Files\The Foundry\NUKE\Nuke10.0v2\Nuke10.0.exe" goto :missing_app

:: if user forgot to set project or asset
if "%MINDBENDER_PROJECTPATH%"=="" goto :missing_set_project
if "%MINDBENDER_ASSET%"=="" goto :missing_set_asset

:: If user forgets to include task with "maya"..
if "%1"=="" goto :missing_task

if not exist "%1" goto :missing_taskfolder

set MINDBENDER_WORKDIR=%cd%\%1\%USERNAME%\nuke
if Not exist %MINDBENDER_WORKDIR% (
    echo Creating new task "%1"..

    :: Arvid, redigera gärna den här Nuke mapp strukturen
    mkdir %MINDBENDER_WORKDIR%\nk
    mkdir %MINDBENDER_WORKDIR%\scripts
    mkdir %MINDBENDER_WORKDIR%\cache
    mkdir %MINDBENDER_WORKDIR%\render
    rem etc..
)

:: Initialisation files
set NUKE_PATH=%MINDBENDER_CORE%\mindbender\nuke\nuke_path;%NUKE_PATH%
set PYBLISHPLUGINPATH=%MINDBENDER_CORE%\mindbender\plugins\nuke;%PYBLISHPLUGINPATH%

:: Set filepath for open script window
pushd %MINDBENDER_WORKDIR%\nk

:: Launch (local) Nuke
echo Launching NukeX @ %MINDBENDER_WORKDIR%..
start "NukeX" "C:\Program Files\The Foundry\NUKE\Nuke10.0v2\Nuke10.0" --nukex

popd
goto :eof

:missing_task
    Echo Which task? E.g. "comp", "roto"
:missing_set_project
    Echo You must set a project before Launch
    Exit /B
:missing_set_asset
    Echo You have a project set %MINDBENDER_PROJECTPATH%
    Echo You must set a Asset before Launch
    Exit /B
:missing_app
    Echo You dont have the app installed on your workstation, or could be you dont have correct version
    Exit /B
:missing_taskfolder
    echo ERROR: Unrecognised command "%1"
    exit /B

update info for user when creating new task


:: Start with bootstrap
CALL .\b2.exe install toolset=gcc --prefix=%SRC_DIR%\b2_for_mingw
cd .\tools\build
ECHO .\bootstrap.bat
CALL .\bootstrap.bat
IF errorlevel 1 exit 1
ECHO .\bootstrap.bat mingw
CALL .\bootstrap.bat mingw
IF errorlevel 1 exit 1
ECHO .\b2.exe install toolset=gcc --prefix=%SRC_DIR%\b2_for_mingw
CALL .\b2.exe install toolset=gcc --prefix=%SRC_DIR%\b2_for_mingw
ECHO cd %SRCDIR%
cd %SRCDIR%
set PATH=%PATH%;%SRCDIR%\b2_for_mingw\bin
ECHO b2 toolset=gcc --build-type=complete stage ^
     --build-dir=buildboost ^
     --prefix=%LIBRARY_PREFIX% ^
     address-model=%ARCH% ^
     variant=release ^
     threading=multi ^
     link=shared ^
     -j%CPU_COUNT% ^
     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
     --with-python
CALL b2 toolset=gcc --build-type=complete stage ^
     --build-dir=buildboost ^
     --prefix=%LIBRARY_PREFIX% ^
     address-model=%ARCH% ^
     variant=release ^
     threading=multi ^
     link=shared ^
     -j%CPU_COUNT% ^
     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
     --with-python

:: cd ..\..
:: dir .
:: CALL .\tools\build\b2.exe install toolset=gcc --prefix=%LIBRARY_PREFIX%
:: dir .
:: set PATH=%PATH%;%LIBRARY_BIN%
::
:: Build step
:: CALL b2 install ^
::     --build-dir=buildboost ^
::     --prefix=%LIBRARY_PREFIX% ^
::     toolset=gcc ^
::     address-model=%ARCH% ^
::     variant=release ^
::     threading=multi ^
::     link=shared ^
::     -j%CPU_COUNT% ^
::     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
::     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
::     --with-python
:: IF errorlevel 1 exit 1
::
:: :: Install fix-up for a non version-specific boost include
:: move %LIBRARY_INC%\boost-1_61\boost %LIBRARY_INC%
:: IF errorlevel 1 exit 1
::
:: Move dll's to LIBRARY_BIN
:: move %LIBRARY_LIB%\*vc%LIB_VER%-mt-1_61.dll "%LIBRARY_BIN%"
:: IF errorlevel 1 exit 1
:: Status API Training Shop Blog About

:: Start with bootstrap
type bld.bat
cd .\tools\build
ECHO .\bootstrap.bat
CALL .\bootstrap.bat
IF errorlevel 1 exit 1
ECHO .\bootstrap.bat mingw
CALL .\bootstrap.bat mingw
IF errorlevel 1 exit 1
type bld.bat
ECHO .\b2.exe install toolset=gcc --prefix=%SRC_DIR%\b2_for_mingw
CALL .\b2.exe install toolset=gcc --prefix=%SRC_DIR%\b2_for_mingw
ECHO cd %SRCDIR%
cd %SRCDIR%
set PATH=%PATH%;%SRCDIR%\b2_for_mingw\bin
ECHO b2 toolset=gcc --build-type=complete stage ^
     --build-dir=buildboost ^
     --prefix=%LIBRARY_PREFIX% ^
     address-model=%ARCH% ^
     variant=release ^
     threading=multi ^
     link=shared ^
     -j%CPU_COUNT% ^
     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
     --with-python
CALL b2 toolset=gcc --build-type=complete stage ^
     --build-dir=buildboost ^
     --prefix=%LIBRARY_PREFIX% ^
     address-model=%ARCH% ^
     variant=release ^
     threading=multi ^
     link=shared ^
     -j%CPU_COUNT% ^
     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
     --with-python

:: cd ..\..
:: dir .
:: CALL .\tools\build\b2.exe install toolset=gcc --prefix=%LIBRARY_PREFIX%
:: dir .
:: set PATH=%PATH%;%LIBRARY_BIN%
::
:: Build step
:: CALL b2 install ^
::     --build-dir=buildboost ^
::     --prefix=%LIBRARY_PREFIX% ^
::     toolset=gcc ^
::     address-model=%ARCH% ^
::     variant=release ^
::     threading=multi ^
::     link=shared ^
::     -j%CPU_COUNT% ^
::     -s ZLIB_INCLUDE="%LIBRARY_INC%" ^
::     -s ZLIB_LIBPATH="%LIBRARY_LIB%" ^
::     --with-python
:: IF errorlevel 1 exit 1
::
:: :: Install fix-up for a non version-specific boost include
:: move %LIBRARY_INC%\boost-1_61\boost %LIBRARY_INC%
:: IF errorlevel 1 exit 1
::
:: Move dll's to LIBRARY_BIN
:: move %LIBRARY_LIB%\*vc%LIB_VER%-mt-1_61.dll "%LIBRARY_BIN%"
:: IF errorlevel 1 exit 1
:: Status API Training Shop Blog About

Update bld.bat

Update bld.bat


@if not defined _echo @echo off
setlocal

:SetupArgs
:: Initialize the args that will be passed to cmake
set __nativeWindowsDir=%~dp0\Windows
set __artifactsDir=%~dp0..\..\artifacts
set __rootDir=%~dp0..\..
set __CMakeBinDir=""
set __IntermediatesDir=""
set __BuildArch=x64
set __appContainer=""
set __VCBuildArch=x86_amd64
set __BuildOS=Windows_NT
set CMAKE_BUILD_TYPE=Debug
set "__LinkArgs= "
set "__LinkLibraries= "

:Arg_Loop
:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing
if [%1] == [] goto :ToolsVersion
if /i [%1] == [Release]     ( set CMAKE_BUILD_TYPE=Release&&shift&goto Arg_Loop)
if /i [%1] == [Debug]       ( set CMAKE_BUILD_TYPE=Debug&&shift&goto Arg_Loop)

if /i [%1] == [AnyCPU]      ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [x86]         ( set __BuildArch=x86&&set __VCBuildArch=x86&&shift&goto Arg_Loop)
if /i [%1] == [arm]         ( set __BuildArch=arm&&set __VCBuildArch=x86_arm&&set __SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"&&shift&goto Arg_Loop)
if /i [%1] == [x64]         ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [amd64]       ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [arm64]       ( set __BuildArch=arm64&&set __VCBuildArch=x86_arm64&&set __SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"&&shift&goto Arg_Loop)
if /i [%1] == [wasm]        ( set __BuildArch=wasm&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)

if /i [%1] == [outconfig] ( set __outConfig=%2&&shift&&shift&goto Arg_Loop)

if /i [%1] == [WebAssembly] ( set __BuildOS=WebAssembly&&shift&goto Arg_Loop)

shift
goto :Arg_Loop

:ToolsVersion
:: Default to highest Visual Studio version available
::
:: For VS2017 and later, multiple instances can be installed on the same box SxS and VSxxxCOMNTOOLS is only set if the user
:: has launched the VS2017 or VS2019 Developer Command Prompt.
::
:: Following this logic, we will default to the VS2017 or VS2019 toolset if VS150COMNTOOLS or VS160COMMONTOOLS tools is
:: set, as this indicates the user is running from the VS2017 or VS2019 Developer Command Prompt and
:: is already configured to use that toolset. Otherwise, we will fail the script if no supported VS instance can be found.

if defined VisualStudioVersion goto :RunVCVars

set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist %_VSWHERE% (
  for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
)
if not exist "%_VSCOMNTOOLS%" goto :MissingVersion

call "%_VSCOMNTOOLS%\VsDevCmd.bat"

:RunVCVars
if "%VisualStudioVersion%"=="16.0" (
    goto :VS2019
) else if "%VisualStudioVersion%"=="15.0" (
    goto :VS2017
)

:MissingVersion
:: Can't find VS 2017, 2019
echo Error: Visual Studio 2017 or 2019 required
echo        Please see https://github.com/dotnet/corefx/tree/master/Documentation for build instructions.
exit /b 1

:VS2019
:: Setup vars for VS2019
set __VSVersion=vs2019
set __PlatformToolset=v142
:: Set the environment for the native build
call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
goto :SetupDirs

:VS2017
:: Setup vars for VS2017
set __VSVersion=vs2017
set __PlatformToolset=v141
:: Set the environment for the native build
call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
goto :SetupDirs

:SetupDirs
:: Setup to cmake the native components
echo Commencing build of native components
echo.

if [%__outConfig%] == [] set __outConfig=%__BuildOS%-%__BuildArch%-%CMAKE_BUILD_TYPE%

if %__CMakeBinDir% == "" (
    set "__CMakeBinDir=%__artifactsDir%\bin\native\%__outConfig%"
)
if %__IntermediatesDir% == "" (
    set "__IntermediatesDir=%__artifactsDir%\obj\native\%__outConfig%"
)
set "__CMakeBinDir=%__CMakeBinDir:\=/%"
set "__IntermediatesDir=%__IntermediatesDir:\=/%"

:: Check that the intermediate directory exists so we can place our cmake build tree there
if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%"
if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"

:: Write an empty Directory.Build.props/targets to ensure that msbuild doesn't pick up
:: the repo's root Directory.Build.props/targets.
set MSBUILD_EMPTY_PROJECT_CONTENT= ^
 ^^^<Project xmlns=^"http://schemas.microsoft.com/developer/msbuild/2003^"^^^> ^
 ^^^</Project^^^>
echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.props"
echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.targets"

if exist "%VSINSTALLDIR%DIA SDK" goto GenVSSolution
echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
Make sure you selected the correct dependencies when installing Visual Studio.
:: DIA SDK not included in Express editions
echo Visual Studio Express does not include the DIA SDK. ^
You need Visual Studio 2017 or 2019 (Community is free).
echo See: https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md#required-software
exit /b 1

:GenVSSolution
:: Regenerate the VS solution

pushd "%__IntermediatesDir%"
call "%__nativeWindowsDir%\gen-buildsys-win.bat" "%__nativeWindowsDir%" %__VSVersion% %__BuildArch%
popd

:CheckForProj
:: Check that the project created by Cmake exists
if exist "%__IntermediatesDir%\install.vcxproj" goto BuildNativeProj
if exist "%__IntermediatesDir%\Makefile" goto BuildNativeEmscripten
goto :Failure

:BuildNativeProj
:: Build the project created by Cmake
set __msbuildArgs=/p:Platform=%__BuildArch% /p:PlatformToolset="%__PlatformToolset%"

call msbuild "%__IntermediatesDir%\install.vcxproj" /t:rebuild /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
IF ERRORLEVEL 1 (
    goto :Failure
)

echo Done building Native components
exit /B 0

:BuildNativeEmscripten
pushd "%__IntermediatesDir%"
nmake install
popd
IF ERRORLEVEL 1 (
    goto :Failure
)

:: Copy results to native_aot since packaging expects a copy there too
mkdir "%__artifactsDir%\bin\native\%__outConfig%-aot"
copy "%__artifactsDir%\bin\native\%__outConfig%\*" "%__artifactsDir%\bin\native\%__outConfig%-aot"

exit /B 0

:Failure
:: Build failed
echo Failed to generate native component build project!
exit /b 1

@if not defined _echo @echo off
setlocal

:SetupArgs
:: Initialize the args that will be passed to cmake
set __nativeWindowsDir=%~dp0\Windows
set __artifactsDir=%~dp0..\..\artifacts
set __rootDir=%~dp0..\..
set __CMakeBinDir=""
set __IntermediatesDir=""
set __BuildArch=x64
set __BuildTarget="build"
set __appContainer=""
set __VCBuildArch=x86_amd64
set __BuildOS=Windows_NT
set CMAKE_BUILD_TYPE=Debug
set "__LinkArgs= "
set "__LinkLibraries= "

:Arg_Loop
:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing
if [%1] == [] goto :ToolsVersion
if /i [%1] == [Release]     ( set CMAKE_BUILD_TYPE=Release&&shift&goto Arg_Loop)
if /i [%1] == [Debug]       ( set CMAKE_BUILD_TYPE=Debug&&shift&goto Arg_Loop)

if /i [%1] == [AnyCPU]      ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [x86]         ( set __BuildArch=x86&&set __VCBuildArch=x86&&shift&goto Arg_Loop)
if /i [%1] == [arm]         ( set __BuildArch=arm&&set __VCBuildArch=x86_arm&&set __SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"&&shift&goto Arg_Loop)
if /i [%1] == [x64]         ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [amd64]       ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
if /i [%1] == [arm64]       ( set __BuildArch=arm64&&set __VCBuildArch=x86_arm64&&set __SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"&&shift&goto Arg_Loop)
if /i [%1] == [wasm]        ( set __BuildArch=wasm&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)

if /i [%1] == [outconfig] ( set __outConfig=%2&&shift&&shift&goto Arg_Loop)

if /i [%1] == [WebAssembly] ( set __BuildOS=WebAssembly&&shift&goto Arg_Loop)

if /i [%1] == [rebuild] ( set __BuildTarget=rebuild&&shift&goto Arg_Loop)

shift
goto :Arg_Loop

:ToolsVersion
:: Default to highest Visual Studio version available
::
:: For VS2017 and later, multiple instances can be installed on the same box SxS and VSxxxCOMNTOOLS is only set if the user
:: has launched the VS2017 or VS2019 Developer Command Prompt.
::
:: Following this logic, we will default to the VS2017 or VS2019 toolset if VS150COMNTOOLS or VS160COMMONTOOLS tools is
:: set, as this indicates the user is running from the VS2017 or VS2019 Developer Command Prompt and
:: is already configured to use that toolset. Otherwise, we will fail the script if no supported VS instance can be found.

if defined VisualStudioVersion goto :RunVCVars

set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist %_VSWHERE% (
  for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
)
if not exist "%_VSCOMNTOOLS%" goto :MissingVersion

call "%_VSCOMNTOOLS%\VsDevCmd.bat" -no_logo

:RunVCVars
if "%VisualStudioVersion%"=="16.0" (
    goto :VS2019
) else if "%VisualStudioVersion%"=="15.0" (
    goto :VS2017
)

:MissingVersion
:: Can't find VS 2017, 2019
echo Error: Visual Studio 2017 or 2019 required
echo        Please see https://github.com/dotnet/corefx/tree/master/Documentation for build instructions.
exit /b 1

:VS2019
:: Setup vars for VS2019
set __VSVersion=vs2019
set __PlatformToolset=v142
:: Set the environment for the native build
call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
goto :SetupDirs

:VS2017
:: Setup vars for VS2017
set __VSVersion=vs2017
set __PlatformToolset=v141
:: Set the environment for the native build
call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
goto :SetupDirs

:SetupDirs
:: Setup to cmake the native components
echo Commencing build of native components
echo.

if [%__outConfig%] == [] set __outConfig=%__BuildOS%-%__BuildArch%-%CMAKE_BUILD_TYPE%

if %__CMakeBinDir% == "" (
    set "__CMakeBinDir=%__artifactsDir%\bin\native\%__outConfig%"
)
if %__IntermediatesDir% == "" (
    set "__IntermediatesDir=%__artifactsDir%\obj\native\%__outConfig%"
)
set "__CMakeBinDir=%__CMakeBinDir:\=/%"
set "__IntermediatesDir=%__IntermediatesDir:\=/%"

:: Check that the intermediate directory exists so we can place our cmake build tree there
if "%__BuildTarget%"=="rebuild" if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%"
if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"

:: Write an empty Directory.Build.props/targets to ensure that msbuild doesn't pick up
:: the repo's root Directory.Build.props/targets.
set MSBUILD_EMPTY_PROJECT_CONTENT= ^
 ^^^<Project xmlns=^"http://schemas.microsoft.com/developer/msbuild/2003^"^^^> ^
 ^^^</Project^^^>
echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.props"
echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.targets"

if exist "%VSINSTALLDIR%DIA SDK" goto GenVSSolution
echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
Make sure you selected the correct dependencies when installing Visual Studio.
:: DIA SDK not included in Express editions
echo Visual Studio Express does not include the DIA SDK. ^
You need Visual Studio 2017 or 2019 (Community is free).
echo See: https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md#required-software
exit /b 1

:GenVSSolution
:: Regenerate the VS solution

pushd "%__IntermediatesDir%"
call "%__nativeWindowsDir%\gen-buildsys-win.bat" "%__nativeWindowsDir%" %__VSVersion% %__BuildArch%
popd

:CheckForProj
:: Check that the project created by Cmake exists
if exist "%__IntermediatesDir%\install.vcxproj" goto BuildNativeProj
if exist "%__IntermediatesDir%\Makefile" goto BuildNativeEmscripten
goto :Failure

:BuildNativeProj
:: Build the project created by Cmake
set __msbuildArgs=/p:Platform=%__BuildArch% /p:PlatformToolset="%__PlatformToolset%"

call msbuild "%__IntermediatesDir%\install.vcxproj" /t:%__BuildTarget% /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
IF ERRORLEVEL 1 (
    goto :Failure
)

echo Done building Native components
exit /B 0

:BuildNativeEmscripten
pushd "%__IntermediatesDir%"
nmake install
popd
IF ERRORLEVEL 1 (
    goto :Failure
)

:: Copy results to native_aot since packaging expects a copy there too
mkdir "%__artifactsDir%\bin\native\%__outConfig%-aot"
copy "%__artifactsDir%\bin\native\%__outConfig%\*" "%__artifactsDir%\bin\native\%__outConfig%-aot"

exit /B 0

:Failure
:: Build failed
echo Failed to generate native component build project!
exit /b 1

build by default, make rebuild optional (#40001)