@echo off
rem This file is the script to set path for command tool.

set TL_PATH=%~dp0
set CYGWIN=nodosfilewarning
set TOOL_PATH=C:\Program Files (x86)\ChipON IDE\KungFu32\ChipONCC32
set TOOL_CHAIN=ccr1_issue
set MAKE=gmake

set WORK_PATH=d:\workspace32
set PROJECT_NAME=1233
set PROJECT_MODE=Release

set PATH=%TOOL_PATH%\%TOOL_CHAIN%\bin;%TOOL_PATH%\%TOOL_CHAIN%\kf32\bin;%TOOL_PATH%\common;%TOOL_PATH%\%TOOL_CHAIN%\lib\gcc\kf32\4.7.0;%TL_PATH%;%PATH%
rem cmd /K cd %CD% 

echo Init building ...

echo delete history hex file ...

if exist "%TL_PATH%%PROJECT_NAME%_UPDATE.hex" del "%TL_PATH%%PROJECT_NAME%_UPDATE.hex"

if exist "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.hex" del "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.hex"
if exist "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.elf" del "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.elf"
if exist "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.lst" del  "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.lst"
if exist "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.map" del  "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.map"

echo Init building ...
rem del /f output
rem mkdir  output
rem cd %CD%\output

cd /d "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%"
echo In Cut Upgrade file Please Wait a moment

rem  %MAKE% -k clean
%MAKE% -k all 1>build_log.txt  2>&1
type build_log.txt
rem %MAKE% -k all 




Setlocal Enabledelayedexpansion
set /a row=0

copy "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\build_log.txt" "%TL_PATH%build_log.txt"

rem for /f "tokens=*" %%i in (%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.hex) do (
rem set /a row+=1
rem if !row! GTR 292 echo %%i>> "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_NAME%_UPDATE.hex"
rem )
copy "%WORK_PATH%\%PROJECT_NAME%\%PROJECT_MODE%\%PROJECT_NAME%.hex" "%TL_PATH%%PROJECT_NAME%_UPDATE.hex"

echo Done.

pause
