Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for compiling automatically all ifdef / ifndef directives [closed]

My C project uses preprocessor directives to activate / deactivate some features. It's not unusual to find some of the less common configurations do not compile anymore due to a change made a few days ago within an #ifdef.

We use a script to compile the most common configurations, but I'm looking for a tool to ensure everything is compiled (testing is not a problem in our case, we just want to detect ASAP nothing stops compiling). Usually ifdefs / ifndefs are independent, so normally each module have to be compiled just twice (all symbols defined, all undefined). But sometimes the ifdefs are nested, so those modules have to be compiled more times.

Do you know of any tool to search all ifdef / ifndef (also nested ones) and gives how many times a module have to be compiled (with the set of preprocessor symbols to be defined in each one) to ensure every single source line of code is analyzed by the compiler?

like image 749
Santiago Avatar asked Jan 06 '10 11:01

Santiago


1 Answers

I am not aware of any tool for doing what you want to do. But looking at your problem i think all you need is a script that will compile the source with all possible combinations of the preprocessor symbols.

Like say if you have..

#ifdef A 
    CallFnA();
#ifdef B
    CallFnB();
#endif
    CallFnC();
#endif

You will have to trigger the build with the foll combinations

  1. A and B both defined
  2. A not defined and B defined ( will not make sense here, but required for entire module)
  3. A defined and B not defined
  4. A and B both not defined

Would love to see some script that will grep the source code and produce the combinations. Something like

find ./ -name '*.cpp' -exec egrep -h '^#ifdef' {} \; | awk '{ print $2}' | sort | uniq

With *.cpp replaced with whatever files you want to search.

like image 119
CodeRain Avatar answered Nov 15 '22 10:11

CodeRain