Determine list of source files (*.[ch]) for a comp

2019-04-29 12:37发布

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.

1条回答
一夜七次
2楼-- · 2019-04-29 13:27

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)$'
查看更多
登录 后发表回答