Author Topic: Generating multiple .hex or .bin files with different #define in Keil  (Read 1803 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1902
  • Country: ca
Hi,
Suppose that I have a project in keil and I have written my code that certain options would be enabled or disabled based on the #define's in my Code, I want to know if it's possible to change the final output file name based on these switches so that  I can get ride of renaming different output file names by hand, is there any way to do that?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline funkathustra

  • Regular Contributor
  • *
  • Posts: 150
  • Country: us
Assuming you're talking about Keil C51 and not MDK or one of their other compiler toolchains, OH51 is the Keil utility that µVision invokes to create hex files from omf binaries the assembler spits out. Neither it nor the assembler has any ability to parse C preprocessor macros, so what you're asking is not possible.

Instead, consider defining multiple targets in µVision and define your build symbols in that target configuration. Then, you could create a batch file that builds each target
Code: [Select]
uv4.exe -b PROJECT.UVproj -t"blinky"
uv4.exe -b PROJECT.UVproj -t"blinky-no-rtc"
...
« Last Edit: June 25, 2018, 02:55:07 pm by funkathustra »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Does the toolchain provide a Make utility?  If so, just create Makefiles and define the options as compiler command line options (assuming it supports command line options).  You might also be able to use ANY Make program, there's nothing special about the GNU or Microsoft versions.  They're just Make...

See -Dname=def

http://www.keil.com/support/man/docs/armcc/armcc_chr1359124194749.htm

Basically, internal #defines are the default values unless overridden by -Dname.  In your source, you test to see if your name is already defined.  If not, you use the #define.  If it is, you use the current definition

in your source code:

#ifndef myvariable
   myvariable = 15
#endif

from the command line:

<compiler command> -Dmyvariable=32 ...

If the -D option is given, myvariable will have a value of 32 else 15

Value isn't the right word.  #defines are macro substitutions, not values.  Sometimes it is easier to think of them as values.

 

Offline photovore

  • Newbie
  • Posts: 9
  • Country: de
You can also do this entirely over the Gui.

First create the different Project Targets: Project->Manage->Project Items and create new targets unter the Project Targets submenu.

For each of these targets you can create a different output filename under Project->Option for Target->Output->Name of Executable.

Any conditional #defines can be set or disable under Project->Options for Target->C/C++ in the Define input field.  Each target can have its own unique defines.

Using a Batch Build or Batch Rebuild will build all of your project variants with one mouse click.
« Last Edit: June 26, 2018, 06:31:34 am by photovore »
 
The following users thanked this post: ali_asadzadeh

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1902
  • Country: ca
Thanks for your hints, I;m using MDK for ARM Cortex, So let me try to see what I can get ;)
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf