3

recently i'm working on some project with arm but no OS in it.
Now when i compile it, i must open keil.
but keil is weak in edit, so i'm considering to write a script to execute complier of keil, to build the project.
but i know little about keil, so i want to know if it is possble, for avoiding useless work.

thanks for any help.

sillypenguin
  • 129
  • 2
  • 7
  • 1
    What is wrong with calling [`armcc`](http://www.keil.com/support/man/docs/armcc/armcc_Cchbggjb.htm) directly? It should be named *armcc.exe* on windows and will probably be somewhere in your *Program Files* directory; but I haven't used Windows for about 15 years. – artless noise Dec 09 '13 at 20:06

2 Answers2

6

As mentioned by artless noise you can call armcc directly on the command line or integrate it into a build system like make, scons, etc . A good starting point is letting Keil uVision create a batch file for you: CREATING A PROJECT BATCH FILE. Another possibility is to call Keil from the command line with the project file as command line parameter with options to build the project.Keil uV4 command line. BTW I use this command line options also for automated unit testing in the simulator and for flash download.

Manu3l0us
  • 466
  • 3
  • 7
  • If you are using these scripts or have adapted it, it would be great to have your feedback. – Manu3l0us May 15 '14 at 11:41
  • Are these scripts still available somewhere? – fsteff Mar 15 '19 at 11:12
  • @fsteff it looks like the link is dead in the mean time, so probably not. But you should be able to recreate some wrapper functions to call the command line quite easily. – Manu3l0us Mar 15 '19 at 14:29
  • Thanks. I know, in fact I already did, but I were curious to see another solution. I've spotted sevreal errors in the limited documentation available from Keil, and I'm still discovering corner cases where my wrapper fails. Flex licences errors to mention one. – fsteff Mar 15 '19 at 18:25
  • 1
    @fsteff The Keil documentation for this is quite bad. I don't know if this has improved with later versions, I don't use it anymore. But I remember somehow that I have done the following to catch the Flex license errors: - Start Keil with the `-o ` option. - Wait for the process to end. - Check return code - If return code != 0, process according to return code (from doc) - If return code == 0, do a regex search in the logfile for FlexLM errors - Extract other interesting things from logfile using a regex – Manu3l0us Mar 18 '19 at 07:41
5

Edit 2021:

Revisited this answer as Kiel still hasn't improved their command-line tools.

  • Corrected a small typo in the script.
  • Fixed the link to the Kiel command line documentation.
  • Added the script to a Github gist, so it can easier be forked.

Original 2019 answer:

Here's my attempt at scripting the Keil uVision4 compiler.

Keil's Commandline interface basically hasn't changed since at least 2011, and it's very limited - especially for using the compiler on a build server.

Additionally, the Keil uVision4 compiler is very strange, not least when it comes to creating output, but in theory supports two methods - however sometimes none, only one, the other, or both output files are created. This batch script attempts to handle all of these situations.

Another issue is when the Flex license server is in use. This script allows you to define the number of times you want to retry a build and to set the interval between attempted builds. It also successfully recover if the license is suddenly withdrawn during a build.

If you have additions to this script, please post them here.

@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
fsteff
  • 543
  • 5
  • 19