One fairly common requirement in builds is to create some tool from source code, and then use that tool as part of the build to generate other files. This example shows how to do that, with thanks to Gary Oberbrunner. The tool to be generated is named mk_vds, and is built from the source file mk_vds.c. Then .txt input files are used by mk_vds to generate .vds files.
1 # SConstruct file 2 env=Environment() 3 4 # Create the mk_vds generator tool 5 mk_vds_tool = env.Program(target= 'mk_vds', source = 'mk_vds.c') 6 7 # This emitter will be used later by a Builder, and has an explcit dependency on the mk_vds tool 8 def mk_vds_emitter(target, source, env): 9 env.Depends(target, mk_vds_tool) 10 return (target, source) 11 12 # Create a builder (that uses the emitter) to build .vds files from .txt files 13 # The use of abspath is so that mk_vds's directory doesn't have to be added to the shell path. 14 bld = Builder(action = mk_vds.abspath + ' < $SOURCE > $TARGET', 15 emitter = mk_vds_emitter, 16 suffix = '.vds', src_suffix = '.txt') 17 18 # Add the new Builder to the list of builders 19 env['BUILDERS']['MK_VDS'] = bld 20 21 # Generate foo.vds from foo.txt using mk_vds 22 env.MK_VDS('foo.txt')
If you look at the resulting dependency tree you can see it works::
% scons --debug=tree foo.vds +-foo.vds +-foo.txt +-mk_vds +-mk_vds.o +-mk_vds.c