Lumiera  0.pre.03
»edit your freedom«
BuilderGCH.py
1 # coding: utf-8
2 
5 
6 # Copyright (C) scons.org/wiki/GchBuilder
7 # 2006, Tim Blechmann
8 # 2008, Hermann Vosseler <Ichthyostega@web.de>
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2 of
13 # the License, or (at your option) any later version.
14 
15 
16 # history: 8/2008 adapted for Lumiera build system
17 # changed to accept a list of precompiled header defs
18 
19 
20 from types import ListType
21 
22 import SCons.Action
23 import SCons.Builder
24 import SCons.Scanner.C
25 import SCons.Util
26 import SCons.Script
27 
28 SCons.Script.EnsureSConsVersion(0,96,92)
29 
30 GchAction = SCons.Action.Action('$GCHCOM', '$GCHCOMSTR')
31 GchShAction = SCons.Action.Action('$GCHSHCOM', '$GCHSHCOMSTR')
32 
33 def gen_suffix(env, sources):
34  return sources[0].get_suffix() + env['GCHSUFFIX']
35 
36 
37 GchShBuilder = SCons.Builder.Builder(action = GchShAction,
38  source_scanner = SCons.Scanner.C.CScanner(),
39  suffix = gen_suffix)
40 
41 GchBuilder = SCons.Builder.Builder(action = GchAction,
42  source_scanner = SCons.Scanner.C.CScanner(),
43  suffix = gen_suffix)
44 
45 def setup_dependency(target,source,env, key):
46  scanner = SCons.Scanner.C.CScanner()
47  path = scanner.path(env)
48  deps = scanner(source[0], env, path)
49 
50  if env.has_key(key) and env[key]:
51  for header in env[key]:
52  header_path = header.path.strip('.gch')
53  if header_path in [x.path for x in deps]:
54  print "Precompiled header(%s) %s \t <--- %s" % (key,header_path,source[0])
55  env.Depends(target, header)
56 
57 
58 def static_pch_emitter(target,source,env):
59  SCons.Defaults.StaticObjectEmitter( target, source, env )
60  setup_dependency(target,source,env, key='GCH')
61  return (target, source)
62 
63 def shared_pch_emitter(target,source,env):
64  SCons.Defaults.SharedObjectEmitter( target, source, env )
65  setup_dependency(target,source,env, key='GCH-sh')
66  return (target, source)
67 
68 
69 def generate(env):
70  """ Add builders and construction variables for the Gch builder.
71  """
72  env.Append(BUILDERS = {
73  'gch': env.Builder(
74  action = GchAction,
75  target_factory = env.fs.File,
76  ),
77  'gchsh': env.Builder(
78  action = GchShAction,
79  target_factory = env.fs.File,
80  ),
81  })
82 
83  try:
84  bld = env['BUILDERS']['GCH']
85  bldsh = env['BUILDERS']['GCH-sh']
86  except KeyError:
87  bld = GchBuilder
88  bldsh = GchShBuilder
89  env['BUILDERS']['PrecompiledHeader'] = bld
90  env['BUILDERS']['PrecompiledHeaderShared'] = bldsh
91 
92  env['GCHCOM'] = '$CXX -o $TARGET -x c++-header -c $CXXFLAGS $_CCCOMCOM $SOURCE'
93  env['GCHSHCOM'] = '$CXX -o $TARGET -x c++-header -c $SHCXXFLAGS $_CCCOMCOM $SOURCE'
94  env['GCHSUFFIX'] = '.gch'
95 
96  for suffix in SCons.Util.Split('.c .C .cc .cxx .cpp .c++'):
97  env['BUILDERS']['StaticObject'].add_emitter( suffix, static_pch_emitter )
98  env['BUILDERS']['SharedObject'].add_emitter( suffix, shared_pch_emitter )
99 
100 
101 def exists(env):
102  return env.Detect('g++')