Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I modify to only pre-process all C files in an entire project?

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.

like image 214
Pedro Bahamondes Walters Avatar asked Nov 08 '22 05:11

Pedro Bahamondes Walters


1 Answers

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.

like image 155
R Sahu Avatar answered Nov 15 '22 04:11

R Sahu