Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.
Differences between revisions 19 and 20
Revision 19 as of 2005-05-25 19:59:26
Size: 1416
Editor: 204
Comment: Replaced XML entities with real characters
Revision 20 as of 2008-03-12 02:47:09
Size: 1416
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

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()
   4 # Create the mk_vds generator tool
   5 mk_vds_tool = env.Program(target= 'mk_vds', source = 'mk_vds.c')
   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)
  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[0].abspath + ' < $SOURCE > $TARGET',
  15               emitter = mk_vds_emitter,
  16               suffix = '.vds', src_suffix = '.txt')
  18 # Add the new Builder to the list of builders
  19 env['BUILDERS']['MK_VDS'] = bld
  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

UsingCodeGenerators (last edited 2008-03-12 02:47:09 by localhost)