@echo off
rem __________________________________________________________________________
rem
rem Prepare before build. Expand the templates
rem Run this before first compile
rem Needs Win2K+
rem __________________________________________________________________________
rem
setlocal
pushd "%~dp0"

rem Delete old files to be generated
call :delfile StructList.inc
call :delfile CompressList.inc
call :delfile StructVer??????.pas
call :delfile CompressVer????.pas
call :delfile version.rc
call :delfile version.res
call :delfile innounp_observer.rc
call :delfile innounp_observer.res

rem Generate structure information units
for /f "tokens=1,2" %%a in (StructList) do (
  replace DEFVER %%a _EXTSUF_ "%%b" <StructTemplate.pas >StructVer%%a%%b.pas
  echo StructVer%%a%%b,>> StructList.inc
)
echo empty>>StructList.inc

rem Generate compression units
for /f %%a in (CompressList) do (
  replace DEFVER %%a <CompressTemplate.pas >CompressVer%%a.pas
  echo CompressVer%%a,>> CompressList.inc
)
echo empty>>CompressList.inc

rem Prepare version information
call :verinfo "version"
call :verinfo "innounp_observer"

rem Preparations complete
popd
goto :eof

:delfile
if exist "%~1" del "%~1"
goto :eof

:verinfo
call :delfile "%~1.rc"
call :delfile "%~1.res"
copy "%~1.rc.in" "%~1.rc" >nul
for /f "tokens=1,2 delims==;" %%a in (VersionInfo.inc) do (
   replace %%a %%b -- "%~1.rc"
)
brcc32 -fo"%~1.res" "%~1.rc" >nul
call :delfile "%~1.rc"
goto :eof
