20 from types
import ListType
24 import SCons.Scanner.C
28 SCons.Script.EnsureSConsVersion(0,96,92)
30 GchAction = SCons.Action.Action(
'$GCHCOM',
'$GCHCOMSTR')
31 GchShAction = SCons.Action.Action(
'$GCHSHCOM',
'$GCHSHCOMSTR')
33 def gen_suffix(env, sources):
34 return sources[0].get_suffix() + env[
'GCHSUFFIX']
37 GchShBuilder = SCons.Builder.Builder(action = GchShAction,
38 source_scanner = SCons.Scanner.C.CScanner(),
41 GchBuilder = SCons.Builder.Builder(action = GchAction,
42 source_scanner = SCons.Scanner.C.CScanner(),
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)
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)
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)
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)
70 """ Add builders and construction variables for the Gch builder. 72 env.Append(BUILDERS = {
75 target_factory = env.fs.File,
79 target_factory = env.fs.File,
84 bld = env[
'BUILDERS'][
'GCH']
85 bldsh = env[
'BUILDERS'][
'GCH-sh']
89 env[
'BUILDERS'][
'PrecompiledHeader'] = bld
90 env[
'BUILDERS'][
'PrecompiledHeaderShared'] = bldsh
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' 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 )
102 return env.Detect(
'g++')