Q:

How to remove private code before publishing?

We have a medium-sized C codebase that provides an API for using our hardware products. We provide the source for this API so that customers can compile it into whatever environment they choose. It's important that the source is legible and easily navigated as many people do just that. We don't obfuscate it in any way.
In our code we have a number of functions and sections that are for internal testing only, stuff like wrapper methods, low level checks, etc. None of it is particularly interesting nor harmful in any respect but we don't really want people using them or getting confused about what they are. This has happened numerous times before despite having warnings in the code about using them.
Is there any tool or method by which we can filter out these sections before publishing the source?
Right now we use a custom method with comments, however it's hard to parse and maintain:
/* $if : INTERNAL : some comment */
debug_code();
/* $endif : INTERNAL */

I've looked at using #ifdef and the preprocessor but there doesn't seem to be a way to preprocess specific defines/macros and not the whole file at once. I would only want the specific blocks preprocessed (and therefore removed) and not all the defines and in the code.
EDIT: From my comment below, the stuff we would like to remove from the published code should not be located in separate files. Like wrappers, we prefer to keep those next to the functions they wrap to make it easy to find. Other times we have detailed comments about internal implementation that we want in the code for our reference but don't want others seeing it.

A:

One tool I've found useful for applications like this is coan, which is still actively maintained (although apparently it currently doesn't compile cleanly on Mac OS X, if that is a concern).
Coan is designed for code analysis and it can perform quite a few tasks which you probably don't need. As long as you don't explicitly #define the preprocessor macros which surround the code to be removed, you should be able to just -Define or -Undefine as appropriate. 
Coan wants to keep the code consistent, and can evaluate preprocessor macros so as to correctly evaluate and possibly eliminate preprocessor conditionals. Even if you don't ask it to do the evaluation, it will normally interpret and simplify #ifdef blocks if the definition is visible. Even that behaviour can be altered with the --no-transients option, but it will emit a warning.

