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 ########################################################################
225 # Walk the tree and execute all SConscripts in subdirectories
228 here = Dir('.').srcnode().abspath
229 for root, dirs, files in os.walk(base_dir, topdown=True):
231 # we don't want to recurse back into this SConscript
234 if 'SConscript' in files:
235 build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
236 SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
238 for extra_dir in extras_dir_list:
239 prefix_len = len(dirname(extra_dir)) + 1
240 for root, dirs, files in os.walk(extra_dir, topdown=True):
241 if 'SConscript' in files:
242 build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
243 SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
245 for opt in env.ExportOptions:
248 ########################################################################
250 # Prevent any SimObjects from being added after this point, they
251 # should all have been added in the SConscripts above
253 class DictImporter(object):
254 '''This importer takes a dictionary of arbitrary module names that
255 map to arbitrary filenames.'''
256 def __init__(self, modules):
257 self.modules = modules
258 self.installed = set()
265 for module in self.installed:
266 del sys.modules[module]
267 self.installed = set()
269 def find_module(self, fullname, path):
270 if fullname == '__scons':
273 if fullname == 'm5.objects':
276 if fullname.startswith('m5.internal'):
279 if fullname in self.modules and exists(self.modules[fullname]):
284 def load_module(self, fullname):
285 mod = imp.new_module(fullname)
286 sys.modules[fullname] = mod
287 self.installed.add(fullname)
289 mod.__loader__ = self
290 if fullname == 'm5.objects':
291 mod.__path__ = fullname.split('.')
294 if fullname == '__scons':
295 mod.__dict__['m5_build_env'] = build_env
298 srcfile = self.modules[fullname]
299 if basename(srcfile) == '__init__.py':
300 mod.__path__ = fullname.split('.')
301 mod.__file__ = srcfile
303 exec file(srcfile, 'r') in mod.__dict__
308 for source in py_sources:
309 py_modules[source.modpath] = source.snode.abspath
311 # install the python importer so we can grab stuff from the source
312 # tree itself. We can't have SimObjects added after this point or
313 # else we won't know about them for the rest of the stuff.
314 sim_objects_fixed = True
315 importer = DictImporter(py_modules)
316 sys.meta_path[0:0] = [ importer ]
320 # import all sim objects so we can populate the all_objects list
321 # make sure that we're working with a list, then let's sort it
322 sim_objects = list(sim_object_modfiles)
324 for simobj in sim_objects:
325 exec('from m5.objects import %s' % simobj)
327 # we need to unload all of the currently imported modules so that they
328 # will be re-imported the next time the sconscript is run
330 sys.meta_path.remove(importer)
332 sim_objects = m5.SimObject.allClasses
333 all_enums = m5.params.allEnums
336 for name,obj in sim_objects.iteritems():
337 for param in obj._params.local.values():
338 if not hasattr(param, 'swig_decl'):
340 pname = param.ptype_str
341 if pname not in all_params:
342 all_params[pname] = param
344 ########################################################################
346 # calculate extra dependencies
348 module_depends = ["m5", "m5.SimObject", "m5.params"]
349 depends = [ File(py_modules[dep]) for dep in module_depends ]
351 ########################################################################
353 # Commands for the basic automatically generated python files
356 # Generate Python file containing a dict specifying the current
358 def makeDefinesPyFile(target, source, env):
359 f = file(str(target[0]), 'w')
360 print >>f, "m5_build_env = ", source[0]
363 # Generate python file containing info about the M5 source code
364 def makeInfoPyFile(target, source, env):
365 f = file(str(target[0]), 'w')
367 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
368 print >>f, "%s = %s" % (src, repr(data))
371 # Generate the __init__.py file for m5.objects
372 def makeObjectsInitFile(target, source, env):
373 f = file(str(target[0]), 'w')
374 print >>f, 'from params import *'
375 print >>f, 'from m5.SimObject import *'
376 for module in source:
377 print >>f, 'from %s import *' % module.get_contents()
380 # Generate a file with all of the compile options in it
381 env.Command('python/m5/defines.py', Value(build_env), makeDefinesPyFile)
382 PySource('m5', 'python/m5/defines.py')
384 # Generate a file that wraps the basic top level files
385 env.Command('python/m5/info.py',
386 [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
388 PySource('m5', 'python/m5/info.py')
390 # Generate an __init__.py file for the objects package
391 env.Command('python/m5/objects/__init__.py',
392 [ Value(o) for o in sort_list(sim_object_modfiles) ],
394 PySource('m5.objects', 'python/m5/objects/__init__.py')
396 ########################################################################
398 # Create all of the SimObject param headers and enum headers
401 def createSimObjectParam(target, source, env):
402 assert len(target) == 1 and len(source) == 1
404 hh_file = file(target[0].abspath, 'w')
405 name = str(source[0].get_contents())
406 obj = sim_objects[name]
408 print >>hh_file, obj.cxx_decl()
410 def createSwigParam(target, source, env):
411 assert len(target) == 1 and len(source) == 1
413 i_file = file(target[0].abspath, 'w')
414 name = str(source[0].get_contents())
415 param = all_params[name]
417 for line in param.swig_decl():
420 def createEnumStrings(target, source, env):
421 assert len(target) == 1 and len(source) == 1
423 cc_file = file(target[0].abspath, 'w')
424 name = str(source[0].get_contents())
425 obj = all_enums[name]
427 print >>cc_file, obj.cxx_def()
430 def createEnumParam(target, source, env):
431 assert len(target) == 1 and len(source) == 1
433 hh_file = file(target[0].abspath, 'w')
434 name = str(source[0].get_contents())
435 obj = all_enums[name]
437 print >>hh_file, obj.cxx_decl()
439 # Generate all of the SimObject param struct header files
441 for name,simobj in sim_objects.iteritems():
442 extra_deps = [ File(py_modules[simobj.__module__]) ]
444 hh_file = File('params/%s.hh' % name)
445 params_hh_files.append(hh_file)
446 env.Command(hh_file, Value(name), createSimObjectParam)
447 env.Depends(hh_file, depends + extra_deps)
449 # Generate any parameter header files needed
451 for name,param in all_params.iteritems():
452 if isinstance(param, m5.params.VectorParamDesc):
457 i_file = File('params/%s_%s.i' % (name, ext))
458 params_i_files.append(i_file)
459 env.Command(i_file, Value(name), createSwigParam)
460 env.Depends(i_file, depends)
462 # Generate all enum header files
463 for name,enum in all_enums.iteritems():
464 extra_deps = [ File(py_modules[enum.__module__]) ]
466 cc_file = File('enums/%s.cc' % name)
467 env.Command(cc_file, Value(name), createEnumStrings)
468 env.Depends(cc_file, depends + extra_deps)
471 hh_file = File('enums/%s.hh' % name)
472 env.Command(hh_file, Value(name), createEnumParam)
473 env.Depends(hh_file, depends + extra_deps)
475 # Build the big monolithic swigged params module (wraps all SimObject
476 # param structs and enum structs)
477 def buildParams(target, source, env):
478 names = [ s.get_contents() for s in source ]
479 objs = [ sim_objects[name] for name in names ]
480 out = file(target[0].abspath, 'w')
490 if str(obj) != 'SimObject':
491 order_obj(obj.__bases__[0])
493 ordered_objs.append(obj)
504 if pd not in pd_seen:
508 for obj in ordered_objs:
509 params = obj._params.local.values()
512 if issubclass(ptype, m5.params.Enum):
513 if ptype not in enums:
515 pds = param.swig_predecls()
516 if isinstance(pds, (list, tuple)):
521 print >>out, '%module params'
524 for obj in ordered_objs:
525 print >>out, '#include "params/%s.hh"' % obj
534 print >>out, '%%include "enums/%s.hh"' % enum.__name__
537 for obj in ordered_objs:
538 if obj.swig_objdecls:
539 for decl in obj.swig_objdecls:
543 class_path = obj.cxx_class.split('::')
544 classname = class_path[-1]
545 namespaces = class_path[:-1]
551 code += '// avoid name conflicts\n'
552 sep_string = '_COLONS_'
553 flat_name = sep_string.join(class_path)
554 code += '%%rename(%s) %s;\n' % (flat_name, classname)
556 code += '// stop swig from creating/wrapping default ctor/dtor\n'
557 code += '%%nodefault %s;\n' % classname
558 code += 'class %s ' % classname
560 code += ': public %s' % obj._base.cxx_class
563 for ns in namespaces:
564 new_code = 'namespace %s {\n' % ns
571 print >>out, '%%include "src/sim/sim_object_params.hh"' % obj
572 for obj in ordered_objs:
573 print >>out, '%%include "params/%s.hh"' % obj
575 params_file = File('params/params.i')
576 names = sort_list(sim_objects.keys())
577 env.Command(params_file, [ Value(v) for v in names ], buildParams)
578 env.Depends(params_file, params_hh_files + params_i_files + depends)
579 SwigSource('m5.objects', params_file)
581 # Build all swig modules
584 for source,package in swig_sources:
585 filename = str(source)
586 assert filename.endswith('.i')
588 base = '.'.join(filename.split('.')[:-1])
589 module = basename(base)
590 cc_file = base + '_wrap.cc'
591 py_file = base + '.py'
593 env.Command([cc_file, py_file], source,
594 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
595 '-o ${TARGETS[0]} $SOURCES')
596 env.Depends(py_file, source)
597 env.Depends(cc_file, source)
599 swig_modules.append(Value(module))
600 cc_swig_sources.append(File(cc_file))
601 PySource(package, py_file)
603 # Generate the main swig init file
604 def makeSwigInit(target, source, env):
605 f = file(str(target[0]), 'w')
606 print >>f, 'extern "C" {'
607 for module in source:
608 print >>f, ' void init_%s();' % module.get_contents()
610 print >>f, 'void initSwig() {'
611 for module in source:
612 print >>f, ' init_%s();' % module.get_contents()
616 env.Command('python/swig/init.cc', swig_modules, makeSwigInit)
617 Source('python/swig/init.cc')
619 # Generate traceflags.py
620 def traceFlagsPy(target, source, env):
621 assert(len(target) == 1)
623 f = file(str(target[0]), 'w')
627 val = eval(s.get_contents())
630 print >>f, 'baseFlags = ['
631 for flag, compound, desc in allFlags:
633 print >>f, " '%s'," % flag
637 print >>f, 'compoundFlags = ['
639 for flag, compound, desc in allFlags:
641 print >>f, " '%s'," % flag
645 print >>f, "allFlags = frozenset(baseFlags + compoundFlags)"
648 print >>f, 'compoundFlagMap = {'
649 all = tuple([flag for flag,compound,desc in allFlags if not compound])
650 print >>f, " 'All' : %s," % (all, )
651 for flag, compound, desc in allFlags:
653 print >>f, " '%s' : %s," % (flag, compound)
657 print >>f, 'flagDescriptions = {'
658 print >>f, " 'All' : 'All flags',"
659 for flag, compound, desc in allFlags:
660 print >>f, " '%s' : '%s'," % (flag, desc)
665 def traceFlagsCC(target, source, env):
666 assert(len(target) == 1)
668 f = file(str(target[0]), 'w')
672 val = eval(s.get_contents())
678 * DO NOT EDIT THIS FILE! Automatically generated
681 #include "base/traceflags.hh"
683 using namespace Trace;
685 const char *Trace::flagStrings[] =
688 # The string array is used by SimpleEnumParam to map the strings
689 # provided by the user to enum values.
690 for flag, compound, desc in allFlags:
692 print >>f, ' "%s",' % flag
695 for flag, compound, desc in allFlags:
697 print >>f, ' "%s",' % flag
701 print >>f, 'const int Trace::numFlagStrings = %d;' % (len(allFlags) + 1)
705 # Now define the individual compound flag arrays. There is an array
706 # for each compound flag listing the component base flags.
708 all = tuple([flag for flag,compound,desc in allFlags if not compound])
709 print >>f, 'static const Flags AllMap[] = {'
710 for flag, compound, desc in allFlags:
712 print >>f, " %s," % flag
716 for flag, compound, desc in allFlags:
719 print >>f, 'static const Flags %sMap[] = {' % flag
720 for flag in compound:
721 print >>f, " %s," % flag
722 print >>f, " (Flags)-1"
727 # Finally the compoundFlags[] array maps the compound flags
728 # to their individual arrays/
730 print >>f, 'const Flags *Trace::compoundFlags[] ='
732 print >>f, ' AllMap,'
733 for flag, compound, desc in allFlags:
735 print >>f, ' %sMap,' % flag
741 def traceFlagsHH(target, source, env):
742 assert(len(target) == 1)
744 f = file(str(target[0]), 'w')
748 val = eval(s.get_contents())
751 # file header boilerplate
754 * DO NOT EDIT THIS FILE!
756 * Automatically generated from traceflags.py
759 #ifndef __BASE_TRACE_FLAGS_HH__
760 #define __BASE_TRACE_FLAGS_HH__
766 # Generate the enum. Base flags come first, then compound flags.
768 for flag, compound, desc in allFlags:
770 print >>f, ' %s = %d,' % (flag, idx)
774 print >>f, ' NumFlags = %d,' % idx
776 # put a comment in here to separate base from compound flags
778 // The remaining enum values are *not* valid indices for Trace::flags.
779 // They are "compound" flags, which correspond to sets of base
780 // flags, and are used by changeFlag.'''
782 print >>f, ' All = %d,' % idx
784 for flag, compound, desc in allFlags:
786 print >>f, ' %s = %d,' % (flag, idx)
789 numCompoundFlags = idx - numBaseFlags
790 print >>f, ' NumCompoundFlags = %d' % numCompoundFlags
792 # trailer boilerplate
796 // Array of strings for SimpleEnumParam
797 extern const char *flagStrings[];
798 extern const int numFlagStrings;
800 // Array of arraay pointers: for each compound flag, gives the list of
801 // base flags to set. Inidividual flag arrays are terminated by -1.
802 extern const Flags *compoundFlags[];
804 /* namespace Trace */ }
806 #endif // __BASE_TRACE_FLAGS_HH__
811 flags = [ Value(f) for f in trace_flags ]
812 env.Command('base/traceflags.py', flags, traceFlagsPy)
813 PySource('m5', 'base/traceflags.py')
815 env.Command('base/traceflags.hh', flags, traceFlagsHH)
816 env.Command('base/traceflags.cc', flags, traceFlagsCC)
817 Source('base/traceflags.cc')
819 # Generate program_info.cc
820 def programInfo(target, source, env):
821 def gen_file(target, rev, node, date):
822 pi_stats = file(target, 'w')
823 print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node)
824 print >>pi_stats, 'const char *hgDate = "%s";' % date
827 target = str(target[0])
828 scons_dir = str(source[0].get_contents())
830 import mercurial.demandimport, mercurial.hg, mercurial.ui
831 import mercurial.util, mercurial.node
832 if not exists(scons_dir) or not isdir(scons_dir) or \
833 not exists(joinpath(scons_dir, ".hg")):
835 repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir)
836 rev = mercurial.node.nullrev + repo.changelog.count()
837 changenode = repo.changelog.node(rev)
838 changes = repo.changelog.read(changenode)
839 date = mercurial.util.datestr(changes[2])
841 gen_file(target, rev, mercurial.node.hex(changenode), date)
843 mercurial.demandimport.disable()
845 gen_file(target, "Unknown", "Unknown", "Unknown")
849 gen_file(target, "Unknown", "Unknown", "Unknown")
850 mercurial.demandimport.disable()
852 env.Command('base/program_info.cc',
853 Value(str(SCons.Node.FS.default_fs.SConstruct_dir)),
856 # embed python files. All .py files that have been indicated by a
857 # PySource() call in a SConscript need to be embedded into the M5
858 # library. To do that, we compile the file to byte code, marshal the
859 # byte code, compress it, and then generate an assembly file that
860 # inserts the result into the data section with symbols indicating the
861 # beginning, and end (and with the size at the end)
862 py_sources_tnodes = {}
863 for pysource in py_sources:
864 py_sources_tnodes[pysource.tnode] = pysource
866 def objectifyPyFile(target, source, env):
867 '''Action function to compile a .py into a code object, marshal
868 it, compress it, and stick it into an asm file so the code appears
869 as just bytes with a label in the data section'''
871 src = file(str(source[0]), 'r').read()
872 dst = file(str(target[0]), 'w')
874 pysource = py_sources_tnodes[source[0]]
875 compiled = compile(src, pysource.debugname, 'exec')
876 marshalled = marshal.dumps(compiled)
877 compressed = zlib.compress(marshalled)
880 # Some C/C++ compilers prepend an underscore to global symbol
881 # names, so if they're going to do that, we need to prepend that
882 # leading underscore to globals in the assembly file.
883 if env['LEADING_UNDERSCORE']:
884 sym = '_' + pysource.symname
886 sym = pysource.symname
890 print >>dst, ".globl %s_beg" % sym
891 print >>dst, ".globl %s_end" % sym
892 print >>dst, "%s_beg:" % sym
893 for i in xrange(0, len(data), step):
894 x = array.array('B', data[i:i+step])
895 print >>dst, ".byte", ','.join([str(d) for d in x])
896 print >>dst, "%s_end:" % sym
897 print >>dst, ".long %d" % len(marshalled)
899 for source in py_sources:
900 env.Command(source.assembly, source.tnode, objectifyPyFile)
901 Source(source.assembly)
903 # Generate init_python.cc which creates a bunch of EmbeddedPyModule
904 # structs that describe the embedded python code. One such struct
905 # contains information about the importer that python uses to get at
906 # the embedded files, and then there's a list of all of the rest that
907 # the importer uses to load the rest on demand.
908 py_sources_symbols = {}
909 for pysource in py_sources:
910 py_sources_symbols[pysource.symname] = pysource
911 def pythonInit(target, source, env):
912 dst = file(str(target[0]), 'w')
914 def dump_mod(sym, endchar=','):
915 pysource = py_sources_symbols[sym]
916 print >>dst, ' { "%s",' % pysource.arcname
917 print >>dst, ' "%s",' % pysource.modpath
918 print >>dst, ' %s_beg, %s_end,' % (sym, sym)
919 print >>dst, ' %s_end - %s_beg,' % (sym, sym)
920 print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
922 print >>dst, '#include "sim/init.hh"'
925 sym = sym.get_contents()
926 print >>dst, "extern const char %s_beg[], %s_end[];" % (sym, sym)
928 print >>dst, "const EmbeddedPyModule embeddedPyImporter = "
929 dump_mod("PyEMB_importer", endchar=';');
932 print >>dst, "const EmbeddedPyModule embeddedPyModules[] = {"
933 for i,sym in enumerate(source):
934 sym = sym.get_contents()
935 if sym == "PyEMB_importer":
936 # Skip the importer since we've already exported it
939 print >>dst, " { 0, 0, 0, 0, 0, 0 }"
942 symbols = [Value(s.symname) for s in py_sources]
943 env.Command('sim/init_python.cc', symbols, pythonInit)
944 Source('sim/init_python.cc')
946 ########################################################################
948 # Define binaries. Each different build type (debug, opt, etc.) gets
949 # a slightly different build environment.
952 # List of constructed environments to pass back to SConstruct
955 # This function adds the specified sources to the given build
956 # environment, and returns a list of all the corresponding SCons
957 # Object nodes (including an extra one for date.cc). We explicitly
958 # add the Object nodes so we can set up special dependencies for
960 def make_objs(sources, env, static):
962 XObject = env.StaticObject
964 XObject = env.SharedObject
966 objs = [ XObject(s) for s in sources ]
968 # make date.cc depend on all other objects so it always gets
969 # recompiled whenever anything else does
970 date_obj = XObject('base/date.cc')
972 # Make the generation of program_info.cc dependend on all
973 # the other cc files and the compiling of program_info.cc
974 # dependent on all the objects but program_info.o
975 pinfo_obj = XObject('base/program_info.cc')
976 env.Depends('base/program_info.cc', sources)
977 env.Depends(date_obj, objs)
978 env.Depends(pinfo_obj, objs)
979 objs.extend([date_obj, pinfo_obj])
982 # Function to create a new build environment as clone of current
983 # environment 'env' with modified object suffix and optional stripped
984 # binary. Additional keyword arguments are appended to corresponding
985 # build environment vars.
986 def makeEnv(label, objsfx, strip = False, **kwargs):
987 # SCons doesn't know to append a library suffix when there is a '.' in the
988 # name. Use '_' instead.
989 libname = 'm5_' + label
990 exename = 'm5.' + label
992 new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
993 new_env.Label = label
994 new_env.Append(**kwargs)
996 swig_env = new_env.Copy()
998 swig_env.Append(CCFLAGS='-Wno-uninitialized')
999 swig_env.Append(CCFLAGS='-Wno-sign-compare')
1000 swig_env.Append(CCFLAGS='-Wno-parentheses')
1002 static_objs = make_objs(cc_lib_sources, new_env, static=True)
1003 shared_objs = make_objs(cc_lib_sources, new_env, static=False)
1004 static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ]
1005 shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ]
1007 # First make a library of everything but main() so other programs can
1009 static_lib = new_env.StaticLibrary(libname, static_objs + static_objs)
1010 shared_lib = new_env.SharedLibrary(libname, shared_objs + shared_objs)
1012 for target, sources in unit_tests:
1013 objs = [ new_env.StaticObject(s) for s in sources ]
1014 new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib)
1016 # Now link a stub with main() and the static library.
1017 objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib
1019 unstripped_exe = exename + '.unstripped'
1020 new_env.Program(unstripped_exe, objects)
1021 if sys.platform == 'sunos5':
1022 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1024 cmd = 'strip $SOURCE -o $TARGET'
1025 targets = new_env.Command(exename, unstripped_exe, cmd)
1027 targets = new_env.Program(exename, objects)
1029 new_env.M5Binary = targets[0]
1030 envList.append(new_env)
1035 if sys.platform == 'sunos5':
1036 ccflags['debug'] = '-gstabs+'
1038 ccflags['debug'] = '-ggdb3'
1039 ccflags['opt'] = '-g -O3'
1040 ccflags['fast'] = '-O3'
1041 ccflags['prof'] = '-O3 -g -pg'
1043 ccflags['debug'] = '-g0'
1044 ccflags['opt'] = '-g -O'
1045 ccflags['fast'] = '-fast'
1046 ccflags['prof'] = '-fast -g -pg'
1048 ccflags['debug'] = '-g -O0'
1049 ccflags['opt'] = '-g -O'
1050 ccflags['fast'] = '-fast'
1051 ccflags['prof'] = '-fast -g -pg'
1053 print 'Unknown compiler, please fix compiler options'
1056 makeEnv('debug', '.do',
1057 CCFLAGS = Split(ccflags['debug']),
1058 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
1061 makeEnv('opt', '.o',
1062 CCFLAGS = Split(ccflags['opt']),
1063 CPPDEFINES = ['TRACING_ON=1'])
1066 makeEnv('fast', '.fo', strip = True,
1067 CCFLAGS = Split(ccflags['fast']),
1068 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
1071 makeEnv('prof', '.po',
1072 CCFLAGS = Split(ccflags['prof']),
1073 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],