Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine list of source files (*.[ch]) for a complex build with scons

Suppose you have a complex source tree for a C project, lots of directories with lots of files. The scons build supports multiple targets (i386, sparc, powerpc) and multiple variants (debug, release). There's an sconstruct at the root (referencing various sconscripts) that does the right thing for all of these, when called with arguments specifying target and variant, e.g. scons target=i386 variant=release.

Is there an easy way to determine which source files (*.c and *.h) each of these builds will use (they are all slightly different)? My theory is that scons needs to compute this file set anyway to know which files to compile and when to recompile. Can it provide this information?

What I do not want to do:

  • Log a verbose build and postprocess it (probably wouldn't tell *.h files anyway)
  • find . -name '*.[ch]' also prints unwanted files for unit testing and other cruft and is not target specific

Ideally I would like to do scons target=i386 variant=release printfileset and see the proper list of *.[ch] files. This list could then serve as input for further source file munging tools like doxygen.

like image 957
Jens Avatar asked Sep 02 '11 12:09

Jens


1 Answers

There are a few questions all squashed together here:

  • You can prevent SCons from running the compiler using the --dry-run flag
  • You can get a dependency tree from SCons by using --debug=tree, or --tree=all flags, depending on which version you are running
  • Given a list of files, one per line, you can use grep to filter out only the things that are interesting for you.

When you put all of that together you end up with something like:

scons target=i386 variant=release printfileset -n --tree=all | egrep -i '^ .*\.(c|h|cpp|cxx|hpp|inl)$'
like image 81
Andrew Walker Avatar answered Oct 02 '22 18:10

Andrew Walker