Reputation: 413
GCC's preprocessor-option "-H" prints the name of each header file used to STDERR. Is it possible to forward this output to a file, instead of letting it print to STDERR, and let GCC continue with the compilation in one step?
Something like:
gcc -H=file.h -c file.cc
I know I can use SHELL tricks to filter out this "-H"-output, but I would like to avoid that.
I just want to write the "-H"-output to a file instead of STDERR. I don't care if this output for some reason had to be mixed/interleaved with some other output, as long as the "-H"-output did not pollute STDERR and normal compilation/linking warnings/errors were still being printed to STDERR.
While GCC's developer-option "-save-temps" saves the entire preprocessor-output to a file, it does not save the "-H"-output with it.
Upvotes: 2
Views: 1471
Reputation: 240
g++ -save-temps -c file.cc
GCC's developer option "-save-temps
" does not rely on SHELL tricks and does not produce unwanted extra STDERR output. Instead, the GCC option produces two files (file.ii
and file.s
), where file.ii
contains the preprocessor output.
At a later stage, e.g., independent of the build system/procedure, this file.ii
can be transformed into something similar to what the "-H
"-output would have produced. In a csh SHELL, you can use the following command (or something similar) to achieve this transformation:
cat file.ii | grep '^# ' | awk '{a=$0;gsub(/"/,"",a);split(a,b);if(/\" 1/){split(c,d," ");c=d[1]". ";print c b[3]}if(/\" 2/){split(c,d,". ");c=d[1]" "}}' > file.h
Upvotes: 1
Reputation: 1539
Write a small wrapper around gcc to do what you want, instead of shell tricks.
GCC is open source software. If something is missing, feel free to add it.
Upvotes: 0