SConscript (9982:b2bfc23f932c) SConscript (10196:be0e1724eb39)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
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.
16#
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.
28#
29# Authors: Nathan Binkert
30
31import array
32import bisect
33import imp
34import marshal
35import os
36import re
37import sys
38import zlib
39
40from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
41
42import SCons
43
44# This file defines how to build a particular configuration of gem5
45# based on variable settings in the 'env' build environment.
46
47Import('*')
48
49# Children need to see the environment
50Export('env')
51
52build_env = [(opt, env[opt]) for opt in export_vars]
53
54from m5.util import code_formatter, compareVersions
55
56########################################################################
57# Code for adding source files of various types
58#
59# When specifying a source file of some type, a set of guards can be
60# specified for that file. When get() is used to find the files, if
61# get specifies a set of filters, only files that match those filters
62# will be accepted (unspecified filters on files are assumed to be
63# false). Current filters are:
64# main -- specifies the gem5 main() function
65# skip_lib -- do not put this file into the gem5 library
66# <unittest> -- unit tests use filters based on the unit test name
67#
68# A parent can now be specified for a source file and default filter
69# values will be retrieved recursively from parents (children override
70# parents).
71#
72class SourceMeta(type):
73 '''Meta class for source files that keeps track of all files of a
74 particular type and has a get function for finding all functions
75 of a certain type that match a set of guards'''
76 def __init__(cls, name, bases, dict):
77 super(SourceMeta, cls).__init__(name, bases, dict)
78 cls.all = []
79
80 def get(cls, **guards):
81 '''Find all files that match the specified guards. If a source
82 file does not specify a flag, the default is False'''
83 for src in cls.all:
84 for flag,value in guards.iteritems():
85 # if the flag is found and has a different value, skip
86 # this file
87 if src.all_guards.get(flag, False) != value:
88 break
89 else:
90 yield src
91
92class SourceFile(object):
93 '''Base object that encapsulates the notion of a source file.
94 This includes, the source node, target node, various manipulations
95 of those. A source file also specifies a set of guards which
96 describing which builds the source file applies to. A parent can
97 also be specified to get default guards from'''
98 __metaclass__ = SourceMeta
99 def __init__(self, source, parent=None, **guards):
100 self.guards = guards
101 self.parent = parent
102
103 tnode = source
104 if not isinstance(source, SCons.Node.FS.File):
105 tnode = File(source)
106
107 self.tnode = tnode
108 self.snode = tnode.srcnode()
109
110 for base in type(self).__mro__:
111 if issubclass(base, SourceFile):
112 base.all.append(self)
113
114 @property
115 def filename(self):
116 return str(self.tnode)
117
118 @property
119 def dirname(self):
120 return dirname(self.filename)
121
122 @property
123 def basename(self):
124 return basename(self.filename)
125
126 @property
127 def extname(self):
128 index = self.basename.rfind('.')
129 if index <= 0:
130 # dot files aren't extensions
131 return self.basename, None
132
133 return self.basename[:index], self.basename[index+1:]
134
135 @property
136 def all_guards(self):
137 '''find all guards for this object getting default values
138 recursively from its parents'''
139 guards = {}
140 if self.parent:
141 guards.update(self.parent.guards)
142 guards.update(self.guards)
143 return guards
144
145 def __lt__(self, other): return self.filename < other.filename
146 def __le__(self, other): return self.filename <= other.filename
147 def __gt__(self, other): return self.filename > other.filename
148 def __ge__(self, other): return self.filename >= other.filename
149 def __eq__(self, other): return self.filename == other.filename
150 def __ne__(self, other): return self.filename != other.filename
151
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
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.
16#
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.
28#
29# Authors: Nathan Binkert
30
31import array
32import bisect
33import imp
34import marshal
35import os
36import re
37import sys
38import zlib
39
40from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
41
42import SCons
43
44# This file defines how to build a particular configuration of gem5
45# based on variable settings in the 'env' build environment.
46
47Import('*')
48
49# Children need to see the environment
50Export('env')
51
52build_env = [(opt, env[opt]) for opt in export_vars]
53
54from m5.util import code_formatter, compareVersions
55
56########################################################################
57# Code for adding source files of various types
58#
59# When specifying a source file of some type, a set of guards can be
60# specified for that file. When get() is used to find the files, if
61# get specifies a set of filters, only files that match those filters
62# will be accepted (unspecified filters on files are assumed to be
63# false). Current filters are:
64# main -- specifies the gem5 main() function
65# skip_lib -- do not put this file into the gem5 library
66# <unittest> -- unit tests use filters based on the unit test name
67#
68# A parent can now be specified for a source file and default filter
69# values will be retrieved recursively from parents (children override
70# parents).
71#
72class SourceMeta(type):
73 '''Meta class for source files that keeps track of all files of a
74 particular type and has a get function for finding all functions
75 of a certain type that match a set of guards'''
76 def __init__(cls, name, bases, dict):
77 super(SourceMeta, cls).__init__(name, bases, dict)
78 cls.all = []
79
80 def get(cls, **guards):
81 '''Find all files that match the specified guards. If a source
82 file does not specify a flag, the default is False'''
83 for src in cls.all:
84 for flag,value in guards.iteritems():
85 # if the flag is found and has a different value, skip
86 # this file
87 if src.all_guards.get(flag, False) != value:
88 break
89 else:
90 yield src
91
92class SourceFile(object):
93 '''Base object that encapsulates the notion of a source file.
94 This includes, the source node, target node, various manipulations
95 of those. A source file also specifies a set of guards which
96 describing which builds the source file applies to. A parent can
97 also be specified to get default guards from'''
98 __metaclass__ = SourceMeta
99 def __init__(self, source, parent=None, **guards):
100 self.guards = guards
101 self.parent = parent
102
103 tnode = source
104 if not isinstance(source, SCons.Node.FS.File):
105 tnode = File(source)
106
107 self.tnode = tnode
108 self.snode = tnode.srcnode()
109
110 for base in type(self).__mro__:
111 if issubclass(base, SourceFile):
112 base.all.append(self)
113
114 @property
115 def filename(self):
116 return str(self.tnode)
117
118 @property
119 def dirname(self):
120 return dirname(self.filename)
121
122 @property
123 def basename(self):
124 return basename(self.filename)
125
126 @property
127 def extname(self):
128 index = self.basename.rfind('.')
129 if index <= 0:
130 # dot files aren't extensions
131 return self.basename, None
132
133 return self.basename[:index], self.basename[index+1:]
134
135 @property
136 def all_guards(self):
137 '''find all guards for this object getting default values
138 recursively from its parents'''
139 guards = {}
140 if self.parent:
141 guards.update(self.parent.guards)
142 guards.update(self.guards)
143 return guards
144
145 def __lt__(self, other): return self.filename < other.filename
146 def __le__(self, other): return self.filename <= other.filename
147 def __gt__(self, other): return self.filename > other.filename
148 def __ge__(self, other): return self.filename >= other.filename
149 def __eq__(self, other): return self.filename == other.filename
150 def __ne__(self, other): return self.filename != other.filename
151
152 @staticmethod
153 def done():
154 def disabled(cls, name, *ignored):
155 raise RuntimeError("Additional SourceFile '%s'" % name,\
156 "declared, but targets deps are already fixed.")
157 SourceFile.__init__ = disabled
158
159
152class Source(SourceFile):
153 '''Add a c/c++ source file to the build'''
154 def __init__(self, source, Werror=True, swig=False, **guards):
155 '''specify the source file, and any guards'''
156 super(Source, self).__init__(source, **guards)
157
158 self.Werror = Werror
159 self.swig = swig
160
161class PySource(SourceFile):
162 '''Add a python source file to the named package'''
163 invalid_sym_char = re.compile('[^A-z0-9_]')
164 modules = {}
165 tnodes = {}
166 symnames = {}
167
168 def __init__(self, package, source, **guards):
169 '''specify the python package, the source file, and any guards'''
170 super(PySource, self).__init__(source, **guards)
171
172 modname,ext = self.extname
173 assert ext == 'py'
174
175 if package:
176 path = package.split('.')
177 else:
178 path = []
179
180 modpath = path[:]
181 if modname != '__init__':
182 modpath += [ modname ]
183 modpath = '.'.join(modpath)
184
185 arcpath = path + [ self.basename ]
186 abspath = self.snode.abspath
187 if not exists(abspath):
188 abspath = self.tnode.abspath
189
190 self.package = package
191 self.modname = modname
192 self.modpath = modpath
193 self.arcname = joinpath(*arcpath)
194 self.abspath = abspath
195 self.compiled = File(self.filename + 'c')
196 self.cpp = File(self.filename + '.cc')
197 self.symname = PySource.invalid_sym_char.sub('_', modpath)
198
199 PySource.modules[modpath] = self
200 PySource.tnodes[self.tnode] = self
201 PySource.symnames[self.symname] = self
202
203class SimObject(PySource):
204 '''Add a SimObject python file as a python source object and add
205 it to a list of sim object modules'''
206
207 fixed = False
208 modnames = []
209
210 def __init__(self, source, **guards):
211 '''Specify the source file and any guards (automatically in
212 the m5.objects package)'''
213 super(SimObject, self).__init__('m5.objects', source, **guards)
214 if self.fixed:
215 raise AttributeError, "Too late to call SimObject now."
216
217 bisect.insort_right(SimObject.modnames, self.modname)
218
219class SwigSource(SourceFile):
220 '''Add a swig file to build'''
221
222 def __init__(self, package, source, **guards):
223 '''Specify the python package, the source file, and any guards'''
224 super(SwigSource, self).__init__(source, **guards)
225
226 modname,ext = self.extname
227 assert ext == 'i'
228
229 self.module = modname
230 cc_file = joinpath(self.dirname, modname + '_wrap.cc')
231 py_file = joinpath(self.dirname, modname + '.py')
232
233 self.cc_source = Source(cc_file, swig=True, parent=self)
234 self.py_source = PySource(package, py_file, parent=self)
235
236class ProtoBuf(SourceFile):
237 '''Add a Protocol Buffer to build'''
238
239 def __init__(self, source, **guards):
240 '''Specify the source file, and any guards'''
241 super(ProtoBuf, self).__init__(source, **guards)
242
243 # Get the file name and the extension
244 modname,ext = self.extname
245 assert ext == 'proto'
246
247 # Currently, we stick to generating the C++ headers, so we
248 # only need to track the source and header.
249 self.cc_file = File(modname + '.pb.cc')
250 self.hh_file = File(modname + '.pb.h')
251
252class UnitTest(object):
253 '''Create a UnitTest'''
254
255 all = []
256 def __init__(self, target, *sources, **kwargs):
257 '''Specify the target name and any sources. Sources that are
258 not SourceFiles are evalued with Source(). All files are
259 guarded with a guard of the same name as the UnitTest
260 target.'''
261
262 srcs = []
263 for src in sources:
264 if not isinstance(src, SourceFile):
265 src = Source(src, skip_lib=True)
266 src.guards[target] = True
267 srcs.append(src)
268
269 self.sources = srcs
270 self.target = target
271 self.main = kwargs.get('main', False)
272 UnitTest.all.append(self)
273
274# Children should have access
275Export('Source')
276Export('PySource')
277Export('SimObject')
278Export('SwigSource')
279Export('ProtoBuf')
280Export('UnitTest')
281
282########################################################################
283#
284# Debug Flags
285#
286debug_flags = {}
287def DebugFlag(name, desc=None):
288 if name in debug_flags:
289 raise AttributeError, "Flag %s already specified" % name
290 debug_flags[name] = (name, (), desc)
291
292def CompoundFlag(name, flags, desc=None):
293 if name in debug_flags:
294 raise AttributeError, "Flag %s already specified" % name
295
296 compound = tuple(flags)
297 debug_flags[name] = (name, compound, desc)
298
299Export('DebugFlag')
300Export('CompoundFlag')
301
302########################################################################
303#
304# Set some compiler variables
305#
306
307# Include file paths are rooted in this directory. SCons will
308# automatically expand '.' to refer to both the source directory and
309# the corresponding build directory to pick up generated include
310# files.
311env.Append(CPPPATH=Dir('.'))
312
313for extra_dir in extras_dir_list:
314 env.Append(CPPPATH=Dir(extra_dir))
315
316# Workaround for bug in SCons version > 0.97d20071212
317# Scons bug id: 2006 gem5 Bug id: 308
318for root, dirs, files in os.walk(base_dir, topdown=True):
319 Dir(root[len(base_dir) + 1:])
320
321########################################################################
322#
323# Walk the tree and execute all SConscripts in subdirectories
324#
325
326here = Dir('.').srcnode().abspath
327for root, dirs, files in os.walk(base_dir, topdown=True):
328 if root == here:
329 # we don't want to recurse back into this SConscript
330 continue
331
332 if 'SConscript' in files:
333 build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
334 SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
335
336for extra_dir in extras_dir_list:
337 prefix_len = len(dirname(extra_dir)) + 1
338
339 # Also add the corresponding build directory to pick up generated
340 # include files.
341 env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
342
343 for root, dirs, files in os.walk(extra_dir, topdown=True):
344 # if build lives in the extras directory, don't walk down it
345 if 'build' in dirs:
346 dirs.remove('build')
347
348 if 'SConscript' in files:
349 build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
350 SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
351
352for opt in export_vars:
353 env.ConfigFile(opt)
354
355def makeTheISA(source, target, env):
356 isas = [ src.get_contents() for src in source ]
357 target_isa = env['TARGET_ISA']
358 def define(isa):
359 return isa.upper() + '_ISA'
360
361 def namespace(isa):
362 return isa[0].upper() + isa[1:].lower() + 'ISA'
363
364
365 code = code_formatter()
366 code('''\
367#ifndef __CONFIG_THE_ISA_HH__
368#define __CONFIG_THE_ISA_HH__
369
370''')
371
372 for i,isa in enumerate(isas):
373 code('#define $0 $1', define(isa), i + 1)
374
375 code('''
376
377#define THE_ISA ${{define(target_isa)}}
378#define TheISA ${{namespace(target_isa)}}
379#define THE_ISA_STR "${{target_isa}}"
380
381#endif // __CONFIG_THE_ISA_HH__''')
382
383 code.write(str(target[0]))
384
385env.Command('config/the_isa.hh', map(Value, all_isa_list),
386 MakeAction(makeTheISA, Transform("CFG ISA", 0)))
387
388########################################################################
389#
390# Prevent any SimObjects from being added after this point, they
391# should all have been added in the SConscripts above
392#
393SimObject.fixed = True
394
395class DictImporter(object):
396 '''This importer takes a dictionary of arbitrary module names that
397 map to arbitrary filenames.'''
398 def __init__(self, modules):
399 self.modules = modules
400 self.installed = set()
401
402 def __del__(self):
403 self.unload()
404
405 def unload(self):
406 import sys
407 for module in self.installed:
408 del sys.modules[module]
409 self.installed = set()
410
411 def find_module(self, fullname, path):
412 if fullname == 'm5.defines':
413 return self
414
415 if fullname == 'm5.objects':
416 return self
417
418 if fullname.startswith('m5.internal'):
419 return None
420
421 source = self.modules.get(fullname, None)
422 if source is not None and fullname.startswith('m5.objects'):
423 return self
424
425 return None
426
427 def load_module(self, fullname):
428 mod = imp.new_module(fullname)
429 sys.modules[fullname] = mod
430 self.installed.add(fullname)
431
432 mod.__loader__ = self
433 if fullname == 'm5.objects':
434 mod.__path__ = fullname.split('.')
435 return mod
436
437 if fullname == 'm5.defines':
438 mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
439 return mod
440
441 source = self.modules[fullname]
442 if source.modname == '__init__':
443 mod.__path__ = source.modpath
444 mod.__file__ = source.abspath
445
446 exec file(source.abspath, 'r') in mod.__dict__
447
448 return mod
449
450import m5.SimObject
451import m5.params
452from m5.util import code_formatter
453
454m5.SimObject.clear()
455m5.params.clear()
456
457# install the python importer so we can grab stuff from the source
458# tree itself. We can't have SimObjects added after this point or
459# else we won't know about them for the rest of the stuff.
460importer = DictImporter(PySource.modules)
461sys.meta_path[0:0] = [ importer ]
462
463# import all sim objects so we can populate the all_objects list
464# make sure that we're working with a list, then let's sort it
465for modname in SimObject.modnames:
466 exec('from m5.objects import %s' % modname)
467
468# we need to unload all of the currently imported modules so that they
469# will be re-imported the next time the sconscript is run
470importer.unload()
471sys.meta_path.remove(importer)
472
473sim_objects = m5.SimObject.allClasses
474all_enums = m5.params.allEnums
475
476if m5.SimObject.noCxxHeader:
477 print >> sys.stderr, \
478 "warning: At least one SimObject lacks a header specification. " \
479 "This can cause unexpected results in the generated SWIG " \
480 "wrappers."
481
482# Find param types that need to be explicitly wrapped with swig.
483# These will be recognized because the ParamDesc will have a
484# swig_decl() method. Most param types are based on types that don't
485# need this, either because they're based on native types (like Int)
486# or because they're SimObjects (which get swigged independently).
487# For now the only things handled here are VectorParam types.
488params_to_swig = {}
489for name,obj in sorted(sim_objects.iteritems()):
490 for param in obj._params.local.values():
491 # load the ptype attribute now because it depends on the
492 # current version of SimObject.allClasses, but when scons
493 # actually uses the value, all versions of
494 # SimObject.allClasses will have been loaded
495 param.ptype
496
497 if not hasattr(param, 'swig_decl'):
498 continue
499 pname = param.ptype_str
500 if pname not in params_to_swig:
501 params_to_swig[pname] = param
502
503########################################################################
504#
505# calculate extra dependencies
506#
507module_depends = ["m5", "m5.SimObject", "m5.params"]
508depends = [ PySource.modules[dep].snode for dep in module_depends ]
509
510########################################################################
511#
512# Commands for the basic automatically generated python files
513#
514
515# Generate Python file containing a dict specifying the current
516# buildEnv flags.
517def makeDefinesPyFile(target, source, env):
518 build_env = source[0].get_contents()
519
520 code = code_formatter()
521 code("""
522import m5.internal
523import m5.util
524
525buildEnv = m5.util.SmartDict($build_env)
526
527compileDate = m5.internal.core.compileDate
528_globals = globals()
529for key,val in m5.internal.core.__dict__.iteritems():
530 if key.startswith('flag_'):
531 flag = key[5:]
532 _globals[flag] = val
533del _globals
534""")
535 code.write(target[0].abspath)
536
537defines_info = Value(build_env)
538# Generate a file with all of the compile options in it
539env.Command('python/m5/defines.py', defines_info,
540 MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
541PySource('m5', 'python/m5/defines.py')
542
543# Generate python file containing info about the M5 source code
544def makeInfoPyFile(target, source, env):
545 code = code_formatter()
546 for src in source:
547 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
548 code('$src = ${{repr(data)}}')
549 code.write(str(target[0]))
550
551# Generate a file that wraps the basic top level files
552env.Command('python/m5/info.py',
553 [ '#/COPYING', '#/LICENSE', '#/README', ],
554 MakeAction(makeInfoPyFile, Transform("INFO")))
555PySource('m5', 'python/m5/info.py')
556
557########################################################################
558#
559# Create all of the SimObject param headers and enum headers
560#
561
562def createSimObjectParamStruct(target, source, env):
563 assert len(target) == 1 and len(source) == 1
564
565 name = str(source[0].get_contents())
566 obj = sim_objects[name]
567
568 code = code_formatter()
569 obj.cxx_param_decl(code)
570 code.write(target[0].abspath)
571
572def createParamSwigWrapper(target, source, env):
573 assert len(target) == 1 and len(source) == 1
574
575 name = str(source[0].get_contents())
576 param = params_to_swig[name]
577
578 code = code_formatter()
579 param.swig_decl(code)
580 code.write(target[0].abspath)
581
582def createEnumStrings(target, source, env):
583 assert len(target) == 1 and len(source) == 1
584
585 name = str(source[0].get_contents())
586 obj = all_enums[name]
587
588 code = code_formatter()
589 obj.cxx_def(code)
590 code.write(target[0].abspath)
591
592def createEnumDecls(target, source, env):
593 assert len(target) == 1 and len(source) == 1
594
595 name = str(source[0].get_contents())
596 obj = all_enums[name]
597
598 code = code_formatter()
599 obj.cxx_decl(code)
600 code.write(target[0].abspath)
601
602def createEnumSwigWrapper(target, source, env):
603 assert len(target) == 1 and len(source) == 1
604
605 name = str(source[0].get_contents())
606 obj = all_enums[name]
607
608 code = code_formatter()
609 obj.swig_decl(code)
610 code.write(target[0].abspath)
611
612def createSimObjectSwigWrapper(target, source, env):
613 name = source[0].get_contents()
614 obj = sim_objects[name]
615
616 code = code_formatter()
617 obj.swig_decl(code)
618 code.write(target[0].abspath)
619
620# Generate all of the SimObject param C++ struct header files
621params_hh_files = []
622for name,simobj in sorted(sim_objects.iteritems()):
623 py_source = PySource.modules[simobj.__module__]
624 extra_deps = [ py_source.tnode ]
625
626 hh_file = File('params/%s.hh' % name)
627 params_hh_files.append(hh_file)
628 env.Command(hh_file, Value(name),
629 MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
630 env.Depends(hh_file, depends + extra_deps)
631
632# Generate any needed param SWIG wrapper files
633params_i_files = []
634for name,param in params_to_swig.iteritems():
635 i_file = File('python/m5/internal/%s.i' % (param.swig_module_name()))
636 params_i_files.append(i_file)
637 env.Command(i_file, Value(name),
638 MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
639 env.Depends(i_file, depends)
640 SwigSource('m5.internal', i_file)
641
642# Generate all enum header files
643for name,enum in sorted(all_enums.iteritems()):
644 py_source = PySource.modules[enum.__module__]
645 extra_deps = [ py_source.tnode ]
646
647 cc_file = File('enums/%s.cc' % name)
648 env.Command(cc_file, Value(name),
649 MakeAction(createEnumStrings, Transform("ENUM STR")))
650 env.Depends(cc_file, depends + extra_deps)
651 Source(cc_file)
652
653 hh_file = File('enums/%s.hh' % name)
654 env.Command(hh_file, Value(name),
655 MakeAction(createEnumDecls, Transform("ENUMDECL")))
656 env.Depends(hh_file, depends + extra_deps)
657
658 i_file = File('python/m5/internal/enum_%s.i' % name)
659 env.Command(i_file, Value(name),
660 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
661 env.Depends(i_file, depends + extra_deps)
662 SwigSource('m5.internal', i_file)
663
664# Generate SimObject SWIG wrapper files
665for name,simobj in sim_objects.iteritems():
666 py_source = PySource.modules[simobj.__module__]
667 extra_deps = [ py_source.tnode ]
668
669 i_file = File('python/m5/internal/param_%s.i' % name)
670 env.Command(i_file, Value(name),
671 MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
672 env.Depends(i_file, depends + extra_deps)
673 SwigSource('m5.internal', i_file)
674
675# Generate the main swig init file
676def makeEmbeddedSwigInit(target, source, env):
677 code = code_formatter()
678 module = source[0].get_contents()
679 code('''\
680#include "sim/init.hh"
681
682extern "C" {
683 void init_${module}();
684}
685
686EmbeddedSwig embed_swig_${module}(init_${module});
687''')
688 code.write(str(target[0]))
689
690# Build all swig modules
691for swig in SwigSource.all:
692 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
693 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
694 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
695 cc_file = str(swig.tnode)
696 init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
697 env.Command(init_file, Value(swig.module),
698 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
699 Source(init_file, **swig.guards)
700
701# Build all protocol buffers if we have got protoc and protobuf available
702if env['HAVE_PROTOBUF']:
703 for proto in ProtoBuf.all:
704 # Use both the source and header as the target, and the .proto
705 # file as the source. When executing the protoc compiler, also
706 # specify the proto_path to avoid having the generated files
707 # include the path.
708 env.Command([proto.cc_file, proto.hh_file], proto.tnode,
709 MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
710 '--proto_path ${SOURCE.dir} $SOURCE',
711 Transform("PROTOC")))
712
713 # Add the C++ source file
714 Source(proto.cc_file, **proto.guards)
715elif ProtoBuf.all:
716 print 'Got protobuf to build, but lacks support!'
717 Exit(1)
718
719#
720# Handle debug flags
721#
722def makeDebugFlagCC(target, source, env):
723 assert(len(target) == 1 and len(source) == 1)
724
725 val = eval(source[0].get_contents())
726 name, compound, desc = val
727 compound = list(sorted(compound))
728
729 code = code_formatter()
730
731 # file header
732 code('''
733/*
734 * DO NOT EDIT THIS FILE! Automatically generated
735 */
736
737#include "base/debug.hh"
738''')
739
740 for flag in compound:
741 code('#include "debug/$flag.hh"')
742 code()
743 code('namespace Debug {')
744 code()
745
746 if not compound:
747 code('SimpleFlag $name("$name", "$desc");')
748 else:
749 code('CompoundFlag $name("$name", "$desc",')
750 code.indent()
751 last = len(compound) - 1
752 for i,flag in enumerate(compound):
753 if i != last:
754 code('$flag,')
755 else:
756 code('$flag);')
757 code.dedent()
758
759 code()
760 code('} // namespace Debug')
761
762 code.write(str(target[0]))
763
764def makeDebugFlagHH(target, source, env):
765 assert(len(target) == 1 and len(source) == 1)
766
767 val = eval(source[0].get_contents())
768 name, compound, desc = val
769
770 code = code_formatter()
771
772 # file header boilerplate
773 code('''\
774/*
775 * DO NOT EDIT THIS FILE!
776 *
777 * Automatically generated by SCons
778 */
779
780#ifndef __DEBUG_${name}_HH__
781#define __DEBUG_${name}_HH__
782
783namespace Debug {
784''')
785
786 if compound:
787 code('class CompoundFlag;')
788 code('class SimpleFlag;')
789
790 if compound:
791 code('extern CompoundFlag $name;')
792 for flag in compound:
793 code('extern SimpleFlag $flag;')
794 else:
795 code('extern SimpleFlag $name;')
796
797 code('''
798}
799
800#endif // __DEBUG_${name}_HH__
801''')
802
803 code.write(str(target[0]))
804
805for name,flag in sorted(debug_flags.iteritems()):
806 n, compound, desc = flag
807 assert n == name
808
809 env.Command('debug/%s.hh' % name, Value(flag),
810 MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
811 env.Command('debug/%s.cc' % name, Value(flag),
812 MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
813 Source('debug/%s.cc' % name)
814
815# Embed python files. All .py files that have been indicated by a
816# PySource() call in a SConscript need to be embedded into the M5
817# library. To do that, we compile the file to byte code, marshal the
818# byte code, compress it, and then generate a c++ file that
819# inserts the result into an array.
820def embedPyFile(target, source, env):
821 def c_str(string):
822 if string is None:
823 return "0"
824 return '"%s"' % string
825
826 '''Action function to compile a .py into a code object, marshal
827 it, compress it, and stick it into an asm file so the code appears
828 as just bytes with a label in the data section'''
829
830 src = file(str(source[0]), 'r').read()
831
832 pysource = PySource.tnodes[source[0]]
833 compiled = compile(src, pysource.abspath, 'exec')
834 marshalled = marshal.dumps(compiled)
835 compressed = zlib.compress(marshalled)
836 data = compressed
837 sym = pysource.symname
838
839 code = code_formatter()
840 code('''\
841#include "sim/init.hh"
842
843namespace {
844
845const uint8_t data_${sym}[] = {
846''')
847 code.indent()
848 step = 16
849 for i in xrange(0, len(data), step):
850 x = array.array('B', data[i:i+step])
851 code(''.join('%d,' % d for d in x))
852 code.dedent()
853
854 code('''};
855
856EmbeddedPython embedded_${sym}(
857 ${{c_str(pysource.arcname)}},
858 ${{c_str(pysource.abspath)}},
859 ${{c_str(pysource.modpath)}},
860 data_${sym},
861 ${{len(data)}},
862 ${{len(marshalled)}});
863
864} // anonymous namespace
865''')
866 code.write(str(target[0]))
867
868for source in PySource.all:
869 env.Command(source.cpp, source.tnode,
870 MakeAction(embedPyFile, Transform("EMBED PY")))
871 Source(source.cpp)
872
873########################################################################
874#
875# Define binaries. Each different build type (debug, opt, etc.) gets
876# a slightly different build environment.
877#
878
879# List of constructed environments to pass back to SConstruct
160class Source(SourceFile):
161 '''Add a c/c++ source file to the build'''
162 def __init__(self, source, Werror=True, swig=False, **guards):
163 '''specify the source file, and any guards'''
164 super(Source, self).__init__(source, **guards)
165
166 self.Werror = Werror
167 self.swig = swig
168
169class PySource(SourceFile):
170 '''Add a python source file to the named package'''
171 invalid_sym_char = re.compile('[^A-z0-9_]')
172 modules = {}
173 tnodes = {}
174 symnames = {}
175
176 def __init__(self, package, source, **guards):
177 '''specify the python package, the source file, and any guards'''
178 super(PySource, self).__init__(source, **guards)
179
180 modname,ext = self.extname
181 assert ext == 'py'
182
183 if package:
184 path = package.split('.')
185 else:
186 path = []
187
188 modpath = path[:]
189 if modname != '__init__':
190 modpath += [ modname ]
191 modpath = '.'.join(modpath)
192
193 arcpath = path + [ self.basename ]
194 abspath = self.snode.abspath
195 if not exists(abspath):
196 abspath = self.tnode.abspath
197
198 self.package = package
199 self.modname = modname
200 self.modpath = modpath
201 self.arcname = joinpath(*arcpath)
202 self.abspath = abspath
203 self.compiled = File(self.filename + 'c')
204 self.cpp = File(self.filename + '.cc')
205 self.symname = PySource.invalid_sym_char.sub('_', modpath)
206
207 PySource.modules[modpath] = self
208 PySource.tnodes[self.tnode] = self
209 PySource.symnames[self.symname] = self
210
211class SimObject(PySource):
212 '''Add a SimObject python file as a python source object and add
213 it to a list of sim object modules'''
214
215 fixed = False
216 modnames = []
217
218 def __init__(self, source, **guards):
219 '''Specify the source file and any guards (automatically in
220 the m5.objects package)'''
221 super(SimObject, self).__init__('m5.objects', source, **guards)
222 if self.fixed:
223 raise AttributeError, "Too late to call SimObject now."
224
225 bisect.insort_right(SimObject.modnames, self.modname)
226
227class SwigSource(SourceFile):
228 '''Add a swig file to build'''
229
230 def __init__(self, package, source, **guards):
231 '''Specify the python package, the source file, and any guards'''
232 super(SwigSource, self).__init__(source, **guards)
233
234 modname,ext = self.extname
235 assert ext == 'i'
236
237 self.module = modname
238 cc_file = joinpath(self.dirname, modname + '_wrap.cc')
239 py_file = joinpath(self.dirname, modname + '.py')
240
241 self.cc_source = Source(cc_file, swig=True, parent=self)
242 self.py_source = PySource(package, py_file, parent=self)
243
244class ProtoBuf(SourceFile):
245 '''Add a Protocol Buffer to build'''
246
247 def __init__(self, source, **guards):
248 '''Specify the source file, and any guards'''
249 super(ProtoBuf, self).__init__(source, **guards)
250
251 # Get the file name and the extension
252 modname,ext = self.extname
253 assert ext == 'proto'
254
255 # Currently, we stick to generating the C++ headers, so we
256 # only need to track the source and header.
257 self.cc_file = File(modname + '.pb.cc')
258 self.hh_file = File(modname + '.pb.h')
259
260class UnitTest(object):
261 '''Create a UnitTest'''
262
263 all = []
264 def __init__(self, target, *sources, **kwargs):
265 '''Specify the target name and any sources. Sources that are
266 not SourceFiles are evalued with Source(). All files are
267 guarded with a guard of the same name as the UnitTest
268 target.'''
269
270 srcs = []
271 for src in sources:
272 if not isinstance(src, SourceFile):
273 src = Source(src, skip_lib=True)
274 src.guards[target] = True
275 srcs.append(src)
276
277 self.sources = srcs
278 self.target = target
279 self.main = kwargs.get('main', False)
280 UnitTest.all.append(self)
281
282# Children should have access
283Export('Source')
284Export('PySource')
285Export('SimObject')
286Export('SwigSource')
287Export('ProtoBuf')
288Export('UnitTest')
289
290########################################################################
291#
292# Debug Flags
293#
294debug_flags = {}
295def DebugFlag(name, desc=None):
296 if name in debug_flags:
297 raise AttributeError, "Flag %s already specified" % name
298 debug_flags[name] = (name, (), desc)
299
300def CompoundFlag(name, flags, desc=None):
301 if name in debug_flags:
302 raise AttributeError, "Flag %s already specified" % name
303
304 compound = tuple(flags)
305 debug_flags[name] = (name, compound, desc)
306
307Export('DebugFlag')
308Export('CompoundFlag')
309
310########################################################################
311#
312# Set some compiler variables
313#
314
315# Include file paths are rooted in this directory. SCons will
316# automatically expand '.' to refer to both the source directory and
317# the corresponding build directory to pick up generated include
318# files.
319env.Append(CPPPATH=Dir('.'))
320
321for extra_dir in extras_dir_list:
322 env.Append(CPPPATH=Dir(extra_dir))
323
324# Workaround for bug in SCons version > 0.97d20071212
325# Scons bug id: 2006 gem5 Bug id: 308
326for root, dirs, files in os.walk(base_dir, topdown=True):
327 Dir(root[len(base_dir) + 1:])
328
329########################################################################
330#
331# Walk the tree and execute all SConscripts in subdirectories
332#
333
334here = Dir('.').srcnode().abspath
335for root, dirs, files in os.walk(base_dir, topdown=True):
336 if root == here:
337 # we don't want to recurse back into this SConscript
338 continue
339
340 if 'SConscript' in files:
341 build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
342 SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
343
344for extra_dir in extras_dir_list:
345 prefix_len = len(dirname(extra_dir)) + 1
346
347 # Also add the corresponding build directory to pick up generated
348 # include files.
349 env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
350
351 for root, dirs, files in os.walk(extra_dir, topdown=True):
352 # if build lives in the extras directory, don't walk down it
353 if 'build' in dirs:
354 dirs.remove('build')
355
356 if 'SConscript' in files:
357 build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
358 SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
359
360for opt in export_vars:
361 env.ConfigFile(opt)
362
363def makeTheISA(source, target, env):
364 isas = [ src.get_contents() for src in source ]
365 target_isa = env['TARGET_ISA']
366 def define(isa):
367 return isa.upper() + '_ISA'
368
369 def namespace(isa):
370 return isa[0].upper() + isa[1:].lower() + 'ISA'
371
372
373 code = code_formatter()
374 code('''\
375#ifndef __CONFIG_THE_ISA_HH__
376#define __CONFIG_THE_ISA_HH__
377
378''')
379
380 for i,isa in enumerate(isas):
381 code('#define $0 $1', define(isa), i + 1)
382
383 code('''
384
385#define THE_ISA ${{define(target_isa)}}
386#define TheISA ${{namespace(target_isa)}}
387#define THE_ISA_STR "${{target_isa}}"
388
389#endif // __CONFIG_THE_ISA_HH__''')
390
391 code.write(str(target[0]))
392
393env.Command('config/the_isa.hh', map(Value, all_isa_list),
394 MakeAction(makeTheISA, Transform("CFG ISA", 0)))
395
396########################################################################
397#
398# Prevent any SimObjects from being added after this point, they
399# should all have been added in the SConscripts above
400#
401SimObject.fixed = True
402
403class DictImporter(object):
404 '''This importer takes a dictionary of arbitrary module names that
405 map to arbitrary filenames.'''
406 def __init__(self, modules):
407 self.modules = modules
408 self.installed = set()
409
410 def __del__(self):
411 self.unload()
412
413 def unload(self):
414 import sys
415 for module in self.installed:
416 del sys.modules[module]
417 self.installed = set()
418
419 def find_module(self, fullname, path):
420 if fullname == 'm5.defines':
421 return self
422
423 if fullname == 'm5.objects':
424 return self
425
426 if fullname.startswith('m5.internal'):
427 return None
428
429 source = self.modules.get(fullname, None)
430 if source is not None and fullname.startswith('m5.objects'):
431 return self
432
433 return None
434
435 def load_module(self, fullname):
436 mod = imp.new_module(fullname)
437 sys.modules[fullname] = mod
438 self.installed.add(fullname)
439
440 mod.__loader__ = self
441 if fullname == 'm5.objects':
442 mod.__path__ = fullname.split('.')
443 return mod
444
445 if fullname == 'm5.defines':
446 mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
447 return mod
448
449 source = self.modules[fullname]
450 if source.modname == '__init__':
451 mod.__path__ = source.modpath
452 mod.__file__ = source.abspath
453
454 exec file(source.abspath, 'r') in mod.__dict__
455
456 return mod
457
458import m5.SimObject
459import m5.params
460from m5.util import code_formatter
461
462m5.SimObject.clear()
463m5.params.clear()
464
465# install the python importer so we can grab stuff from the source
466# tree itself. We can't have SimObjects added after this point or
467# else we won't know about them for the rest of the stuff.
468importer = DictImporter(PySource.modules)
469sys.meta_path[0:0] = [ importer ]
470
471# import all sim objects so we can populate the all_objects list
472# make sure that we're working with a list, then let's sort it
473for modname in SimObject.modnames:
474 exec('from m5.objects import %s' % modname)
475
476# we need to unload all of the currently imported modules so that they
477# will be re-imported the next time the sconscript is run
478importer.unload()
479sys.meta_path.remove(importer)
480
481sim_objects = m5.SimObject.allClasses
482all_enums = m5.params.allEnums
483
484if m5.SimObject.noCxxHeader:
485 print >> sys.stderr, \
486 "warning: At least one SimObject lacks a header specification. " \
487 "This can cause unexpected results in the generated SWIG " \
488 "wrappers."
489
490# Find param types that need to be explicitly wrapped with swig.
491# These will be recognized because the ParamDesc will have a
492# swig_decl() method. Most param types are based on types that don't
493# need this, either because they're based on native types (like Int)
494# or because they're SimObjects (which get swigged independently).
495# For now the only things handled here are VectorParam types.
496params_to_swig = {}
497for name,obj in sorted(sim_objects.iteritems()):
498 for param in obj._params.local.values():
499 # load the ptype attribute now because it depends on the
500 # current version of SimObject.allClasses, but when scons
501 # actually uses the value, all versions of
502 # SimObject.allClasses will have been loaded
503 param.ptype
504
505 if not hasattr(param, 'swig_decl'):
506 continue
507 pname = param.ptype_str
508 if pname not in params_to_swig:
509 params_to_swig[pname] = param
510
511########################################################################
512#
513# calculate extra dependencies
514#
515module_depends = ["m5", "m5.SimObject", "m5.params"]
516depends = [ PySource.modules[dep].snode for dep in module_depends ]
517
518########################################################################
519#
520# Commands for the basic automatically generated python files
521#
522
523# Generate Python file containing a dict specifying the current
524# buildEnv flags.
525def makeDefinesPyFile(target, source, env):
526 build_env = source[0].get_contents()
527
528 code = code_formatter()
529 code("""
530import m5.internal
531import m5.util
532
533buildEnv = m5.util.SmartDict($build_env)
534
535compileDate = m5.internal.core.compileDate
536_globals = globals()
537for key,val in m5.internal.core.__dict__.iteritems():
538 if key.startswith('flag_'):
539 flag = key[5:]
540 _globals[flag] = val
541del _globals
542""")
543 code.write(target[0].abspath)
544
545defines_info = Value(build_env)
546# Generate a file with all of the compile options in it
547env.Command('python/m5/defines.py', defines_info,
548 MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
549PySource('m5', 'python/m5/defines.py')
550
551# Generate python file containing info about the M5 source code
552def makeInfoPyFile(target, source, env):
553 code = code_formatter()
554 for src in source:
555 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
556 code('$src = ${{repr(data)}}')
557 code.write(str(target[0]))
558
559# Generate a file that wraps the basic top level files
560env.Command('python/m5/info.py',
561 [ '#/COPYING', '#/LICENSE', '#/README', ],
562 MakeAction(makeInfoPyFile, Transform("INFO")))
563PySource('m5', 'python/m5/info.py')
564
565########################################################################
566#
567# Create all of the SimObject param headers and enum headers
568#
569
570def createSimObjectParamStruct(target, source, env):
571 assert len(target) == 1 and len(source) == 1
572
573 name = str(source[0].get_contents())
574 obj = sim_objects[name]
575
576 code = code_formatter()
577 obj.cxx_param_decl(code)
578 code.write(target[0].abspath)
579
580def createParamSwigWrapper(target, source, env):
581 assert len(target) == 1 and len(source) == 1
582
583 name = str(source[0].get_contents())
584 param = params_to_swig[name]
585
586 code = code_formatter()
587 param.swig_decl(code)
588 code.write(target[0].abspath)
589
590def createEnumStrings(target, source, env):
591 assert len(target) == 1 and len(source) == 1
592
593 name = str(source[0].get_contents())
594 obj = all_enums[name]
595
596 code = code_formatter()
597 obj.cxx_def(code)
598 code.write(target[0].abspath)
599
600def createEnumDecls(target, source, env):
601 assert len(target) == 1 and len(source) == 1
602
603 name = str(source[0].get_contents())
604 obj = all_enums[name]
605
606 code = code_formatter()
607 obj.cxx_decl(code)
608 code.write(target[0].abspath)
609
610def createEnumSwigWrapper(target, source, env):
611 assert len(target) == 1 and len(source) == 1
612
613 name = str(source[0].get_contents())
614 obj = all_enums[name]
615
616 code = code_formatter()
617 obj.swig_decl(code)
618 code.write(target[0].abspath)
619
620def createSimObjectSwigWrapper(target, source, env):
621 name = source[0].get_contents()
622 obj = sim_objects[name]
623
624 code = code_formatter()
625 obj.swig_decl(code)
626 code.write(target[0].abspath)
627
628# Generate all of the SimObject param C++ struct header files
629params_hh_files = []
630for name,simobj in sorted(sim_objects.iteritems()):
631 py_source = PySource.modules[simobj.__module__]
632 extra_deps = [ py_source.tnode ]
633
634 hh_file = File('params/%s.hh' % name)
635 params_hh_files.append(hh_file)
636 env.Command(hh_file, Value(name),
637 MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
638 env.Depends(hh_file, depends + extra_deps)
639
640# Generate any needed param SWIG wrapper files
641params_i_files = []
642for name,param in params_to_swig.iteritems():
643 i_file = File('python/m5/internal/%s.i' % (param.swig_module_name()))
644 params_i_files.append(i_file)
645 env.Command(i_file, Value(name),
646 MakeAction(createParamSwigWrapper, Transform("SW PARAM")))
647 env.Depends(i_file, depends)
648 SwigSource('m5.internal', i_file)
649
650# Generate all enum header files
651for name,enum in sorted(all_enums.iteritems()):
652 py_source = PySource.modules[enum.__module__]
653 extra_deps = [ py_source.tnode ]
654
655 cc_file = File('enums/%s.cc' % name)
656 env.Command(cc_file, Value(name),
657 MakeAction(createEnumStrings, Transform("ENUM STR")))
658 env.Depends(cc_file, depends + extra_deps)
659 Source(cc_file)
660
661 hh_file = File('enums/%s.hh' % name)
662 env.Command(hh_file, Value(name),
663 MakeAction(createEnumDecls, Transform("ENUMDECL")))
664 env.Depends(hh_file, depends + extra_deps)
665
666 i_file = File('python/m5/internal/enum_%s.i' % name)
667 env.Command(i_file, Value(name),
668 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG")))
669 env.Depends(i_file, depends + extra_deps)
670 SwigSource('m5.internal', i_file)
671
672# Generate SimObject SWIG wrapper files
673for name,simobj in sim_objects.iteritems():
674 py_source = PySource.modules[simobj.__module__]
675 extra_deps = [ py_source.tnode ]
676
677 i_file = File('python/m5/internal/param_%s.i' % name)
678 env.Command(i_file, Value(name),
679 MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG")))
680 env.Depends(i_file, depends + extra_deps)
681 SwigSource('m5.internal', i_file)
682
683# Generate the main swig init file
684def makeEmbeddedSwigInit(target, source, env):
685 code = code_formatter()
686 module = source[0].get_contents()
687 code('''\
688#include "sim/init.hh"
689
690extern "C" {
691 void init_${module}();
692}
693
694EmbeddedSwig embed_swig_${module}(init_${module});
695''')
696 code.write(str(target[0]))
697
698# Build all swig modules
699for swig in SwigSource.all:
700 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode,
701 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
702 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG")))
703 cc_file = str(swig.tnode)
704 init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file))
705 env.Command(init_file, Value(swig.module),
706 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
707 Source(init_file, **swig.guards)
708
709# Build all protocol buffers if we have got protoc and protobuf available
710if env['HAVE_PROTOBUF']:
711 for proto in ProtoBuf.all:
712 # Use both the source and header as the target, and the .proto
713 # file as the source. When executing the protoc compiler, also
714 # specify the proto_path to avoid having the generated files
715 # include the path.
716 env.Command([proto.cc_file, proto.hh_file], proto.tnode,
717 MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
718 '--proto_path ${SOURCE.dir} $SOURCE',
719 Transform("PROTOC")))
720
721 # Add the C++ source file
722 Source(proto.cc_file, **proto.guards)
723elif ProtoBuf.all:
724 print 'Got protobuf to build, but lacks support!'
725 Exit(1)
726
727#
728# Handle debug flags
729#
730def makeDebugFlagCC(target, source, env):
731 assert(len(target) == 1 and len(source) == 1)
732
733 val = eval(source[0].get_contents())
734 name, compound, desc = val
735 compound = list(sorted(compound))
736
737 code = code_formatter()
738
739 # file header
740 code('''
741/*
742 * DO NOT EDIT THIS FILE! Automatically generated
743 */
744
745#include "base/debug.hh"
746''')
747
748 for flag in compound:
749 code('#include "debug/$flag.hh"')
750 code()
751 code('namespace Debug {')
752 code()
753
754 if not compound:
755 code('SimpleFlag $name("$name", "$desc");')
756 else:
757 code('CompoundFlag $name("$name", "$desc",')
758 code.indent()
759 last = len(compound) - 1
760 for i,flag in enumerate(compound):
761 if i != last:
762 code('$flag,')
763 else:
764 code('$flag);')
765 code.dedent()
766
767 code()
768 code('} // namespace Debug')
769
770 code.write(str(target[0]))
771
772def makeDebugFlagHH(target, source, env):
773 assert(len(target) == 1 and len(source) == 1)
774
775 val = eval(source[0].get_contents())
776 name, compound, desc = val
777
778 code = code_formatter()
779
780 # file header boilerplate
781 code('''\
782/*
783 * DO NOT EDIT THIS FILE!
784 *
785 * Automatically generated by SCons
786 */
787
788#ifndef __DEBUG_${name}_HH__
789#define __DEBUG_${name}_HH__
790
791namespace Debug {
792''')
793
794 if compound:
795 code('class CompoundFlag;')
796 code('class SimpleFlag;')
797
798 if compound:
799 code('extern CompoundFlag $name;')
800 for flag in compound:
801 code('extern SimpleFlag $flag;')
802 else:
803 code('extern SimpleFlag $name;')
804
805 code('''
806}
807
808#endif // __DEBUG_${name}_HH__
809''')
810
811 code.write(str(target[0]))
812
813for name,flag in sorted(debug_flags.iteritems()):
814 n, compound, desc = flag
815 assert n == name
816
817 env.Command('debug/%s.hh' % name, Value(flag),
818 MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
819 env.Command('debug/%s.cc' % name, Value(flag),
820 MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
821 Source('debug/%s.cc' % name)
822
823# Embed python files. All .py files that have been indicated by a
824# PySource() call in a SConscript need to be embedded into the M5
825# library. To do that, we compile the file to byte code, marshal the
826# byte code, compress it, and then generate a c++ file that
827# inserts the result into an array.
828def embedPyFile(target, source, env):
829 def c_str(string):
830 if string is None:
831 return "0"
832 return '"%s"' % string
833
834 '''Action function to compile a .py into a code object, marshal
835 it, compress it, and stick it into an asm file so the code appears
836 as just bytes with a label in the data section'''
837
838 src = file(str(source[0]), 'r').read()
839
840 pysource = PySource.tnodes[source[0]]
841 compiled = compile(src, pysource.abspath, 'exec')
842 marshalled = marshal.dumps(compiled)
843 compressed = zlib.compress(marshalled)
844 data = compressed
845 sym = pysource.symname
846
847 code = code_formatter()
848 code('''\
849#include "sim/init.hh"
850
851namespace {
852
853const uint8_t data_${sym}[] = {
854''')
855 code.indent()
856 step = 16
857 for i in xrange(0, len(data), step):
858 x = array.array('B', data[i:i+step])
859 code(''.join('%d,' % d for d in x))
860 code.dedent()
861
862 code('''};
863
864EmbeddedPython embedded_${sym}(
865 ${{c_str(pysource.arcname)}},
866 ${{c_str(pysource.abspath)}},
867 ${{c_str(pysource.modpath)}},
868 data_${sym},
869 ${{len(data)}},
870 ${{len(marshalled)}});
871
872} // anonymous namespace
873''')
874 code.write(str(target[0]))
875
876for source in PySource.all:
877 env.Command(source.cpp, source.tnode,
878 MakeAction(embedPyFile, Transform("EMBED PY")))
879 Source(source.cpp)
880
881########################################################################
882#
883# Define binaries. Each different build type (debug, opt, etc.) gets
884# a slightly different build environment.
885#
886
887# List of constructed environments to pass back to SConstruct
880envList = []
881
882date_source = Source('base/date.cc', skip_lib=True)
883
888date_source = Source('base/date.cc', skip_lib=True)
889
890# Capture this directory for the closure makeEnv, otherwise when it is
891# called, it won't know what directory it should use.
892variant_dir = Dir('.').path
893def variant(*path):
894 return os.path.join(variant_dir, *path)
895def variantd(*path):
896 return variant(*path)+'/'
897
884# Function to create a new build environment as clone of current
885# environment 'env' with modified object suffix and optional stripped
886# binary. Additional keyword arguments are appended to corresponding
887# build environment vars.
898# Function to create a new build environment as clone of current
899# environment 'env' with modified object suffix and optional stripped
900# binary. Additional keyword arguments are appended to corresponding
901# build environment vars.
888def makeEnv(label, objsfx, strip = False, **kwargs):
902def makeEnv(env, label, objsfx, strip = False, **kwargs):
889 # SCons doesn't know to append a library suffix when there is a '.' in the
890 # name. Use '_' instead.
903 # SCons doesn't know to append a library suffix when there is a '.' in the
904 # name. Use '_' instead.
891 libname = 'gem5_' + label
892 exename = 'gem5.' + label
893 secondary_exename = 'm5.' + label
905 libname = variant('gem5_' + label)
906 exename = variant('gem5.' + label)
907 secondary_exename = variant('m5.' + label)
894
895 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
896 new_env.Label = label
897 new_env.Append(**kwargs)
898
899 swig_env = new_env.Clone()
900
901 # Both gcc and clang have issues with unused labels and values in
902 # the SWIG generated code
903 swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value'])
904
905 # Add additional warnings here that should not be applied to
906 # the SWIG generated code
907 new_env.Append(CXXFLAGS='-Wmissing-declarations')
908
909 if env['GCC']:
910 # Depending on the SWIG version, we also need to supress
911 # warnings about uninitialized variables and missing field
912 # initializers.
913 swig_env.Append(CCFLAGS=['-Wno-uninitialized',
914 '-Wno-missing-field-initializers'])
915
916 if compareVersions(env['GCC_VERSION'], '4.6') >= 0:
917 swig_env.Append(CCFLAGS='-Wno-unused-but-set-variable')
918
919 # If gcc supports it, also warn for deletion of derived
920 # classes with non-virtual desctructors. For gcc >= 4.7 we
921 # also have to disable warnings about the SWIG code having
922 # potentially uninitialized variables.
923 if compareVersions(env['GCC_VERSION'], '4.7') >= 0:
924 new_env.Append(CXXFLAGS='-Wdelete-non-virtual-dtor')
925 swig_env.Append(CCFLAGS='-Wno-maybe-uninitialized')
926 if env['CLANG']:
927 # Always enable the warning for deletion of derived classes
928 # with non-virtual destructors
929 new_env.Append(CXXFLAGS=['-Wdelete-non-virtual-dtor'])
930
931 werror_env = new_env.Clone()
932 werror_env.Append(CCFLAGS='-Werror')
933
934 def make_obj(source, static, extra_deps = None):
935 '''This function adds the specified source to the correct
936 build environment, and returns the corresponding SCons Object
937 nodes'''
938
939 if source.swig:
940 env = swig_env
941 elif source.Werror:
942 env = werror_env
943 else:
944 env = new_env
945
946 if static:
947 obj = env.StaticObject(source.tnode)
948 else:
949 obj = env.SharedObject(source.tnode)
950
951 if extra_deps:
952 env.Depends(obj, extra_deps)
953
954 return obj
955
956 static_objs = \
957 [ make_obj(s, True) for s in Source.get(main=False, skip_lib=False) ]
958 shared_objs = \
959 [ make_obj(s, False) for s in Source.get(main=False, skip_lib=False) ]
960
961 static_date = make_obj(date_source, static=True, extra_deps=static_objs)
962 static_objs.append(static_date)
963
964 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
965 shared_objs.append(shared_date)
966
967 # First make a library of everything but main() so other programs can
968 # link against m5.
969 static_lib = new_env.StaticLibrary(libname, static_objs)
970 shared_lib = new_env.SharedLibrary(libname, shared_objs)
971
972 # Now link a stub with main() and the static library.
973 main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
974
975 for test in UnitTest.all:
976 flags = { test.target : True }
977 test_sources = Source.get(**flags)
978 test_objs = [ make_obj(s, static=True) for s in test_sources ]
979 if test.main:
980 test_objs += main_objs
908
909 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
910 new_env.Label = label
911 new_env.Append(**kwargs)
912
913 swig_env = new_env.Clone()
914
915 # Both gcc and clang have issues with unused labels and values in
916 # the SWIG generated code
917 swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value'])
918
919 # Add additional warnings here that should not be applied to
920 # the SWIG generated code
921 new_env.Append(CXXFLAGS='-Wmissing-declarations')
922
923 if env['GCC']:
924 # Depending on the SWIG version, we also need to supress
925 # warnings about uninitialized variables and missing field
926 # initializers.
927 swig_env.Append(CCFLAGS=['-Wno-uninitialized',
928 '-Wno-missing-field-initializers'])
929
930 if compareVersions(env['GCC_VERSION'], '4.6') >= 0:
931 swig_env.Append(CCFLAGS='-Wno-unused-but-set-variable')
932
933 # If gcc supports it, also warn for deletion of derived
934 # classes with non-virtual desctructors. For gcc >= 4.7 we
935 # also have to disable warnings about the SWIG code having
936 # potentially uninitialized variables.
937 if compareVersions(env['GCC_VERSION'], '4.7') >= 0:
938 new_env.Append(CXXFLAGS='-Wdelete-non-virtual-dtor')
939 swig_env.Append(CCFLAGS='-Wno-maybe-uninitialized')
940 if env['CLANG']:
941 # Always enable the warning for deletion of derived classes
942 # with non-virtual destructors
943 new_env.Append(CXXFLAGS=['-Wdelete-non-virtual-dtor'])
944
945 werror_env = new_env.Clone()
946 werror_env.Append(CCFLAGS='-Werror')
947
948 def make_obj(source, static, extra_deps = None):
949 '''This function adds the specified source to the correct
950 build environment, and returns the corresponding SCons Object
951 nodes'''
952
953 if source.swig:
954 env = swig_env
955 elif source.Werror:
956 env = werror_env
957 else:
958 env = new_env
959
960 if static:
961 obj = env.StaticObject(source.tnode)
962 else:
963 obj = env.SharedObject(source.tnode)
964
965 if extra_deps:
966 env.Depends(obj, extra_deps)
967
968 return obj
969
970 static_objs = \
971 [ make_obj(s, True) for s in Source.get(main=False, skip_lib=False) ]
972 shared_objs = \
973 [ make_obj(s, False) for s in Source.get(main=False, skip_lib=False) ]
974
975 static_date = make_obj(date_source, static=True, extra_deps=static_objs)
976 static_objs.append(static_date)
977
978 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
979 shared_objs.append(shared_date)
980
981 # First make a library of everything but main() so other programs can
982 # link against m5.
983 static_lib = new_env.StaticLibrary(libname, static_objs)
984 shared_lib = new_env.SharedLibrary(libname, shared_objs)
985
986 # Now link a stub with main() and the static library.
987 main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
988
989 for test in UnitTest.all:
990 flags = { test.target : True }
991 test_sources = Source.get(**flags)
992 test_objs = [ make_obj(s, static=True) for s in test_sources ]
993 if test.main:
994 test_objs += main_objs
981 testname = "unittest/%s.%s" % (test.target, label)
982 new_env.Program(testname, test_objs + static_objs)
995 path = variant('unittest/%s.%s' % (test.target, label))
996 new_env.Program(path, test_objs + static_objs)
983
984 progname = exename
985 if strip:
986 progname += '.unstripped'
987
988 targets = new_env.Program(progname, main_objs + static_objs)
989
990 if strip:
991 if sys.platform == 'sunos5':
992 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
993 else:
994 cmd = 'strip $SOURCE -o $TARGET'
995 targets = new_env.Command(exename, progname,
996 MakeAction(cmd, Transform("STRIP")))
997
998 new_env.Command(secondary_exename, exename,
999 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1000
1001 new_env.M5Binary = targets[0]
997
998 progname = exename
999 if strip:
1000 progname += '.unstripped'
1001
1002 targets = new_env.Program(progname, main_objs + static_objs)
1003
1004 if strip:
1005 if sys.platform == 'sunos5':
1006 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1007 else:
1008 cmd = 'strip $SOURCE -o $TARGET'
1009 targets = new_env.Command(exename, progname,
1010 MakeAction(cmd, Transform("STRIP")))
1011
1012 new_env.Command(secondary_exename, exename,
1013 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1014
1015 new_env.M5Binary = targets[0]
1002 envList.append(new_env)
1016 return new_env
1003
1004# Start out with the compiler flags common to all compilers,
1005# i.e. they all use -g for opt and -g -pg for prof
1006ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
1007 'perf' : ['-g']}
1008
1009# Start out with the linker flags common to all linkers, i.e. -pg for
1010# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
1011# no-as-needed and as-needed as the binutils linker is too clever and
1012# simply doesn't link to the library otherwise.
1013ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
1014 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
1015
1016# For Link Time Optimization, the optimisation flags used to compile
1017# individual files are decoupled from those used at link time
1018# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
1019# to also update the linker flags based on the target.
1020if env['GCC']:
1021 if sys.platform == 'sunos5':
1022 ccflags['debug'] += ['-gstabs+']
1023 else:
1024 ccflags['debug'] += ['-ggdb3']
1025 ldflags['debug'] += ['-O0']
1026 # opt, fast, prof and perf all share the same cc flags, also add
1027 # the optimization to the ldflags as LTO defers the optimization
1028 # to link time
1029 for target in ['opt', 'fast', 'prof', 'perf']:
1030 ccflags[target] += ['-O3']
1031 ldflags[target] += ['-O3']
1032
1033 ccflags['fast'] += env['LTO_CCFLAGS']
1034 ldflags['fast'] += env['LTO_LDFLAGS']
1035elif env['CLANG']:
1036 ccflags['debug'] += ['-g', '-O0']
1037 # opt, fast, prof and perf all share the same cc flags
1038 for target in ['opt', 'fast', 'prof', 'perf']:
1039 ccflags[target] += ['-O3']
1040else:
1041 print 'Unknown compiler, please fix compiler options'
1042 Exit(1)
1043
1044
1045# To speed things up, we only instantiate the build environments we
1046# need. We try to identify the needed environment for each target; if
1047# we can't, we fall back on instantiating all the environments just to
1048# be safe.
1049target_types = ['debug', 'opt', 'fast', 'prof', 'perf']
1050obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
1051 'gpo' : 'perf'}
1052
1053def identifyTarget(t):
1054 ext = t.split('.')[-1]
1055 if ext in target_types:
1056 return ext
1057 if obj2target.has_key(ext):
1058 return obj2target[ext]
1059 match = re.search(r'/tests/([^/]+)/', t)
1060 if match and match.group(1) in target_types:
1061 return match.group(1)
1062 return 'all'
1063
1064needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
1065if 'all' in needed_envs:
1066 needed_envs += target_types
1067
1017
1018# Start out with the compiler flags common to all compilers,
1019# i.e. they all use -g for opt and -g -pg for prof
1020ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
1021 'perf' : ['-g']}
1022
1023# Start out with the linker flags common to all linkers, i.e. -pg for
1024# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
1025# no-as-needed and as-needed as the binutils linker is too clever and
1026# simply doesn't link to the library otherwise.
1027ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
1028 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
1029
1030# For Link Time Optimization, the optimisation flags used to compile
1031# individual files are decoupled from those used at link time
1032# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
1033# to also update the linker flags based on the target.
1034if env['GCC']:
1035 if sys.platform == 'sunos5':
1036 ccflags['debug'] += ['-gstabs+']
1037 else:
1038 ccflags['debug'] += ['-ggdb3']
1039 ldflags['debug'] += ['-O0']
1040 # opt, fast, prof and perf all share the same cc flags, also add
1041 # the optimization to the ldflags as LTO defers the optimization
1042 # to link time
1043 for target in ['opt', 'fast', 'prof', 'perf']:
1044 ccflags[target] += ['-O3']
1045 ldflags[target] += ['-O3']
1046
1047 ccflags['fast'] += env['LTO_CCFLAGS']
1048 ldflags['fast'] += env['LTO_LDFLAGS']
1049elif env['CLANG']:
1050 ccflags['debug'] += ['-g', '-O0']
1051 # opt, fast, prof and perf all share the same cc flags
1052 for target in ['opt', 'fast', 'prof', 'perf']:
1053 ccflags[target] += ['-O3']
1054else:
1055 print 'Unknown compiler, please fix compiler options'
1056 Exit(1)
1057
1058
1059# To speed things up, we only instantiate the build environments we
1060# need. We try to identify the needed environment for each target; if
1061# we can't, we fall back on instantiating all the environments just to
1062# be safe.
1063target_types = ['debug', 'opt', 'fast', 'prof', 'perf']
1064obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
1065 'gpo' : 'perf'}
1066
1067def identifyTarget(t):
1068 ext = t.split('.')[-1]
1069 if ext in target_types:
1070 return ext
1071 if obj2target.has_key(ext):
1072 return obj2target[ext]
1073 match = re.search(r'/tests/([^/]+)/', t)
1074 if match and match.group(1) in target_types:
1075 return match.group(1)
1076 return 'all'
1077
1078needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
1079if 'all' in needed_envs:
1080 needed_envs += target_types
1081
1068# Debug binary
1069if 'debug' in needed_envs:
1070 makeEnv('debug', '.do',
1071 CCFLAGS = Split(ccflags['debug']),
1072 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
1073 LINKFLAGS = Split(ldflags['debug']))
1082gem5_root = Dir('.').up().up().abspath
1083def makeEnvirons(target, source, env):
1084 # cause any later Source() calls to be fatal, as a diagnostic.
1085 Source.done()
1074
1086
1075# Optimized binary
1076if 'opt' in needed_envs:
1077 makeEnv('opt', '.o',
1078 CCFLAGS = Split(ccflags['opt']),
1079 CPPDEFINES = ['TRACING_ON=1'],
1080 LINKFLAGS = Split(ldflags['opt']))
1087 envList = []
1081
1088
1082# "Fast" binary
1083if 'fast' in needed_envs:
1084 makeEnv('fast', '.fo', strip = True,
1085 CCFLAGS = Split(ccflags['fast']),
1086 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1087 LINKFLAGS = Split(ldflags['fast']))
1089 # Debug binary
1090 if 'debug' in needed_envs:
1091 envList.append(
1092 makeEnv(env, 'debug', '.do',
1093 CCFLAGS = Split(ccflags['debug']),
1094 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
1095 LINKFLAGS = Split(ldflags['debug'])))
1088
1096
1089# Profiled binary using gprof
1090if 'prof' in needed_envs:
1091 makeEnv('prof', '.po',
1092 CCFLAGS = Split(ccflags['prof']),
1093 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1094 LINKFLAGS = Split(ldflags['prof']))
1097 # Optimized binary
1098 if 'opt' in needed_envs:
1099 envList.append(
1100 makeEnv(env, 'opt', '.o',
1101 CCFLAGS = Split(ccflags['opt']),
1102 CPPDEFINES = ['TRACING_ON=1'],
1103 LINKFLAGS = Split(ldflags['opt'])))
1095
1104
1096# Profiled binary using google-pprof
1097if 'perf' in needed_envs:
1098 makeEnv('perf', '.gpo',
1099 CCFLAGS = Split(ccflags['perf']),
1100 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1101 LINKFLAGS = Split(ldflags['perf']))
1105 # "Fast" binary
1106 if 'fast' in needed_envs:
1107 envList.append(
1108 makeEnv(env, 'fast', '.fo', strip = True,
1109 CCFLAGS = Split(ccflags['fast']),
1110 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1111 LINKFLAGS = Split(ldflags['fast'])))
1102
1112
1103Return('envList')
1113 # Profiled binary using gprof
1114 if 'prof' in needed_envs:
1115 envList.append(
1116 makeEnv(env, 'prof', '.po',
1117 CCFLAGS = Split(ccflags['prof']),
1118 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1119 LINKFLAGS = Split(ldflags['prof'])))
1120
1121 # Profiled binary using google-pprof
1122 if 'perf' in needed_envs:
1123 envList.append(
1124 makeEnv(env, 'perf', '.gpo',
1125 CCFLAGS = Split(ccflags['perf']),
1126 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1127 LINKFLAGS = Split(ldflags['perf'])))
1128
1129 # Set up the regression tests for each build.
1130 for e in envList:
1131 SConscript(os.path.join(gem5_root, 'tests', 'SConscript'),
1132 variant_dir = variantd('tests', e.Label),
1133 exports = { 'env' : e }, duplicate = False)
1134
1135# The MakeEnvirons Builder defers the full dependency collection until
1136# after processing the ISA definition (due to dynamically generated
1137# source files). Add this dependency to all targets so they will wait
1138# until the environments are completely set up. Otherwise, a second
1139# process (e.g. -j2 or higher) will try to compile the requested target,
1140# not know how, and fail.
1141env.Append(BUILDERS = {'MakeEnvirons' :
1142 Builder(action=MakeAction(makeEnvirons,
1143 Transform("ENVIRONS", 1)))})
1144
1145isa_target = env['PHONY_BASE'] + '-deps'
1146environs = env['PHONY_BASE'] + '-environs'
1147env.Depends('#all-deps', isa_target)
1148env.Depends('#all-environs', environs)
1149env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA']))
1150envSetup = env.MakeEnvirons(environs, isa_target)
1151
1152# make sure no -deps targets occur before all ISAs are complete
1153env.Depends(isa_target, '#all-isas')
1154# likewise for -environs targets and all the -deps targets
1155env.Depends(environs, '#all-deps')