Reputation: 11
I have to preprocess a header, during this I want to only process the header for #ifdef, #if defined sections, other sections like Macro expansion and #include sections should not be expanded or checked. how to get this? I need to pass this output file to another software like cmock to create a mock file and then use it for compilation. but the problem I am facing is if I use gcc -E it generates a file where all #includes are expanded, Macros expanded along with #if defines. any help would be appreciated
for example:
#include <stdint.h> //i don't want to pre-process this line
#if defined (__MACRO_A__) //i want to pre-process this line
void funcA(void);
#else
void funcB(void);
#endif
I want the output file to have only funcB prototype. I have not defined MACRO_A, so if I preprocess header only funcB is getting included, but all the #includes are getting expanded, which I don't want.
Upvotes: 1
Views: 518
Reputation: 141155
but all the #includes are getting expanded, which I don't want.
So remove them from the file.
grep -v '#include' inputfile.c | gcc -E -xc -
The regex above can possibly be better.
Upvotes: 1