cancel
Showing results for 
Search instead for 
Did you mean: 

Artifact Filename based on a Fw costant

MPast.1
Senior II

Hi All,

I need to obtain an artifact with the name present in some costant in "main.h".

In other words, my project is called "TestProject" and main.h I have these costants:

#define GUI_MAJOR_VER 		0		// Major
#define GUI_MINOR_VER 		1		// Minor
#define GUI_RELEASE_VER 	3		// Release

I would like to ahve a final executable named "TestProject v013.hex"

This means that every time I will change the #defines in main.h, output file will change automatically with a new numeration.

Does someone has some suggestion? or better, an example?

thanks in advance for your help.

 

 

11 REPLIES 11
Pavel A.
Evangelist III

Sure, you can do this in post-build action: Extract the version numbers from the .h file, then copy or rename the hex file.

Post-build action can be a "unix" shell script (sh is provided in the CubeIDE environment) so we don't have to ****  with ******* bat files.

HI @Pavel A. ,

thanks for suggestion but I should want a practical example to copy the various instructions.

you told about  ready scripts on CubeIDE: can you sueggest to me the folder?

Do I need to search for *.bat files? or on makefiles?

 

 thanks.

Apologies for been not clear enough. There are no ready examples of such scripts. I only said that we can use the normal "unix" shell tool, even on Windows. Which is easier than dreadful bat files.

The post-build command goes into the project settings:

PavelA_0-1743175133663.png

As you see, CubeIDE variables can be used in the commands, with ${...} syntax.

 

 

 

Ok, now I understood that I need to use post-build section on project settings.

My problem is that I don't know the syntax that I must insert on the command string.

For example How can extract values form main.h? and, How can I compose a new filename?

in other words, this is my first time for this problem and I need a reference guide/example to learn the various command to be autonomous.

Do you kwnow same link for the references?

 

Thanks

 

 

Hmm. Extracting version numbers from the .h file can be done with "awk" for example. Perhaps ask the AI ? ))

You could also just write a native command line application.

One that could take the file name as a command line parameter, use fopen(), fseek(), ftell(), fread() etc, like a C coder, do file manipulation and naming there.

I'm not sure you'd be able to fish out the source files, but the .BIN you could go search the binary for a tag where you embedded this data. Or perhaps parse the .ELF and pull things out of that as symbols, or pre-processor MACROs

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

To get the version as string: make a small C file, for example ver.c  ver.h  [edited - use .h suffix so that Eclipse won't add it to the project as a source file]

 

#include "main.h"

#define STRINGIFY(w) #w
#define MAKEVERS(x, y, z) STRINGIFY(x) "." STRINGIFY(y) "." STRINGIFY(z)

MAKEVERS(GUI_MAJOR_VER, GUI_MINOR_VER, GUI_RELEASE_VER)

Then preprocess this file and filter junk out:

gcc -E -P ver.h | sed '/^[ \t]*$/d; s/[ \t\"]//g'

 Here you get the version suffix string, like "0.1.3"

hi @Pavel A. ,

I create "version.c"

immagine.png

I inserted these in pre-build:

MPast1_0-1743196400357.png

And I obtain an error:

MPast1_1-1743196489733.png

But I'm in trouble with the compiler in use:

MPast1_2-1743196738436.png

 trying to put on post-build command

MPast1_1-1743198307944.png

I get this error:

MPast1_0-1743198254504.png

 

 

Hi @Pavel A. ,

 maybe I have done a little bit of confusion.

After reading for 100  times your original message, maybe I understood the right steps to do :

right click on "version.c" -> proprieties -->settings --> build Steps..

MPast1_0-1743199352073.png

In this way everything is compiling without any error, but Output file has still the project name.