@echo off

echo %date% %time%

set BUILD_FD=..\..\G13-BCM\BCM21331\tool\all\UART_Downloader
set BOOT_FD=..\..\G13-BCM\BCM21331\baseband\boot
set RETURN_PATH=..\..\..\..\..\ShpTarget\tools

call ..\rvct22.bat

copy %BOOT_FD%\boot1a.img %BUILD_FD%
copy %BOOT_FD%\boot1b.img %BUILD_FD%
copy %BOOT_FD%\boot2.img %BUILD_FD%

pushd %BUILD_FD%

del   .\Release\*.* /q
rmdir .\Release

call A_bootloader1a.bat
call A_bootloader1b.bat
call A_bootloader2.bat

perl -pi -e "s/StubSize/hBootloader1aSize/g" ./bootloader1a.h 
perl -pi -e "s/Stub/hBootloader1a/g" ./bootloader1a.h 
perl -pi -e "s/StubSize/hBootloader1bSize/g" ./bootloader1b.h 
perl -pi -e "s/Stub/hBootloader1b/g" ./bootloader1b.h 
perl -pi -e "s/StubSize/hBootloader2Size/g" ./bootloader2.h 
perl -pi -e "s/Stub/hBootloader2/g" ./bootloader2.h

del bootloader1a.h.bak
del bootloader1b.h.bak
del bootloader2.h.bak

call VCVARS32.BAT

NMAKE /f "cabrio_downloaderv01.mak" 

copy	.\Release\UART_Downloader.exe %RETURN_PATH%

pushd %RETURN_PATH%

if "%1"=="" goto end
rename UART_Downloader.exe %1.exe
echo "rename :: UART_Downloader.exe => %1.exe"

echo %date% %time%

:end