@echo off
@rem prebuild.cmd should be called as pre-build event like this:
@rem call ..\buildtools\prebuild.cmd $(PROJECTPATH)
@echo %0
@echo running in %CD%

set PROJECTPATH=%1
if "%PROJECTPATH%"=="" goto NeedPara
rem echo PROJECTPATH=%PROJECTPATH%
call :DelExt %1
echo RESULT=%RESULT%
call :DelExt %RESULT%
set PROJECTNAMEONLY=%RESULT%
echo PROJECTNAMEONLY=%PROJECTNAMEONLY%

set OUTPUTDIR=%~dp1

subwcrev .. %~dp0\templates\SVN_Version_template.ini SVN_Version.ini

pushd %OUTPUTDIR%

%~dp0\prepbuild.exe --incbuild --BuildDateTime={today} --readini=%PROJECTNAMEONLY% --updateini=%PROJECTNAMEONLY% --WriteRc=%PROJECTNAMEONLY% --InputManifest=%PROJECTNAMEONLY%.manifest.in --manifest=%PROJECTNAMEONLY% --updatemanifest --WriteManifestRc=%PROJECTNAMEONLY% --ignoremanifesterrors
brcc32 %PROJECTNAMEONLY%_Version.rc

if not exist %PROJECTNAMEONLY%_Manifest.rc goto nomanirc
if not exist %PROJECTNAMEONLY%.manifest goto nomani
brcc32 %PROJECTNAMEONLY%_Manifest.rc
goto donemani
:nomanirc
echo Hint: %PROJECTNAMEONLY%_Manifest.rc not found, skipping
goto donemani
:nomani
echo Hint: %PROJECTNAMEONLY%.manifest not found, skipping
goto donemani
:donemani

if not exist %PROJECTNAMEONLY%_Icon.rc goto noicon
%~dp0\rc %PROJECTNAMEONLY%_Icon.rc
goto doneicon
:noicon
echo Hint: %PROJECTNAMEONLY%_Icon.rc not found, skipping
:doneicon

popd

echo %0 exiting
goto :EOF

:NeedPara
echo Error: Needs the base filename of the executable as parameter
goto :EOF

:DelExt
setlocal
set RESULT=%~dpn1
endlocal & set RESULT=%RESULT%

