+def makeEmbeddedSwigInit(target, source, env):
+ code = code_formatter()
+ module = source[0].get_contents()
+ code('''\
+#include "sim/init.hh"
+
+extern "C" {
+ void init_${module}();
+}
+
+EmbeddedSwig embed_swig_${module}(init_${module});
+''')
+ code.write(str(target[0]))
+
+# Build all swig modules
+for swig in SwigSource.all:
+ env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
+ MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
+ '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
+ cc_file = str(swig.tnode)
+ init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
+ env.Command(init_file, Value(swig.module),
+ MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
+ Source(init_file, **swig.guards)
+
+# Build all protocol buffers if we have got protoc and protobuf available
+if env['HAVE_PROTOBUF']:
+ for proto in ProtoBuf.all:
+ # Use both the source and header as the target, and the .proto
+ # file as the source. When executing the protoc compiler, also
+ # specify the proto_path to avoid having the generated files
+ # include the path.
+ env.Command([proto.cc_file, proto.hh_file], proto.tnode,
+ MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
+ '--proto_path ${SOURCE.dir} $SOURCE',
+ Transform("PROTOC")))
+
+ # Add the C++ source file
+ Source(proto.cc_file, **proto.guards)
+elif ProtoBuf.all:
+ print 'Got protobuf to build, but lacks support!'
+ Exit(1)
+
+#
+# Handle debug flags
+#
+def makeDebugFlagCC(target, source, env):
+ assert(len(target) == 1 and len(source) == 1)
+
+ val = eval(source[0].get_contents())
+ name, compound, desc = val
+ compound = list(sorted(compound))
+
+ code = code_formatter()
+
+ # file header
+ code('''
+/*
+ * DO NOT EDIT THIS FILE! Automatically generated
+ */
+
+#include "base/debug.hh"
+''')
+
+ for flag in compound:
+ code('#include "debug/$flag.hh"')
+ code()
+ code('namespace Debug {')
+ code()
+
+ if not compound:
+ code('SimpleFlag $name("$name", "$desc");')
+ else:
+ code('CompoundFlag $name("$name", "$desc",')
+ code.indent()
+ last = len(compound) - 1
+ for i,flag in enumerate(compound):
+ if i != last:
+ code('$flag,')
+ else:
+ code('$flag);')
+ code.dedent()
+
+ code()
+ code('} // namespace Debug')
+
+ code.write(str(target[0]))
+
+def makeDebugFlagHH(target, source, env):
+ assert(len(target) == 1 and len(source) == 1)
+
+ val = eval(source[0].get_contents())
+ name, compound, desc = val
+
+ code = code_formatter()
+
+ # file header boilerplate
+ code('''\
+/*
+ * DO NOT EDIT THIS FILE!
+ *
+ * Automatically generated by SCons
+ */
+
+#ifndef __DEBUG_${name}_HH__
+#define __DEBUG_${name}_HH__
+
+namespace Debug {
+''')
+
+ if compound:
+ code('class CompoundFlag;')
+ code('class SimpleFlag;')
+
+ if compound:
+ code('extern CompoundFlag $name;')
+ for flag in compound:
+ code('extern SimpleFlag $flag;')
+ else:
+ code('extern SimpleFlag $name;')
+
+ code('''
+}
+
+#endif // __DEBUG_${name}_HH__
+''')