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 1 and 2
Revision 1 as of 2007-02-26 01:03:17
Size: 2113
Editor: TimBlechmann
Comment: added CombineBuilder
Revision 2 as of 2008-03-12 02:46:57
Size: 2113
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

i'm using this simple builder to generate c++ source files, that include other source files. beware: it may result in problems, if the code of the source files is expected to be located in different compile units! however, i'm using it successfully to reduce compile times for programs with large header files ...

   1 # $Id: combiner.py 545 2007-02-26 00:57:33Z tim $
   2 #
   3 # SCons builder to combine c++ source files
   4 # Copyright (C) 2007 Tim Blechmann
   5 #
   6 # This program is free software; you can redistribute it and/or modify
   7 # it under the terms of the GNU General Public License as published by
   8 # the Free Software Foundation; either version 2 of the License, or
   9 # (at your option) any later version.
  10 #
  11 # This program is distributed in the hope that it will be useful,
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 # GNU General Public License for more details.
  15 #
  16 # You should have received a copy of the GNU General Public License
  17 # along with this program; see the file COPYING.  If not, write to
  18 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19 # Boston, MA 02111-1307, USA.
  20 
  21 # $Revision: 545 $
  22 # $LastChangedRevision: 545 $
  23 # $LastChangedDate: 2007-02-26 01:57:33 +0100 (Mon, 26 Feb 2007) $
  24 # $LastChangedBy: tim $
  25 
  26 import SCons.Action
  27 import SCons.Builder
  28 
  29 def build_it(target, source, env):
  30     """generate a file, that's including all sources"""
  31 
  32     out = ""
  33     for src in source:
  34         out += "#include \"%s\"\n" % src.abspath
  35 
  36     open(str(target[0]), 'w').write(out)
  37     return 0
  38 
  39 def generate(env):
  40     env.Append(BUILDERS = {
  41         'Combine': env.Builder(
  42         action = SCons.Action.Action(build_it, "generating '$TARGET'"),
  43         target_factory = env.fs.File,
  44         )
  45         })
  46 
  47 def exists(env):
  48     return True

to use it from the sconscript:

   1 env = Environment()
   2 env.Tool('combiner', toolpath='.')
   3 combined = env.Combine("build.cpp", ["a.cpp", "b.cpp"])
   4 prog = env.Program("prog", combined)

CombineBuilder (last edited 2008-03-12 02:46:57 by localhost)