|
|
View previous topic :: View next topic |
Author |
Message |
MotoDan
Joined: 30 Dec 2011 Posts: 55
|
#EXPORT Directive with #DEFINE Filename |
Posted: Fri Oct 10, 2014 11:05 am |
|
|
Hello all,
I am trying to get the #EXPORT directive to work with portions of the filename to include the firmware version number like this:
Code: |
#define FW_VER-MAJOR 1
#define FW_VER-MINOR 0
#export (hex,file="FW1234-01_VER_" + FW_VER_MAJOR + "." + "FW_VER_MINOR" + ".HEX"
|
What I end up with is an output file called "FW1234-01_VER_". What I want is "FW1234-01_VER_1.0.HEX".
Thanks,
MotoDan |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Fri Oct 10, 2014 11:33 am |
|
|
I have not tried that, but in my experience, dots "." tend to be problematic (across multiple operating systems too). Try using an underscore "_" instead or another option would be to create a version string like "v1p3" should also work. Much less likely to run into problems - dots in a file name can have multiple "functions" including separating the file name from the file type and Murphy says that it will NOT be interpreted the way you intend it to.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat Oct 11, 2014 1:32 am |
|
|
It's more complex than this....
First, '+' is not the way to catenate.
Second, you have a problem, since you need to catenate without spaces (the default is to add spaces in front of numbers when catenated).
Third, you need to ensure that the macro expansion takes place at each level in the catenation. The default way of catenating without spaces, prevents macro expansion on the argument (this is covered in K&R), so you need to cheat and force an expansion before the catenation (this is the reason for 'xcat' in the code below).
The way to do this is to build the macro, a 'section at a time'.
So:
Code: |
#define FW_VER_MAJOR 1
#define FW_VER_MINOR 0
#define cat(x,y) x ##y
#define xcat(x,y) cat(x,y)
#define FN1 xcat(FW1234-01_VER_,FW_VER_MAJOR)
#define FN2 xcat(FN1,.)
#define FN3 xcat(FN2,FW_VER_MINOR)
#define EXPNAME xcat(FN3,.hex)
#export (hex,file=EXPNAME)
|
This forces each catenation, to expand macros, and remove spaces as you work, to give the required final text.
You can do the whole thing in a single expansion, with:
Code: |
#define FW_VER_MAJOR 1
#define FW_VER_MINOR 0
#define EXPNAME(a,b,c,d,e) a ##b ##c ##d ##e
#export (hex,file= EXPNAME(FW1234-01_VER_,FW_VER_MAJOR,.,FW_VER_MINOR,.hex))
|
Note also, the use of _, rather than - in the major and minor numbers, and the lack of spaces between the ##, and the value afterwards.
Note too, that this has to be a separate macro. Otherwise the macro expansion necessary for the version numbers, won't take place. Same reason for the xcat in the first version.
Last edited by Ttelmah on Mon Oct 13, 2014 12:58 am; edited 1 time in total |
|
|
MotoDan
Joined: 30 Dec 2011 Posts: 55
|
|
Posted: Sat Oct 11, 2014 10:09 am |
|
|
Ttelmah,
Thanks for the reply and excellent solution to my problem! I had no clue how to do this. Being able to build the hex file based on the FW version names allows me to change the revision level in one place. I use the Major.Minor rev names in my code and having the output filename generated automatically is very handy. This macro will go at the top of everything I write from now on!
Thanks again!
MotoDan |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|