How to add preprocessor defined symbol in makefile?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add preprocessor defined symbol in makefile?

Jump to solution
2,958 Views
David0406
Contributor II

 

Hi, I am using S32DS IDE for development.

Would it be possible to add preprocessor defined symbol using custom build steps with auto-generated makefile?

The value of defined symbol is not fixed.

I've tried to create makefile.defs, and add the following content in it. It seems not to work.

thanks in advance!

David0406_3-1680764599832.png

TOPREPROCESS_SRCS is declared in source.mk, which would be included in the auto-generated makefile

David0406_5-1680765357900.png

David0406_6-1680765608974.png

 

 

0 Kudos
Reply
1 Solution
2,846 Views
David0406
Contributor II

 

Hi,

thanks for the reply and discussion thread you provided

 

I give up adding git info in preprocessor defined symbol way.

I've followed the solution mentioned in the below image by first executing a script to get git info, then

writing it into the header file which would be included in the main.c in Pre-build steps.

After flashing binaries, it works!

 

thanks for providing solutions  : )

David0406_0-1681293444172.png

 

View solution in original post

0 Kudos
Reply
7 Replies
2,945 Views
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Could you help us elaborate more on this manner? We are not understanding the overall request.

We understand that you want to generate a preprocessor defined symbol, which can be done by looking into:

"Properties > C/C++ Build > Setting > Standard S32DS C Compiler > Preprocessor"

Of your project. In there, you can add new defined symbols for your project.

Please, let us know.

0 Kudos
Reply
2,935 Views
David0406
Contributor II

 

Hi,

Thanks for the reply. 

I would like to write a script to get git commit hash first and make it a preprocessor defined symbol added to my code for identification.

The solution you provide works, but the commit hash varies for each commit. Therefore, the defined symbol might have to be modified manually for each commit. 

Thanks in advance.

0 Kudos
Reply
2,892 Views
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

There is the possibility of adding a "Preprocessor Macros File" to your project, in which you could add new macros. Below will be a picture of where to add this kind of file:

DanielAguirre_1-1681163937440.png

 

For our test, before trying to add the file, we created a new header file on the project by the name "MACROS.h" in which we have the following information:

#ifndef MACROS_H_
#define MACROS_H_

#define TEST 149

#endif /* MACROS_H_ */

We then added the "Preprocessor Macros File" as shown on the image above and created the #IF conditional on our project. Below the results:

If met:

DanielAguirre_2-1681164027367.png

If not met:

DanielAguirre_3-1681164044718.png

Please, let us know.

2,877 Views
David0406
Contributor II

 

Hi,

Thanks for the reply.

I've follow the solution you provided to test it on one of NXP Uart example code, but it seems not to work on the project.

May I check the testing process with you? 

process

1.create MACRO.h and add it to ${ProjDirPath}/ with the same content 

David0406_0-1681206201832.png

2.add it to CDT_User_Setting_Entries

David0406_2-1681206522080.png

 

3.add #IF conditional in main.c

David0406_4-1681206785474.png

David0406_1-1681206353858.png

the #if block did being shaded if changing the compared value with TEST to 150

result

the warning messge was shown in the build log 

David0406_5-1681207359898.png

flash binaries and monitor with uart terminal software

David0406_6-1681207501624.png

thanks in advance!

 

 

0 Kudos
Reply
2,858 Views
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Thanks for your feedback. It seems that as you are saying, the GUI shows as if the Macro has been detected, but at compilation it does not take it into account.

Digging further into this topic, seems that S32DS has a bug regarding this same topic. A thread below mentioning this:

Solved: Macros to access filename - NXP Community

I've tried with S32DS v3.5 (since it is the newer version) but I cannot get it working. We apologize.

On the above-mentioned thread, there is a possibility of adding the flag directly into the command line pattern, but we don't know if it is what you are looking for.

Please, let us know.

2,847 Views
David0406
Contributor II

 

Hi,

thanks for the reply and discussion thread you provided

 

I give up adding git info in preprocessor defined symbol way.

I've followed the solution mentioned in the below image by first executing a script to get git info, then

writing it into the header file which would be included in the main.c in Pre-build steps.

After flashing binaries, it works!

 

thanks for providing solutions  : )

David0406_0-1681293444172.png

 

0 Kudos
Reply
2,832 Views
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Thanks for your feedback. Good to know you found a workaround.

Please, let us know if there is anything else we can help you with.