有没有一种方法可以构建arm项目,不需要keil,只需要一些脚本



最近我在做一些有arm但没有操作系统的项目。
现在,当我编译它时,我必须打开keil
但是keil在编辑方面很弱,所以我正在考虑写一个脚本来执行keil的编译器,以构建项目
但我对凯尔知之甚少,所以我想知道它是否是possble,因为它避免了无用的工作。

谢谢你的帮助。

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

编辑2021:

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

  • 更正了脚本中的一个小拼写错误
  • 修复了基尔命令行文档的链接
  • 将脚本添加到Github要旨中,因此可以更容易地分叉

2019年的原始答案:

以下是我为Keil uVision4编译器编写脚本的尝试。

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

此外,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=MyProjectbootloader"
set "Compiler=C:Keil_v5UV4UV4.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

相关内容

最新更新