Electronics > Microcontrollers

Makefile change output hex file name from header file #define

(1/5) > >>

hal9001:
I use a #define inside a header file for firmware version. Can the makefile append the version number from the #define to the name of the hex file? Im using Atmel Studio.

mfro:

--- Quote from: hal9001 on May 15, 2024, 09:02:16 am ---I use a #define inside a header file for firmware version. Can the makefile append the version number from the #define to the name of the hex file? Im using Atmel Studio.

--- End quote ---

The Makefile itself can't - but with a little help from the C preprocessor cpp, it's possible. Let's assume you have your version number in a file called version.h like so:

--- Code: ---#define VERSION "1.0.0-beta"

--- End code ---

you can assign that to a Makefile variable using the C preprocessor:


--- Code: ---VERSION = $(shell echo "#include \"version.h\"\nVERSION" | $(CPP) - -P -o -)

--- End code ---

The version string can than be appended to any name in the Makefile.


(assuming you are using Linux or another *X-based OS like Mac OS. If you are using Windows, I'm afraid you need to ask somebody else)

hal9001:

--- Quote from: mfro on May 15, 2024, 09:39:05 am ---
--- Quote from: hal9001 on May 15, 2024, 09:02:16 am ---I use a #define inside a header file for firmware version. Can the makefile append the version number from the #define to the name of the hex file? Im using Atmel Studio.

--- End quote ---

The Makefile itself can't - but with a little help from the C preprocessor cpp, it's possible. Let's assume you have your version number in a file called version.h like so:

--- Code: ---#define VERSION "1.0.0-beta"

--- End code ---

you can assign that to a Makefile variable using the C preprocessor:


--- Code: ---VERSION = $(shell echo "#include \"version.h\"\nVERSION" | $(CPP) - -P -o -)

--- End code ---

The version string can than be appended to any name in the Makefile.


(assuming you are using Linux or another *X-based OS like Mac OS. If you are using Windows, I'm afraid you need to ask somebody else)

--- End quote ---
Cheers! Im using Windows. Maybe power shell in windows can work the same way?

mfro:

--- Quote from: hal9001 on May 15, 2024, 09:53:48 am ---Cheers! Im using Windows. Maybe power shell in windows can work the same way?

--- End quote ---

That's entirely possible (maybe even CMD might do it), but I can't assist with that as I didn't touch any Windows for years.

tellurium:
You might try this

version.h:

--- Code: ---#define VERSION "1.2.3"

--- End code ---


--- Code: ---VERSION = $(shell echo VERSION | gcc -P -E -imacros version.h -)

--- End code ---

However the generated variable will be double-quoted , which is probably not what you want. But hey, there are at least two solutions for that:
1. Find how to dequote a string - a quick google search suggests it is doable, or
2. Stop using Windows, and start using something more developer-friendly

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod