keil 脚本编译

@echo off

REM  protocol bin infomation
set "protocol=PROFINET"
set "firmwarepath=.\Firmware"
set "hexfile=.\Firmware\Master.hex"

REM keil path
set UV=%KEIL_PATH%
set UV_PRO_FILE="uvprojx"
set UV_PRO_DIR=%cd% 
set "search_dir=.\Project"
set "search_ext=uvprojx"

REM Script compile firmwar folder path 
set "foldername=.\Firmware"
if not exist "%foldername%" (
    mkdir "%foldername%"
)

REM keil compile firmwar path
set "HEX_FILE=.\Project\Objects\Master.hex"
set "BIN_FILE=.\Project\Objects\Master.bin"

if exist %HEX_FILE%  del /f   %HEX_FILE%
if exist %BIN_FILE%  del /f   %BIN_FILE%
REM

call:func_get_sys_datetime 

REM get firmware version information
set "firmfile=.\User\firmver.h"  
set "line=3"
set "column=3" 

call:func_find_str_xline_ycolumn %firmfile% %line% %column%

set "protocolinfo=%protocol% fireware compile start,waiting......."
set "versinfoinfo=        %year%-%month%-%day% %hour%:%minute%:%second% %content:~1,5%"
echo *******************************************************************************
echo * 
echo *                     %versinfoinfo%
echo *                                                         
echo *                     %protocolinfo% 
echo *                                                                                       
echo *******************************************************************************

setlocal enabledelayedexpansion

REM find keil project compile files and output build log to build_log.txt
set "logfile=build_log.txt"  
set "name=!logfile:~0,-4!"  
set "extension=!logfile:~-4!"
set "logname=!name!_!datetime:~0,14!!extension!"

REM set "files="
call:func_find_files    %search_dir% %search_ext%
echo > %logfile%    REM keil compile log > build_log.txt

call:func_keil_compile  %files%  %cd%\%logfile%

type %logfile%

ren "%logfile%"    %logname%  
REM   

if exist %HEX_FILE% (

	if exist .\Firmware\*.txt   del /f .\Firmware\*.txt
	if exist .\Firmware\*.hex   del /f .\Firmware\*.hex
	if exist .\Firmware\*.xml   del /f .\Firmware\*.xml

	copy %HEX_FILE%    %firmwarepath%
	copy .\"%logname%" %firmwarepath%
	del /f .\"%logname%"
	
	:set "hexfile=.\Bin\Master.hex"
	set "hexname=!hexfile:~0,-4!"  
	set "hexextension=!hexfile:~-4!"
	
	ren "%hexfile%" "%protocol%_%content:~1,5%_!datetime:~0,14!!hexextension!" 
	
	call GSDML_file_generate.bat  %datetime%

	"C:\Program Files\7-Zip\7z.exe" a  .\Firmware\"%protocol%_%content:~1,5%_!datetime:~0,14!".zip .\Firmware\*.txt .\Firmware\*.xml .\Firmware\*.hex
	
	del /f .\Firmware\*.txt
	del /f .\Firmware\*.hex
	del /f .\Firmware\*.xml	
	
	echo *******************************************************************************  
	echo *                                  compile finish 
	echo *******************************************************************************

	color    20
	timeout /t 5
	
) else (

	echo *******************************************************************************  
	echo *                                  compile fail
	echo *******************************************************************************
	
	color    40
	timeout /t 20
)

endlocal


REM %UV% -j0 -r %files% -o %cd%\%logfile%            (%1 == compilefilepath, %2 == logfile) 
:func_keil_compile  
%UV%  -j0  -r  %1  -o  %2
goto:eof

:func_get_sys_datetime
for /f %%x in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do set "datetime=%%x"

set "year=%datetime:~0,4%"
set "month=%datetime:~4,2%"
set "day=%datetime:~6,2%"
set "hour=%datetime:~8,2%"
set "minute=%datetime:~10,2%"
set "second=%datetime:~12,2%"

goto:eof

:func_find_files
REM for /r "%search_dir%" %%F in (*.%search_ext%) do (
REM    set files= "%%~dpF%%~nxF"
REM )

for /r %1 %%F in (*.%2) do (
    set files= "%%~dpF%%~nxF"
)

echo file path = %files%

goto:eof


:func_find_str_xline_ycolumn
REM get firmware version information
REM set "filename=.\User\firmver.h"  
REM set "lineNumber=3"
REM set "columnNumber=3" 

REM output every line content
REM for /f "delims=" %%a in ('type "%filename%"') do (
REM    set "line=%%a"
REM    echo !line!  
REM )

REM output lineNumber content
REM for /f "usebackq skip=%lineNumber% delims=" %%a in ("%filename%") do (
REM    set "line=%%a"
REM    set /a count+=1
REM    if !count! == 1 (
REM        echo !line!  
REM    )
REM )

REM  output lineNumber columnNumber content
REM  set /a count=0
REM  for /f "usebackq tokens=%columnNumber% delims= " %%a in (`more +%lineNumber% "%filename%"`) do (
REM  set "content=%%a"
REM  set /a count+=1
REM  if !count! == 1 (
REM    REM echo !content!  
REM  )
REM )

REM output lineNumber columnNumber content
 set /a count=0
 for /f "usebackq tokens=%3 delims= " %%a in (`more +%2 %1`) do (
    set "content=%%a"
    set /a count+=1
    if !count! == 1 (
    REM echo !content!  
  )
)
REM 

goto:eof

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shuiyunjian1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值