@echo off
REM starts build.py with my local setup 
SETLOCAL

build.py --force --inc-shib --with-unil ..\..\libs\php_classes\unil --with-udb ..\..\libs\microdb --echo-vername build.ver %*

if %ERRORLEVEL%==0 goto ok
goto failed


:ok
REM in a bash shell this would be
REM cp pianos-`cat build.ver`.tar.gz pianos-latest.tar.gz
REM but this is a dos shell where backticks are not available. This can be worked
REM around (see http://stackoverflow.com/questions/2768608/batch-equivalent-of-bash-backticks)
if not exist build.ver goto failed2
set /p BUILT_VERSION=<build.ver
if "%BUILT_VERSION%"=="" goto failed3

set OUTPUT_FILENAME=pianos-%BUILT_VERSION%.tar.gz
set RELEASE_FILENAME=pianos-latest.tar.gz

echo.
echo Created %OUTPUT_FILENAME%
echo   Updating %RELEASE_FILENAME%
copy %OUTPUT_FILENAME% %RELEASE_FILENAME%

del build.ver

goto end

:failed
echo.
echo Build failed. (if it's a dependency resolution problem, make sure the resolvers are good, e.g. local web server running)
goto end


:failed3
echo like fail2, but even worse
:failed2
echo BUILT_VERSION=%BUILT_VERSION%
echo OUTPUT_FILENAME=%OUTPUT_FILENAME%
echo RELEASE_FILENAME=%RELEASE_FILENAME%
goto end


:end
ENDLOCAL
