2

最近我正在使用 arm 进行一些项目,但其中没有操作系统。
现在当我编译它时,我必须打开keil。
但是keil的编辑能力很弱,所以我正在考虑编写一个脚本来执行keil的编译器,以构建项目。
但我对keil知之甚少,所以我想知道它是否可能,以避免无用的工作。

谢谢你的帮助。

4

2 回答 2

6

正如 artless noise 所提到的,您可以直接在命令行上调用 armcc 或将其集成到构建系统中,如 make、scons 等。一个好的起点是让 Keil uVision 为您创建一个批处理文件:CREATING A PROJECT BATCH FILE。另一种可能性是使用项目文件作为命令行参数从命令行调用 Keil,并带有构建项目的选项。Keil uV4 命令行. 顺便说一句,我也将此命令行选项用于模拟器中的自动单元测试和闪存下载。

于 2013-12-11T20:20:43.607 回答
2

2021年编辑:

重新审视了这个答案,因为 Kiel 仍然没有改进他们的命令行工具。

  • 更正了脚本中的一个小错字。
  • 修复了 Kiel 命令行文档的链接。
  • 将脚本添加到Github gist中,因此可以更轻松地分叉。

2019年原始答案:

这是我尝试编写 Keil uVision4 编译器的脚本。

Keil 的命令行界面至少自 2011 年以来基本上没有改变,而且非常有限——尤其是在构建服务器上使用编译器时。

此外,Keil uVision4 编译器非常奇怪,尤其是在创建输出时,但理论上支持两种方法 - 但有时不创建、只创建一个、另一个或两个输出文件。此批处理脚本尝试处理所有这些情况。

另一个问题是使用 Flex 许可证服务器时。此脚本允许您定义要重试构建的次数并设置尝试构建之间的间隔。如果在构建过程中突然撤销许可证,它也会成功恢复。

如果您对此脚本有补充,请在此处发布。

@echo off
setlocal
:: KeiluVisionBuilder.cmd
:: Written by Flemming Steffensen, 2019.
:: Free for use and abuse by anyone.

:: ======================
:: Configuration
::     
set WaitForLicenseTimeout=60
set BuildAttemptsMax=10

set "ProjectFileName=bootloader.uvprojx"
set "ProjectPath=MyProject\bootloader\"
set "Compiler=C:\Keil_v5\UV4\UV4.exe"
set "OutFolder=OutputFolderDefinedIn_MyProject\"
::
:: ======================
:: Do not edit below this line
set BuildAttempt=0

pushd %ProjectPath%

:PerformBuild
echo:
echo:Performing Keil Build...

if exist build.log                del build.log
if exist %OutFolder%*.build_log.htm  del %OutFolder%*.build_log.htm

start /wait %Compiler% -j0 -b %ProjectFileName% -o build.log
set ReportedError=%ERRORLEVEL%

:: Scan build.log to determine if the license is locked.
find /c "Error: *** All Flex licenses are in use! ***" build.log  >nul
if %errorlevel% equ 0 (
    set /a BuildAttempt=%BuildAttempt% + 1 
    echo:Error: *** All Flex licenses are in use!
    if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
    echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
    waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
    goto PerformBuild
) 
:: Scan alternative build.log to determine if the license is locked.
find /c "Failed to check out a license" %OutFolder%*.build_log.htm >nul
if %errorlevel% equ 0 (
    set /a BuildAttempt=%BuildAttempt% + 1 
    echo:Error: Failed to check out a license
    if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
    echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
    waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
    goto PerformBuild
)
goto NoLicenseProblem


:NoLicenseAvailable
echo:Error: After %BuildAttempt% attempts, the Flex license still appear to be unavailable. Failing the build!
echo:
popd
exit /b 1

:NoLicenseProblem
:: Parse exit codes
set KnownErrors=0 1 2 3 11 12 13 15 20 41

echo:Kiel compiler exited with error code %ReportedError%

for %%a in (%KnownErrors%) do (
   if [%ReportedError%] equ [%%a] goto Error%ReportedError%
)
goto UnknownError

:Error0
   echo Compilation successful
   goto ExitButContinueJob

:Error1
   echo Warnings were found
   goto ExitButContinueJob

:Error2 
   echo Errors were found
   goto ExitCritical

:Error3
   echo Error 3 = Fatal Errors
   goto ExitCritical

:Error11
   echo Error 11 = Cannot open project file for writing
   goto ExitCritical

:Error12
   echo Error 12 = Device with given name in not found in database
   goto ExitCritical

:Error13
   echo Error 13 = Error writing project file
   goto ExitCritical

:Error15
   echo Error 15 = Error reading import XML file
   goto ExitCritical

:Error20
   echo Error 20 = Can not convert the project file.
   goto ExitCritical

:Error41
   echo Error 41 = Can not create the logfile requested using the -l switch.
   goto ExitCritical

:UnknownError
   echo Error %ReportedError% = Unknown error 
   goto ExitCritical

:ExitCritical
echo:
if [%ReportedError%] neq 0 exit /b %ReportedError% 

:ExitButContinueJob
echo:
popd
exit /b 0
于 2019-03-22T14:02:03.963 回答