问题
I would like to condense our linux driver code in to only the code that runs on the current kernel. It has parts that are ignored by if statements all the way back to kernele 2.4.x
Have you ever heard of a way to compile the code to an output which will be the working code with out all the stuff ignored by the c compiler if else statements?
I am wondering if we can run make something or gcc something that will simply result in all the code that is used for that build.
So like if I had this .c file below, then after running the make command I should have just the code I need for the newest kernel.
example.c
static somefunction .... {
avar = 0;
#if (linux_ver >= 2.6.31)
some newer code
#elseif (linux_ver >= 2.4.24)
some older code
#else
original code
#endif
}
after extracting / condensing, example.c would simply read as below
static somefunction .... {
avar = 0;
some newer code
}
回答1:
The tool you are after is sunifdef
or (more recent) coan
.
See also: Is there a C pre-processor which eliminates #ifdef blocks based on values defined or undefined?
回答2:
That's what the preprocessor directives do already. Try running the code through gcc -E
(but prepare for a lot of output, as all #include
s will be inlined).
来源:https://stackoverflow.com/questions/9271984/can-i-export-the-used-code-from-a-c-program-with-many-compiler-flags