3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Authors: Nathan Binkert
39 from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
43 # This file defines how to build a particular configuration of M5
44 # based on variable settings in the 'env' build environment.
48 # Children need to see the environment
51 build_env = dict([(opt, env[opt]) for opt in env.ExportOptions])
54 """return a sorted copy of '_list'"""
55 if isinstance(_list, list):
62 class PySourceFile(object):
63 invalid_sym_char = re.compile('[^A-z0-9_]')
64 def __init__(self, package, tnode):
65 snode = tnode.srcnode()
67 pyname = basename(filename)
68 assert pyname.endswith('.py')
71 path = package.split('.')
76 if name != '__init__':
78 modpath = '.'.join(modpath)
80 arcpath = path + [ pyname ]
81 arcname = joinpath(*arcpath)
83 debugname = snode.abspath
84 if not exists(debugname):
85 debugname = tnode.abspath
90 self.package = package
91 self.modpath = modpath
92 self.arcname = arcname
93 self.debugname = debugname
94 self.compiled = File(filename + 'c')
95 self.assembly = File(filename + '.s')
96 self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath)
99 ########################################################################
100 # Code for adding source files of various types
104 '''Add a source file to the libm5 build'''
105 if not isinstance(source, SCons.Node.FS.File):
106 source = File(source)
108 cc_lib_sources.append(source)
111 def BinSource(source):
112 '''Add a source file to the m5 binary build'''
113 if not isinstance(source, SCons.Node.FS.File):
114 source = File(source)
116 cc_bin_sources.append(source)
119 def PySource(package, source):
120 '''Add a python source file to the named package'''
121 if not isinstance(source, SCons.Node.FS.File):
122 source = File(source)
124 source = PySourceFile(package, source)
125 py_sources.append(source)
127 sim_objects_fixed = False
128 sim_object_modfiles = set()
129 def SimObject(source):
130 '''Add a SimObject python file as a python source object and add
131 it to a list of sim object modules'''
133 if sim_objects_fixed:
134 raise AttributeError, "Too late to call SimObject now."
136 if not isinstance(source, SCons.Node.FS.File):
137 source = File(source)
139 PySource('m5.objects', source)
140 modfile = basename(str(source))
141 assert modfile.endswith('.py')
142 modname = modfile[:-3]
143 sim_object_modfiles.add(modname)
146 def SwigSource(package, source):
147 '''Add a swig file to build'''
148 if not isinstance(source, SCons.Node.FS.File):
149 source = File(source)
151 swig_sources.append(val)
154 def UnitTest(target, sources):
155 if not isinstance(sources, (list, tuple)):
156 sources = [ sources ]
159 for source in sources:
160 if not isinstance(source, SCons.Node.FS.File):
161 source = File(source)
164 unit_tests.append((target, srcs))
166 # Children should have access
174 ########################################################################
180 def TraceFlag(name, desc=''):
181 if name in all_flags:
182 raise AttributeError, "Flag %s already specified" % name
183 flag = (name, (), desc)
184 trace_flags.append(flag)
187 def CompoundFlag(name, flags, desc=''):
188 if name in all_flags:
189 raise AttributeError, "Flag %s already specified" % name
191 compound = tuple(flags)
192 for flag in compound:
193 if flag not in all_flags:
194 raise AttributeError, "Trace flag %s not found" % flag
196 raise AttributeError, \
197 "Compound flag can't point to another compound flag"
199 flag = (name, compound, desc)
200 trace_flags.append(flag)
201 all_flags[name] = compound
204 Export('CompoundFlag')
206 ########################################################################
208 # Set some compiler variables
211 # Include file paths are rooted in this directory. SCons will
212 # automatically expand '.' to refer to both the source directory and
213 # the corresponding build directory to pick up generated include
215 env.Append(CPPPATH=Dir('.'))
217 for extra_dir in extras_dir_list:
218 env.Append(CPPPATH=Dir(extra_dir))
220 # Add a flag defining what THE_ISA should be for all compilation
221 env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
223 # Workaround for bug in SCons version > 0.97d20071212
224 # Scons bug id: 2006 M5 Bug id: 308
225 for root, dirs, files in os.walk(base_dir, topdown=True):
226 Dir(root[len(base_dir) + 1:])
228 ########################################################################
230 # Walk the tree and execute all SConscripts in subdirectories
233 here = Dir('.').srcnode().abspath
234 for root, dirs, files in os.walk(base_dir, topdown=True):
236 # we don't want to recurse back into this SConscript
239 if 'SConscript' in files:
240 build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
241 SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
243 for extra_dir in extras_dir_list:
244 prefix_len = len(dirname(extra_dir)) + 1
245 for root, dirs, files in os.walk(extra_dir, topdown=True):
246 if 'SConscript' in files:
247 build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
248 SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
250 for opt in env.ExportOptions:
253 ########################################################################
255 # Prevent any SimObjects from being added after this point, they
256 # should all have been added in the SConscripts above
258 class DictImporter(object):
259 '''This importer takes a dictionary of arbitrary module names that
260 map to arbitrary filenames.'''
261 def __init__(self, modules):
262 self.modules = modules
263 self.installed = set()
270 for module in self.installed:
271 del sys.modules[module]
272 self.installed = set()
274 def find_module(self, fullname, path):
275 if fullname == '__scons':
278 if fullname == 'm5.objects':
281 if fullname.startswith('m5.internal'):
284 if fullname in self.modules and exists(self.modules[fullname]):
289 def load_module(self, fullname):
290 mod = imp.new_module(fullname)
291 sys.modules[fullname] = mod
292 self.installed.add(fullname)
294 mod.__loader__ = self
295 if fullname == 'm5.objects':
296 mod.__path__ = fullname.split('.')
299 if fullname == '__scons':
300 mod.__dict__['m5_build_env'] = build_env
303 srcfile = self.modules[fullname]
304 if basename(srcfile) == '__init__.py':
305 mod.__path__ = fullname.split('.')
306 mod.__file__ = srcfile
308 exec file(srcfile, 'r') in mod.__dict__
313 for source in py_sources:
314 py_modules[source.modpath] = source.snode.abspath
316 # install the python importer so we can grab stuff from the source
317 # tree itself. We can't have SimObjects added after this point or
318 # else we won't know about them for the rest of the stuff.
319 sim_objects_fixed = True
320 importer = DictImporter(py_modules)
321 sys.meta_path[0:0] = [ importer ]
325 # import all sim objects so we can populate the all_objects list
326 # make sure that we're working with a list, then let's sort it
327 sim_objects = list(sim_object_modfiles)
329 for simobj in sim_objects:
330 exec('from m5.objects import %s' % simobj)
332 # we need to unload all of the currently imported modules so that they
333 # will be re-imported the next time the sconscript is run
335 sys.meta_path.remove(importer)
337 sim_objects = m5.SimObject.allClasses
338 all_enums = m5.params.allEnums
341 for name,obj in sim_objects.iteritems():
342 for param in obj._params.local.values():
343 if not hasattr(param, 'swig_decl'):
345 pname = param.ptype_str
346 if pname not in all_params:
347 all_params[pname] = param
349 ########################################################################
351 # calculate extra dependencies
353 module_depends = ["m5", "m5.SimObject", "m5.params"]
354 depends = [ File(py_modules[dep]) for dep in module_depends ]
356 ########################################################################
358 # Commands for the basic automatically generated python files
361 # Generate Python file containing a dict specifying the current
363 def makeDefinesPyFile(target, source, env):
364 f = file(str(target[0]), 'w')
365 print >>f, "m5_build_env = ", source[0]
368 # Generate python file containing info about the M5 source code
369 def makeInfoPyFile(target, source, env):
370 f = file(str(target[0]), 'w')
372 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
373 print >>f, "%s = %s" % (src, repr(data))
376 # Generate the __init__.py file for m5.objects
377 def makeObjectsInitFile(target, source, env):
378 f = file(str(target[0]), 'w')
379 print >>f, 'from params import *'
380 print >>f, 'from m5.SimObject import *'
381 for module in source:
382 print >>f, 'from %s import *' % module.get_contents()
385 # Generate a file with all of the compile options in it
386 env.Command('python/m5/defines.py', Value(build_env), makeDefinesPyFile)
387 PySource('m5', 'python/m5/defines.py')
389 # Generate a file that wraps the basic top level files
390 env.Command('python/m5/info.py',
391 [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
393 PySource('m5', 'python/m5/info.py')
395 # Generate an __init__.py file for the objects package
396 env.Command('python/m5/objects/__init__.py',
397 [ Value(o) for o in sort_list(sim_object_modfiles) ],
399 PySource('m5.objects', 'python/m5/objects/__init__.py')
401 ########################################################################
403 # Create all of the SimObject param headers and enum headers
406 def createSimObjectParam(target, source, env):
407 assert len(target) == 1 and len(source) == 1
409 hh_file = file(target[0].abspath, 'w')
410 name = str(source[0].get_contents())
411 obj = sim_objects[name]
413 print >>hh_file, obj.cxx_decl()
415 def createSwigParam(target, source, env):
416 assert len(target) == 1 and len(source) == 1
418 i_file = file(target[0].abspath, 'w')
419 name = str(source[0].get_contents())
420 param = all_params[name]
422 for line in param.swig_decl():
425 def createEnumStrings(target, source, env):
426 assert len(target) == 1 and len(source) == 1
428 cc_file = file(target[0].abspath, 'w')
429 name = str(source[0].get_contents())
430 obj = all_enums[name]
432 print >>cc_file, obj.cxx_def()
435 def createEnumParam(target, source, env):
436 assert len(target) == 1 and len(source) == 1
438 hh_file = file(target[0].abspath, 'w')
439 name = str(source[0].get_contents())
440 obj = all_enums[name]
442 print >>hh_file, obj.cxx_decl()
444 # Generate all of the SimObject param struct header files
446 for name,simobj in sim_objects.iteritems():
447 extra_deps = [ File(py_modules[simobj.__module__]) ]
449 hh_file = File('params/%s.hh' % name)
450 params_hh_files.append(hh_file)
451 env.Command(hh_file, Value(name), createSimObjectParam)
452 env.Depends(hh_file, depends + extra_deps)
454 # Generate any parameter header files needed
456 for name,param in all_params.iteritems():
457 if isinstance(param, m5.params.VectorParamDesc):
462 i_file = File('params/%s_%s.i' % (name, ext))
463 params_i_files.append(i_file)
464 env.Command(i_file, Value(name), createSwigParam)
465 env.Depends(i_file, depends)
467 # Generate all enum header files
468 for name,enum in all_enums.iteritems():
469 extra_deps = [ File(py_modules[enum.__module__]) ]
471 cc_file = File('enums/%s.cc' % name)
472 env.Command(cc_file, Value(name), createEnumStrings)
473 env.Depends(cc_file, depends + extra_deps)
476 hh_file = File('enums/%s.hh' % name)
477 env.Command(hh_file, Value(name), createEnumParam)
478 env.Depends(hh_file, depends + extra_deps)
480 # Build the big monolithic swigged params module (wraps all SimObject
481 # param structs and enum structs)
482 def buildParams(target, source, env):
483 names = [ s.get_contents() for s in source ]
484 objs = [ sim_objects[name] for name in names ]
485 out = file(target[0].abspath, 'w')
495 if str(obj) != 'SimObject':
496 order_obj(obj.__bases__[0])
498 ordered_objs.append(obj)
509 if pd not in pd_seen:
513 for obj in ordered_objs:
514 params = obj._params.local.values()
517 if issubclass(ptype, m5.params.Enum):
518 if ptype not in enums:
520 pds = param.swig_predecls()
521 if isinstance(pds, (list, tuple)):
526 print >>out, '%module params'
529 for obj in ordered_objs:
530 print >>out, '#include "params/%s.hh"' % obj
539 print >>out, '%%include "enums/%s.hh"' % enum.__name__
542 for obj in ordered_objs:
543 if obj.swig_objdecls:
544 for decl in obj.swig_objdecls:
548 class_path = obj.cxx_class.split('::')
549 classname = class_path[-1]
550 namespaces = class_path[:-1]
556 code += '// avoid name conflicts\n'
557 sep_string = '_COLONS_'
558 flat_name = sep_string.join(class_path)
559 code += '%%rename(%s) %s;\n' % (flat_name, classname)
561 code += '// stop swig from creating/wrapping default ctor/dtor\n'
562 code += '%%nodefault %s;\n' % classname
563 code += 'class %s ' % classname
565 code += ': public %s' % obj._base.cxx_class
568 for ns in namespaces:
569 new_code = 'namespace %s {\n' % ns
576 print >>out, '%%include "src/sim/sim_object_params.hh"' % obj
577 for obj in ordered_objs:
578 print >>out, '%%include "params/%s.hh"' % obj
580 params_file = File('params/params.i')
581 names = sort_list(sim_objects.keys())
582 env.Command(params_file, [ Value(v) for v in names ], buildParams)
583 env.Depends(params_file, params_hh_files + params_i_files + depends)
584 SwigSource('m5.objects', params_file)
586 # Build all swig modules
589 for source,package in swig_sources:
590 filename = str(source)
591 assert filename.endswith('.i')
593 base = '.'.join(filename.split('.')[:-1])
594 module = basename(base)
595 cc_file = base + '_wrap.cc'
596 py_file = base + '.py'
598 env.Command([cc_file, py_file], source,
599 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
600 '-o ${TARGETS[0]} $SOURCES')
601 env.Depends(py_file, source)
602 env.Depends(cc_file, source)
604 swig_modules.append(Value(module))
605 cc_swig_sources.append(File(cc_file))
606 PySource(package, py_file)
608 # Generate the main swig init file
609 def makeSwigInit(target, source, env):
610 f = file(str(target[0]), 'w')
611 print >>f, 'extern "C" {'
612 for module in source:
613 print >>f, ' void init_%s();' % module.get_contents()
615 print >>f, 'void initSwig() {'
616 for module in source:
617 print >>f, ' init_%s();' % module.get_contents()
621 env.Command('python/swig/init.cc', swig_modules, makeSwigInit)
622 Source('python/swig/init.cc')
624 # Generate traceflags.py
625 def traceFlagsPy(target, source, env):
626 assert(len(target) == 1)
628 f = file(str(target[0]), 'w')
632 val = eval(s.get_contents())
635 print >>f, 'baseFlags = ['
636 for flag, compound, desc in allFlags:
638 print >>f, " '%s'," % flag
642 print >>f, 'compoundFlags = ['
644 for flag, compound, desc in allFlags:
646 print >>f, " '%s'," % flag
650 print >>f, "allFlags = frozenset(baseFlags + compoundFlags)"
653 print >>f, 'compoundFlagMap = {'
654 all = tuple([flag for flag,compound,desc in allFlags if not compound])
655 print >>f, " 'All' : %s," % (all, )
656 for flag, compound, desc in allFlags:
658 print >>f, " '%s' : %s," % (flag, compound)
662 print >>f, 'flagDescriptions = {'
663 print >>f, " 'All' : 'All flags',"
664 for flag, compound, desc in allFlags:
665 print >>f, " '%s' : '%s'," % (flag, desc)
670 def traceFlagsCC(target, source, env):
671 assert(len(target) == 1)
673 f = file(str(target[0]), 'w')
677 val = eval(s.get_contents())
683 * DO NOT EDIT THIS FILE! Automatically generated
686 #include "base/traceflags.hh"
688 using namespace Trace;
690 const char *Trace::flagStrings[] =
693 # The string array is used by SimpleEnumParam to map the strings
694 # provided by the user to enum values.
695 for flag, compound, desc in allFlags:
697 print >>f, ' "%s",' % flag
700 for flag, compound, desc in allFlags:
702 print >>f, ' "%s",' % flag
706 print >>f, 'const int Trace::numFlagStrings = %d;' % (len(allFlags) + 1)
710 # Now define the individual compound flag arrays. There is an array
711 # for each compound flag listing the component base flags.
713 all = tuple([flag for flag,compound,desc in allFlags if not compound])
714 print >>f, 'static const Flags AllMap[] = {'
715 for flag, compound, desc in allFlags:
717 print >>f, " %s," % flag
721 for flag, compound, desc in allFlags:
724 print >>f, 'static const Flags %sMap[] = {' % flag
725 for flag in compound:
726 print >>f, " %s," % flag
727 print >>f, " (Flags)-1"
732 # Finally the compoundFlags[] array maps the compound flags
733 # to their individual arrays/
735 print >>f, 'const Flags *Trace::compoundFlags[] ='
737 print >>f, ' AllMap,'
738 for flag, compound, desc in allFlags:
740 print >>f, ' %sMap,' % flag
746 def traceFlagsHH(target, source, env):
747 assert(len(target) == 1)
749 f = file(str(target[0]), 'w')
753 val = eval(s.get_contents())
756 # file header boilerplate
759 * DO NOT EDIT THIS FILE!
761 * Automatically generated from traceflags.py
764 #ifndef __BASE_TRACE_FLAGS_HH__
765 #define __BASE_TRACE_FLAGS_HH__
771 # Generate the enum. Base flags come first, then compound flags.
773 for flag, compound, desc in allFlags:
775 print >>f, ' %s = %d,' % (flag, idx)
779 print >>f, ' NumFlags = %d,' % idx
781 # put a comment in here to separate base from compound flags
783 // The remaining enum values are *not* valid indices for Trace::flags.
784 // They are "compound" flags, which correspond to sets of base
785 // flags, and are used by changeFlag.'''
787 print >>f, ' All = %d,' % idx
789 for flag, compound, desc in allFlags:
791 print >>f, ' %s = %d,' % (flag, idx)
794 numCompoundFlags = idx - numBaseFlags
795 print >>f, ' NumCompoundFlags = %d' % numCompoundFlags
797 # trailer boilerplate
801 // Array of strings for SimpleEnumParam
802 extern const char *flagStrings[];
803 extern const int numFlagStrings;
805 // Array of arraay pointers: for each compound flag, gives the list of
806 // base flags to set. Inidividual flag arrays are terminated by -1.
807 extern const Flags *compoundFlags[];
809 /* namespace Trace */ }
811 #endif // __BASE_TRACE_FLAGS_HH__
816 flags = [ Value(f) for f in trace_flags ]
817 env.Command('base/traceflags.py', flags, traceFlagsPy)
818 PySource('m5', 'base/traceflags.py')
820 env.Command('base/traceflags.hh', flags, traceFlagsHH)
821 env.Command('base/traceflags.cc', flags, traceFlagsCC)
822 Source('base/traceflags.cc')
824 # Generate program_info.cc
825 def programInfo(target, source, env):
826 def gen_file(target, rev, node, date):
827 pi_stats = file(target, 'w')
828 print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node)
829 print >>pi_stats, 'const char *hgDate = "%s";' % date
832 target = str(target[0])
833 scons_dir = str(source[0].get_contents())
835 import mercurial.demandimport, mercurial.hg, mercurial.ui
836 import mercurial.util, mercurial.node
837 if not exists(scons_dir) or not isdir(scons_dir) or \
838 not exists(joinpath(scons_dir, ".hg")):
840 repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir)
841 rev = mercurial.node.nullrev + repo.changelog.count()
842 changenode = repo.changelog.node(rev)
843 changes = repo.changelog.read(changenode)
844 date = mercurial.util.datestr(changes[2])
846 gen_file(target, rev, mercurial.node.hex(changenode), date)
848 mercurial.demandimport.disable()
850 gen_file(target, "Unknown", "Unknown", "Unknown")
854 gen_file(target, "Unknown", "Unknown", "Unknown")
855 mercurial.demandimport.disable()
857 env.Command('base/program_info.cc',
858 Value(str(SCons.Node.FS.default_fs.SConstruct_dir)),
861 # embed python files. All .py files that have been indicated by a
862 # PySource() call in a SConscript need to be embedded into the M5
863 # library. To do that, we compile the file to byte code, marshal the
864 # byte code, compress it, and then generate an assembly file that
865 # inserts the result into the data section with symbols indicating the
866 # beginning, and end (and with the size at the end)
867 py_sources_tnodes = {}
868 for pysource in py_sources:
869 py_sources_tnodes[pysource.tnode] = pysource
871 def objectifyPyFile(target, source, env):
872 '''Action function to compile a .py into a code object, marshal
873 it, compress it, and stick it into an asm file so the code appears
874 as just bytes with a label in the data section'''
876 src = file(str(source[0]), 'r').read()
877 dst = file(str(target[0]), 'w')
879 pysource = py_sources_tnodes[source[0]]
880 compiled = compile(src, pysource.debugname, 'exec')
881 marshalled = marshal.dumps(compiled)
882 compressed = zlib.compress(marshalled)
885 # Some C/C++ compilers prepend an underscore to global symbol
886 # names, so if they're going to do that, we need to prepend that
887 # leading underscore to globals in the assembly file.
888 if env['LEADING_UNDERSCORE']:
889 sym = '_' + pysource.symname
891 sym = pysource.symname
895 print >>dst, ".globl %s_beg" % sym
896 print >>dst, ".globl %s_end" % sym
897 print >>dst, "%s_beg:" % sym
898 for i in xrange(0, len(data), step):
899 x = array.array('B', data[i:i+step])
900 print >>dst, ".byte", ','.join([str(d) for d in x])
901 print >>dst, "%s_end:" % sym
902 print >>dst, ".long %d" % len(marshalled)
904 for source in py_sources:
905 env.Command(source.assembly, source.tnode, objectifyPyFile)
906 Source(source.assembly)
908 # Generate init_python.cc which creates a bunch of EmbeddedPyModule
909 # structs that describe the embedded python code. One such struct
910 # contains information about the importer that python uses to get at
911 # the embedded files, and then there's a list of all of the rest that
912 # the importer uses to load the rest on demand.
913 py_sources_symbols = {}
914 for pysource in py_sources:
915 py_sources_symbols[pysource.symname] = pysource
916 def pythonInit(target, source, env):
917 dst = file(str(target[0]), 'w')
919 def dump_mod(sym, endchar=','):
920 pysource = py_sources_symbols[sym]
921 print >>dst, ' { "%s",' % pysource.arcname
922 print >>dst, ' "%s",' % pysource.modpath
923 print >>dst, ' %s_beg, %s_end,' % (sym, sym)
924 print >>dst, ' %s_end - %s_beg,' % (sym, sym)
925 print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
927 print >>dst, '#include "sim/init.hh"'
930 sym = sym.get_contents()
931 print >>dst, "extern const char %s_beg[], %s_end[];" % (sym, sym)
933 print >>dst, "const EmbeddedPyModule embeddedPyImporter = "
934 dump_mod("PyEMB_importer", endchar=';');
937 print >>dst, "const EmbeddedPyModule embeddedPyModules[] = {"
938 for i,sym in enumerate(source):
939 sym = sym.get_contents()
940 if sym == "PyEMB_importer":
941 # Skip the importer since we've already exported it
944 print >>dst, " { 0, 0, 0, 0, 0, 0 }"
947 symbols = [Value(s.symname) for s in py_sources]
948 env.Command('sim/init_python.cc', symbols, pythonInit)
949 Source('sim/init_python.cc')
951 ########################################################################
953 # Define binaries. Each different build type (debug, opt, etc.) gets
954 # a slightly different build environment.
957 # List of constructed environments to pass back to SConstruct
960 # This function adds the specified sources to the given build
961 # environment, and returns a list of all the corresponding SCons
962 # Object nodes (including an extra one for date.cc). We explicitly
963 # add the Object nodes so we can set up special dependencies for
965 def make_objs(sources, env, static):
967 XObject = env.StaticObject
969 XObject = env.SharedObject
971 objs = [ XObject(s) for s in sources ]
973 # make date.cc depend on all other objects so it always gets
974 # recompiled whenever anything else does
975 date_obj = XObject('base/date.cc')
977 # Make the generation of program_info.cc dependend on all
978 # the other cc files and the compiling of program_info.cc
979 # dependent on all the objects but program_info.o
980 pinfo_obj = XObject('base/program_info.cc')
981 env.Depends('base/program_info.cc', sources)
982 env.Depends(date_obj, objs)
983 env.Depends(pinfo_obj, objs)
984 objs.extend([date_obj, pinfo_obj])
987 # Function to create a new build environment as clone of current
988 # environment 'env' with modified object suffix and optional stripped
989 # binary. Additional keyword arguments are appended to corresponding
990 # build environment vars.
991 def makeEnv(label, objsfx, strip = False, **kwargs):
992 # SCons doesn't know to append a library suffix when there is a '.' in the
993 # name. Use '_' instead.
994 libname = 'm5_' + label
995 exename = 'm5.' + label
997 new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
998 new_env.Label = label
999 new_env.Append(**kwargs)
1001 swig_env = new_env.Copy()
1003 swig_env.Append(CCFLAGS='-Wno-uninitialized')
1004 swig_env.Append(CCFLAGS='-Wno-sign-compare')
1005 swig_env.Append(CCFLAGS='-Wno-parentheses')
1007 static_objs = make_objs(cc_lib_sources, new_env, static=True)
1008 shared_objs = make_objs(cc_lib_sources, new_env, static=False)
1009 static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ]
1010 shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ]
1012 # First make a library of everything but main() so other programs can
1014 static_lib = new_env.StaticLibrary(libname, static_objs + static_objs)
1015 shared_lib = new_env.SharedLibrary(libname, shared_objs + shared_objs)
1017 for target, sources in unit_tests:
1018 objs = [ new_env.StaticObject(s) for s in sources ]
1019 new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib)
1021 # Now link a stub with main() and the static library.
1022 objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib
1024 unstripped_exe = exename + '.unstripped'
1025 new_env.Program(unstripped_exe, objects)
1026 if sys.platform == 'sunos5':
1027 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1029 cmd = 'strip $SOURCE -o $TARGET'
1030 targets = new_env.Command(exename, unstripped_exe, cmd)
1032 targets = new_env.Program(exename, objects)
1034 new_env.M5Binary = targets[0]
1035 envList.append(new_env)
1040 if sys.platform == 'sunos5':
1041 ccflags['debug'] = '-gstabs+'
1043 ccflags['debug'] = '-ggdb3'
1044 ccflags['opt'] = '-g -O3'
1045 ccflags['fast'] = '-O3'
1046 ccflags['prof'] = '-O3 -g -pg'
1048 ccflags['debug'] = '-g0'
1049 ccflags['opt'] = '-g -O'
1050 ccflags['fast'] = '-fast'
1051 ccflags['prof'] = '-fast -g -pg'
1053 ccflags['debug'] = '-g -O0'
1054 ccflags['opt'] = '-g -O'
1055 ccflags['fast'] = '-fast'
1056 ccflags['prof'] = '-fast -g -pg'
1058 print 'Unknown compiler, please fix compiler options'
1061 makeEnv('debug', '.do',
1062 CCFLAGS = Split(ccflags['debug']),
1063 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
1066 makeEnv('opt', '.o',
1067 CCFLAGS = Split(ccflags['opt']),
1068 CPPDEFINES = ['TRACING_ON=1'])
1071 makeEnv('fast', '.fo', strip = True,
1072 CCFLAGS = Split(ccflags['fast']),
1073 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
1076 makeEnv('prof', '.po',
1077 CCFLAGS = Split(ccflags['prof']),
1078 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],