To solve various problems that I'm facing for a tool I'm developing, I'd like to be able to generate pre-processed versions of all C files ( *.c
) in a given project, especially to remove macros but also for some other details. I know that preprocessing can be done with either gcc -E
or cpp
for a single file, but when complicated dependencies and includes appear, as in huge projects, individual preprocessing is useless or completely unpractical.
Now, of course, those projects also normally will have specifications to compile the entire project also in an efficient way, such as a Makefile or a configure file. Thus, my question is: what exactly do I need to be modifying in there (or at least look for) to produce only the pre-processed C files for each C file in the project instead of making the project?
You can assume it's an open source project with C files, but (uninteresting) other files written in other programming languages could be there as well.
Here's a simple make
rule to generate pre-processed output files from .cpp
files.
%.i: %.cpp
g++ -E -o $@ $?
If you have file.cpp
, you can generate file.i
by using:
make file.i
You can setup a similar rule for generating .i
files from .c
files.
%.i: %.c
gcc -E -o $@ $?
If the .cpp
file or the .c
file gets modified the .i
files can be regenerated by running make
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With