I have a hierarchical build that use SConscript to declare build target recursively; so I don't know the targets beforehand. Each build will produce some extra files like *.err *.out that are not in targets. When I run scons -c, those files will be left uncleaned.
Is there a way to clean those file when I run scons -c?
One way to do this is to create you're own builder, then modify the emitter() function to include those possible extra targets.
In my own progject, I created my own builder around the SWIG tool because when it executes, I was saving the generated .py file in a different directory from the generate .cpp file. So the default scons -c wouldn't clean up the extra .py file.
So for your case you would do something like this:
def emitter(target, source, env):
# based on the target, create File nodes for the files that will
# get generated as a side effect.
target.append('%s.err' % target[0])
target.append('%s.out' % target[0])
return target, source
Here a link to my builder tool for SWIG: SwigGen.py
This adds a new builder to the environment object so I can do:
env.SwigGen('module_wrapper.cpp', 'module.i')
And when I do a scons -c the extra 'module.py' that is created will get cleaned also.