Question

Is there a utility that can strip out say #ifdef PRO_VERSION ... #endif code?

Please don't tell me about the Visual Studio compiler flag or XCode's view post-processed source. I can't automate it conveniently like, say, a console application.

What I am looking to do here is find an existing utility if it exists. If not ... I guess I'll have to reinvent the wheel.

Was it helpful?

Solution

unifdef might be what you're looking for.

From its manual:

The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines. A directive is only processed if the symbols specified on the command line are sufficient to allow unifdef to get a definite value for its control expression. If the result is false, the directive and the following lines under its control are removed. If the result is true, only the directive is removed. An #ifdef or #ifndef directive is passed through unchanged if its controlling symbol is not specified on the command line. Any #if or #elif control expression that has an unknown value or that unifdef cannot parse is passed through unchanged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top