SConscript revision 8300
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 315522Snate@binkert.orgimport array 326143Snate@binkert.orgimport bisect 334762Snate@binkert.orgimport imp 345522Snate@binkert.orgimport marshal 35955SN/Aimport os 365522Snate@binkert.orgimport re 37955SN/Aimport sys 385522Snate@binkert.orgimport zlib 394202Sbinkertn@umich.edu 405742Snate@binkert.orgfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 41955SN/A 424381Sbinkertn@umich.eduimport SCons 434381Sbinkertn@umich.edu 448334Snate@binkert.org# This file defines how to build a particular configuration of M5 45955SN/A# based on variable settings in the 'env' build environment. 46955SN/A 474202Sbinkertn@umich.eduImport('*') 48955SN/A 494382Sbinkertn@umich.edu# Children need to see the environment 504382Sbinkertn@umich.eduExport('env') 514382Sbinkertn@umich.edu 526654Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 535517Snate@binkert.org 548614Sgblack@eecs.umich.edufrom m5.util import code_formatter 557674Snate@binkert.org 566143Snate@binkert.org######################################################################## 576143Snate@binkert.org# Code for adding source files of various types 586143Snate@binkert.org# 598233Snate@binkert.org# When specifying a source file of some type, a set of guards can be 608233Snate@binkert.org# specified for that file. When get() is used to find the files, if 618233Snate@binkert.org# get specifies a set of filters, only files that match those filters 628233Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 638233Snate@binkert.org# false). Current filters are: 648334Snate@binkert.org# main -- specifies the m5 main() function 658334Snate@binkert.org# skip_lib -- do not put this file into the m5 library 668233Snate@binkert.org# <unittest> -- unit tests use filters based on the unit test name 678233Snate@binkert.org# 688233Snate@binkert.org# A parent can now be specified for a source file and default filter 698233Snate@binkert.org# values will be retrieved recursively from parents (children override 708233Snate@binkert.org# parents). 718233Snate@binkert.org# 726143Snate@binkert.orgclass SourceMeta(type): 738233Snate@binkert.org '''Meta class for source files that keeps track of all files of a 748233Snate@binkert.org particular type and has a get function for finding all functions 758233Snate@binkert.org of a certain type that match a set of guards''' 766143Snate@binkert.org def __init__(cls, name, bases, dict): 776143Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 786143Snate@binkert.org cls.all = [] 796143Snate@binkert.org 808233Snate@binkert.org def get(cls, **guards): 818233Snate@binkert.org '''Find all files that match the specified guards. If a source 828233Snate@binkert.org file does not specify a flag, the default is False''' 836143Snate@binkert.org for src in cls.all: 848233Snate@binkert.org for flag,value in guards.iteritems(): 858233Snate@binkert.org # if the flag is found and has a different value, skip 868233Snate@binkert.org # this file 878233Snate@binkert.org if src.all_guards.get(flag, False) != value: 886143Snate@binkert.org break 896143Snate@binkert.org else: 906143Snate@binkert.org yield src 914762Snate@binkert.org 926143Snate@binkert.orgclass SourceFile(object): 938233Snate@binkert.org '''Base object that encapsulates the notion of a source file. 948233Snate@binkert.org This includes, the source node, target node, various manipulations 958233Snate@binkert.org of those. A source file also specifies a set of guards which 968233Snate@binkert.org describing which builds the source file applies to. A parent can 978233Snate@binkert.org also be specified to get default guards from''' 986143Snate@binkert.org __metaclass__ = SourceMeta 998233Snate@binkert.org def __init__(self, source, parent=None, **guards): 1008233Snate@binkert.org self.guards = guards 1018233Snate@binkert.org self.parent = parent 1028233Snate@binkert.org 1036143Snate@binkert.org tnode = source 1046143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1056143Snate@binkert.org tnode = File(source) 1066143Snate@binkert.org 1076143Snate@binkert.org self.tnode = tnode 1086143Snate@binkert.org self.snode = tnode.srcnode() 1096143Snate@binkert.org 1106143Snate@binkert.org for base in type(self).__mro__: 1116143Snate@binkert.org if issubclass(base, SourceFile): 1127065Snate@binkert.org base.all.append(self) 1136143Snate@binkert.org 1148233Snate@binkert.org @property 1158233Snate@binkert.org def filename(self): 1168233Snate@binkert.org return str(self.tnode) 1178233Snate@binkert.org 1188233Snate@binkert.org @property 1198233Snate@binkert.org def dirname(self): 1208233Snate@binkert.org return dirname(self.filename) 1218233Snate@binkert.org 1228233Snate@binkert.org @property 1238233Snate@binkert.org def basename(self): 1248233Snate@binkert.org return basename(self.filename) 1258233Snate@binkert.org 1268233Snate@binkert.org @property 1278233Snate@binkert.org def extname(self): 1288233Snate@binkert.org index = self.basename.rfind('.') 1298233Snate@binkert.org if index <= 0: 1308233Snate@binkert.org # dot files aren't extensions 1318233Snate@binkert.org return self.basename, None 1328233Snate@binkert.org 1338233Snate@binkert.org return self.basename[:index], self.basename[index+1:] 1348233Snate@binkert.org 1358233Snate@binkert.org @property 1368233Snate@binkert.org def all_guards(self): 1378233Snate@binkert.org '''find all guards for this object getting default values 1388233Snate@binkert.org recursively from its parents''' 1398233Snate@binkert.org guards = {} 1408233Snate@binkert.org if self.parent: 1418233Snate@binkert.org guards.update(self.parent.guards) 1428233Snate@binkert.org guards.update(self.guards) 1438233Snate@binkert.org return guards 1448233Snate@binkert.org 1456143Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 1466143Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 1476143Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 1486143Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 1496143Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 1506143Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 1519982Satgutier@umich.edu 15210196SCurtis.Dunham@arm.comclass Source(SourceFile): 15310196SCurtis.Dunham@arm.com '''Add a c/c++ source file to the build''' 15410196SCurtis.Dunham@arm.com def __init__(self, source, Werror=True, swig=False, **guards): 15510196SCurtis.Dunham@arm.com '''specify the source file, and any guards''' 15610196SCurtis.Dunham@arm.com super(Source, self).__init__(source, **guards) 15710196SCurtis.Dunham@arm.com 15810196SCurtis.Dunham@arm.com self.Werror = Werror 15910196SCurtis.Dunham@arm.com self.swig = swig 1606143Snate@binkert.org 1616143Snate@binkert.orgclass PySource(SourceFile): 1628945Ssteve.reinhardt@amd.com '''Add a python source file to the named package''' 1638233Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1648233Snate@binkert.org modules = {} 1656143Snate@binkert.org tnodes = {} 1668945Ssteve.reinhardt@amd.com symnames = {} 1676143Snate@binkert.org 1686143Snate@binkert.org def __init__(self, package, source, **guards): 1696143Snate@binkert.org '''specify the python package, the source file, and any guards''' 1706143Snate@binkert.org super(PySource, self).__init__(source, **guards) 1715522Snate@binkert.org 1726143Snate@binkert.org modname,ext = self.extname 1736143Snate@binkert.org assert ext == 'py' 1746143Snate@binkert.org 1759982Satgutier@umich.edu if package: 1768233Snate@binkert.org path = package.split('.') 1778233Snate@binkert.org else: 1788233Snate@binkert.org path = [] 1796143Snate@binkert.org 1806143Snate@binkert.org modpath = path[:] 1816143Snate@binkert.org if modname != '__init__': 1826143Snate@binkert.org modpath += [ modname ] 1835522Snate@binkert.org modpath = '.'.join(modpath) 1845522Snate@binkert.org 1855522Snate@binkert.org arcpath = path + [ self.basename ] 1865522Snate@binkert.org abspath = self.snode.abspath 1875604Snate@binkert.org if not exists(abspath): 1885604Snate@binkert.org abspath = self.tnode.abspath 1896143Snate@binkert.org 1906143Snate@binkert.org self.package = package 1914762Snate@binkert.org self.modname = modname 1924762Snate@binkert.org self.modpath = modpath 1936143Snate@binkert.org self.arcname = joinpath(*arcpath) 1946727Ssteve.reinhardt@amd.com self.abspath = abspath 1956727Ssteve.reinhardt@amd.com self.compiled = File(self.filename + 'c') 1966727Ssteve.reinhardt@amd.com self.cpp = File(self.filename + '.cc') 1974762Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 1986143Snate@binkert.org 1996143Snate@binkert.org PySource.modules[modpath] = self 2006143Snate@binkert.org PySource.tnodes[self.tnode] = self 2016143Snate@binkert.org PySource.symnames[self.symname] = self 2026727Ssteve.reinhardt@amd.com 2036143Snate@binkert.orgclass SimObject(PySource): 2047674Snate@binkert.org '''Add a SimObject python file as a python source object and add 2057674Snate@binkert.org it to a list of sim object modules''' 2065604Snate@binkert.org 2076143Snate@binkert.org fixed = False 2086143Snate@binkert.org modnames = [] 2096143Snate@binkert.org 2104762Snate@binkert.org def __init__(self, source, **guards): 2116143Snate@binkert.org '''Specify the source file and any guards (automatically in 2124762Snate@binkert.org the m5.objects package)''' 2134762Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2144762Snate@binkert.org if self.fixed: 2156143Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 2166143Snate@binkert.org 2174762Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 2188233Snate@binkert.org 2198233Snate@binkert.orgclass SwigSource(SourceFile): 2208233Snate@binkert.org '''Add a swig file to build''' 2218233Snate@binkert.org 2226143Snate@binkert.org def __init__(self, package, source, **guards): 2236143Snate@binkert.org '''Specify the python package, the source file, and any guards''' 2244762Snate@binkert.org super(SwigSource, self).__init__(source, **guards) 2256143Snate@binkert.org 2264762Snate@binkert.org modname,ext = self.extname 2276143Snate@binkert.org assert ext == 'i' 2284762Snate@binkert.org 2296143Snate@binkert.org self.module = modname 2308233Snate@binkert.org cc_file = joinpath(self.dirname, modname + '_wrap.cc') 2318233Snate@binkert.org py_file = joinpath(self.dirname, modname + '.py') 2328233Snate@binkert.org 2336143Snate@binkert.org self.cc_source = Source(cc_file, swig=True, parent=self) 2346143Snate@binkert.org self.py_source = PySource(package, py_file, parent=self) 2356143Snate@binkert.org 2366143Snate@binkert.orgclass UnitTest(object): 2376143Snate@binkert.org '''Create a UnitTest''' 2386143Snate@binkert.org 2396143Snate@binkert.org all = [] 2406143Snate@binkert.org def __init__(self, target, *sources): 2418233Snate@binkert.org '''Specify the target name and any sources. Sources that are 2428233Snate@binkert.org not SourceFiles are evalued with Source(). All files are 243955SN/A guarded with a guard of the same name as the UnitTest 2449396Sandreas.hansson@arm.com target.''' 2459396Sandreas.hansson@arm.com 2469396Sandreas.hansson@arm.com srcs = [] 2479396Sandreas.hansson@arm.com for src in sources: 2489396Sandreas.hansson@arm.com if not isinstance(src, SourceFile): 2499396Sandreas.hansson@arm.com src = Source(src, skip_lib=True) 2509396Sandreas.hansson@arm.com src.guards[target] = True 2519396Sandreas.hansson@arm.com srcs.append(src) 2529396Sandreas.hansson@arm.com 2539396Sandreas.hansson@arm.com self.sources = srcs 2549396Sandreas.hansson@arm.com self.target = target 2559396Sandreas.hansson@arm.com UnitTest.all.append(self) 2569396Sandreas.hansson@arm.com 2579930Sandreas.hansson@arm.com# Children should have access 2589930Sandreas.hansson@arm.comExport('Source') 2599396Sandreas.hansson@arm.comExport('PySource') 2608235Snate@binkert.orgExport('SimObject') 2618235Snate@binkert.orgExport('SwigSource') 2626143Snate@binkert.orgExport('UnitTest') 2638235Snate@binkert.org 2649003SAli.Saidi@ARM.com######################################################################## 2658235Snate@binkert.org# 2668235Snate@binkert.org# Debug Flags 2678235Snate@binkert.org# 2688235Snate@binkert.orgdebug_flags = {} 2698235Snate@binkert.orgdef DebugFlag(name, desc=None): 2708235Snate@binkert.org if name in debug_flags: 2718235Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2728235Snate@binkert.org debug_flags[name] = (name, (), desc) 2738235Snate@binkert.orgTraceFlag = DebugFlag 2748235Snate@binkert.org 2758235Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 2768235Snate@binkert.org if name in debug_flags: 2778235Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2788235Snate@binkert.org 2799003SAli.Saidi@ARM.com compound = tuple(flags) 2808235Snate@binkert.org debug_flags[name] = (name, compound, desc) 2815584Snate@binkert.org 2824382Sbinkertn@umich.eduExport('DebugFlag') 2834202Sbinkertn@umich.eduExport('TraceFlag') 2844382Sbinkertn@umich.eduExport('CompoundFlag') 2854382Sbinkertn@umich.edu 2864382Sbinkertn@umich.edu######################################################################## 2879396Sandreas.hansson@arm.com# 2885584Snate@binkert.org# Set some compiler variables 2894382Sbinkertn@umich.edu# 2904382Sbinkertn@umich.edu 2914382Sbinkertn@umich.edu# Include file paths are rooted in this directory. SCons will 2928232Snate@binkert.org# automatically expand '.' to refer to both the source directory and 2935192Ssaidi@eecs.umich.edu# the corresponding build directory to pick up generated include 2948232Snate@binkert.org# files. 2958232Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2968232Snate@binkert.org 2975192Ssaidi@eecs.umich.edufor extra_dir in extras_dir_list: 2988232Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2995192Ssaidi@eecs.umich.edu 3005799Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 3018232Snate@binkert.org# Scons bug id: 2006 M5 Bug id: 308 3025192Ssaidi@eecs.umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3035192Ssaidi@eecs.umich.edu Dir(root[len(base_dir) + 1:]) 3045192Ssaidi@eecs.umich.edu 3058232Snate@binkert.org######################################################################## 3065192Ssaidi@eecs.umich.edu# 3078232Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories 3085192Ssaidi@eecs.umich.edu# 3095192Ssaidi@eecs.umich.edu 3105192Ssaidi@eecs.umich.eduhere = Dir('.').srcnode().abspath 3115192Ssaidi@eecs.umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3124382Sbinkertn@umich.edu if root == here: 3134382Sbinkertn@umich.edu # we don't want to recurse back into this SConscript 3144382Sbinkertn@umich.edu continue 3152667Sstever@eecs.umich.edu 3162667Sstever@eecs.umich.edu if 'SConscript' in files: 3172667Sstever@eecs.umich.edu build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3182667Sstever@eecs.umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3192667Sstever@eecs.umich.edu 3202667Sstever@eecs.umich.edufor extra_dir in extras_dir_list: 3215742Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 3225742Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 3235742Snate@binkert.org # if build lives in the extras directory, don't walk down it 3245793Snate@binkert.org if 'build' in dirs: 3258334Snate@binkert.org dirs.remove('build') 3265793Snate@binkert.org 3275793Snate@binkert.org if 'SConscript' in files: 3285793Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3294382Sbinkertn@umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3304762Snate@binkert.org 3315344Sstever@gmail.comfor opt in export_vars: 3324382Sbinkertn@umich.edu env.ConfigFile(opt) 3335341Sstever@gmail.com 3345742Snate@binkert.orgdef makeTheISA(source, target, env): 3355742Snate@binkert.org isas = [ src.get_contents() for src in source ] 3365742Snate@binkert.org target_isa = env['TARGET_ISA'] 3375742Snate@binkert.org def define(isa): 3385742Snate@binkert.org return isa.upper() + '_ISA' 3394762Snate@binkert.org 3405742Snate@binkert.org def namespace(isa): 3415742Snate@binkert.org return isa[0].upper() + isa[1:].lower() + 'ISA' 3427722Sgblack@eecs.umich.edu 3435742Snate@binkert.org 3445742Snate@binkert.org code = code_formatter() 3455742Snate@binkert.org code('''\ 3469930Sandreas.hansson@arm.com#ifndef __CONFIG_THE_ISA_HH__ 3479930Sandreas.hansson@arm.com#define __CONFIG_THE_ISA_HH__ 3489930Sandreas.hansson@arm.com 3499930Sandreas.hansson@arm.com''') 3509930Sandreas.hansson@arm.com 3515742Snate@binkert.org for i,isa in enumerate(isas): 3528242Sbradley.danofsky@amd.com code('#define $0 $1', define(isa), i + 1) 3538242Sbradley.danofsky@amd.com 3548242Sbradley.danofsky@amd.com code(''' 3558242Sbradley.danofsky@amd.com 3565341Sstever@gmail.com#define THE_ISA ${{define(target_isa)}} 3575742Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 3587722Sgblack@eecs.umich.edu 3594773Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''') 3606108Snate@binkert.org 3611858SN/A code.write(str(target[0])) 3621085SN/A 3636658Snate@binkert.orgenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3646658Snate@binkert.org MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3657673Snate@binkert.org 3666658Snate@binkert.org######################################################################## 3676658Snate@binkert.org# 3686658Snate@binkert.org# Prevent any SimObjects from being added after this point, they 3696658Snate@binkert.org# should all have been added in the SConscripts above 3706658Snate@binkert.org# 3716658Snate@binkert.orgSimObject.fixed = True 3726658Snate@binkert.org 3737673Snate@binkert.orgclass DictImporter(object): 3747673Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 3757673Snate@binkert.org map to arbitrary filenames.''' 3767673Snate@binkert.org def __init__(self, modules): 3777673Snate@binkert.org self.modules = modules 3787673Snate@binkert.org self.installed = set() 3797673Snate@binkert.org 3806658Snate@binkert.org def __del__(self): 3817673Snate@binkert.org self.unload() 3827673Snate@binkert.org 3837673Snate@binkert.org def unload(self): 3847673Snate@binkert.org import sys 3857673Snate@binkert.org for module in self.installed: 3867673Snate@binkert.org del sys.modules[module] 3879048SAli.Saidi@ARM.com self.installed = set() 3887673Snate@binkert.org 3897673Snate@binkert.org def find_module(self, fullname, path): 3907673Snate@binkert.org if fullname == 'm5.defines': 3917673Snate@binkert.org return self 3926658Snate@binkert.org 3937756SAli.Saidi@ARM.com if fullname == 'm5.objects': 3947816Ssteve.reinhardt@amd.com return self 3956658Snate@binkert.org 3964382Sbinkertn@umich.edu if fullname.startswith('m5.internal'): 3974382Sbinkertn@umich.edu return None 3984762Snate@binkert.org 3994762Snate@binkert.org source = self.modules.get(fullname, None) 4004762Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 4016654Snate@binkert.org return self 4026654Snate@binkert.org 4035517Snate@binkert.org return None 4045517Snate@binkert.org 4055517Snate@binkert.org def load_module(self, fullname): 4065517Snate@binkert.org mod = imp.new_module(fullname) 4075517Snate@binkert.org sys.modules[fullname] = mod 4085517Snate@binkert.org self.installed.add(fullname) 4095517Snate@binkert.org 4105517Snate@binkert.org mod.__loader__ = self 4115517Snate@binkert.org if fullname == 'm5.objects': 4125517Snate@binkert.org mod.__path__ = fullname.split('.') 4135517Snate@binkert.org return mod 4145517Snate@binkert.org 4155517Snate@binkert.org if fullname == 'm5.defines': 4165517Snate@binkert.org mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 4175517Snate@binkert.org return mod 4185517Snate@binkert.org 4195517Snate@binkert.org source = self.modules[fullname] 4206654Snate@binkert.org if source.modname == '__init__': 4215517Snate@binkert.org mod.__path__ = source.modpath 4225517Snate@binkert.org mod.__file__ = source.abspath 4235517Snate@binkert.org 4245517Snate@binkert.org exec file(source.abspath, 'r') in mod.__dict__ 4255517Snate@binkert.org 4265517Snate@binkert.org return mod 4275517Snate@binkert.org 4285517Snate@binkert.orgimport m5.SimObject 4296143Snate@binkert.orgimport m5.params 4306654Snate@binkert.orgfrom m5.util import code_formatter 4315517Snate@binkert.org 4325517Snate@binkert.orgm5.SimObject.clear() 4335517Snate@binkert.orgm5.params.clear() 4345517Snate@binkert.org 4355517Snate@binkert.org# install the python importer so we can grab stuff from the source 4365517Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 4375517Snate@binkert.org# else we won't know about them for the rest of the stuff. 4385517Snate@binkert.orgimporter = DictImporter(PySource.modules) 4395517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 4405517Snate@binkert.org 4415517Snate@binkert.org# import all sim objects so we can populate the all_objects list 4425517Snate@binkert.org# make sure that we're working with a list, then let's sort it 4435517Snate@binkert.orgfor modname in SimObject.modnames: 4445517Snate@binkert.org exec('from m5.objects import %s' % modname) 4456654Snate@binkert.org 4466654Snate@binkert.org# we need to unload all of the currently imported modules so that they 4475517Snate@binkert.org# will be re-imported the next time the sconscript is run 4485517Snate@binkert.orgimporter.unload() 4496143Snate@binkert.orgsys.meta_path.remove(importer) 4506143Snate@binkert.org 4516143Snate@binkert.orgsim_objects = m5.SimObject.allClasses 4526727Ssteve.reinhardt@amd.comall_enums = m5.params.allEnums 4535517Snate@binkert.org 4546727Ssteve.reinhardt@amd.comall_params = {} 4555517Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 4565517Snate@binkert.org for param in obj._params.local.values(): 4575517Snate@binkert.org # load the ptype attribute now because it depends on the 4586654Snate@binkert.org # current version of SimObject.allClasses, but when scons 4596654Snate@binkert.org # actually uses the value, all versions of 4607673Snate@binkert.org # SimObject.allClasses will have been loaded 4616654Snate@binkert.org param.ptype 4626654Snate@binkert.org 4636654Snate@binkert.org if not hasattr(param, 'swig_decl'): 4646654Snate@binkert.org continue 4655517Snate@binkert.org pname = param.ptype_str 4665517Snate@binkert.org if pname not in all_params: 4675517Snate@binkert.org all_params[pname] = param 4686143Snate@binkert.org 4695517Snate@binkert.org######################################################################## 4704762Snate@binkert.org# 4715517Snate@binkert.org# calculate extra dependencies 4725517Snate@binkert.org# 4736143Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 4746143Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 4755517Snate@binkert.org 4765517Snate@binkert.org######################################################################## 4775517Snate@binkert.org# 4785517Snate@binkert.org# Commands for the basic automatically generated python files 4795517Snate@binkert.org# 4805517Snate@binkert.org 4815517Snate@binkert.org# Generate Python file containing a dict specifying the current 4825517Snate@binkert.org# buildEnv flags. 4835517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 4849338SAndreas.Sandberg@arm.com build_env = source[0].get_contents() 4859338SAndreas.Sandberg@arm.com 4869338SAndreas.Sandberg@arm.com code = code_formatter() 4879338SAndreas.Sandberg@arm.com code(""" 4889338SAndreas.Sandberg@arm.comimport m5.internal 4899338SAndreas.Sandberg@arm.comimport m5.util 4908596Ssteve.reinhardt@amd.com 4918596Ssteve.reinhardt@amd.combuildEnv = m5.util.SmartDict($build_env) 4928596Ssteve.reinhardt@amd.com 4938596Ssteve.reinhardt@amd.comcompileDate = m5.internal.core.compileDate 4948596Ssteve.reinhardt@amd.com_globals = globals() 4958596Ssteve.reinhardt@amd.comfor key,val in m5.internal.core.__dict__.iteritems(): 4968596Ssteve.reinhardt@amd.com if key.startswith('flag_'): 4976143Snate@binkert.org flag = key[5:] 4985517Snate@binkert.org _globals[flag] = val 4996654Snate@binkert.orgdel _globals 5006654Snate@binkert.org""") 5016654Snate@binkert.org code.write(target[0].abspath) 5026654Snate@binkert.org 5036654Snate@binkert.orgdefines_info = Value(build_env) 5046654Snate@binkert.org# Generate a file with all of the compile options in it 5055517Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info, 5065517Snate@binkert.org MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5075517Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 5088596Ssteve.reinhardt@amd.com 5098596Ssteve.reinhardt@amd.com# Generate python file containing info about the M5 source code 5104762Snate@binkert.orgdef makeInfoPyFile(target, source, env): 5114762Snate@binkert.org code = code_formatter() 5124762Snate@binkert.org for src in source: 5134762Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 5144762Snate@binkert.org code('$src = ${{repr(data)}}') 5154762Snate@binkert.org code.write(str(target[0])) 5167675Snate@binkert.org 5174762Snate@binkert.org# Generate a file that wraps the basic top level files 5184762Snate@binkert.orgenv.Command('python/m5/info.py', 5194762Snate@binkert.org [ '#/AUTHORS', '#/LICENSE', '#/README', ], 5204762Snate@binkert.org MakeAction(makeInfoPyFile, Transform("INFO"))) 5214382Sbinkertn@umich.eduPySource('m5', 'python/m5/info.py') 5224382Sbinkertn@umich.edu 5235517Snate@binkert.org######################################################################## 5246654Snate@binkert.org# 5255517Snate@binkert.org# Create all of the SimObject param headers and enum headers 5268126Sgblack@eecs.umich.edu# 5276654Snate@binkert.org 5287673Snate@binkert.orgdef createSimObjectParam(target, source, env): 5296654Snate@binkert.org assert len(target) == 1 and len(source) == 1 5306654Snate@binkert.org 5316654Snate@binkert.org name = str(source[0].get_contents()) 5326654Snate@binkert.org obj = sim_objects[name] 5336654Snate@binkert.org 5346654Snate@binkert.org code = code_formatter() 5356654Snate@binkert.org obj.cxx_decl(code) 5366669Snate@binkert.org code.write(target[0].abspath) 5376669Snate@binkert.org 5386669Snate@binkert.orgdef createSwigParam(target, source, env): 5396669Snate@binkert.org assert len(target) == 1 and len(source) == 1 5406669Snate@binkert.org 5416669Snate@binkert.org name = str(source[0].get_contents()) 5426654Snate@binkert.org param = all_params[name] 5437673Snate@binkert.org 5445517Snate@binkert.org code = code_formatter() 5458126Sgblack@eecs.umich.edu code('%module(package="m5.internal") $0_${name}', param.file_ext) 5465798Snate@binkert.org param.swig_decl(code) 5477756SAli.Saidi@ARM.com code.write(target[0].abspath) 5487816Ssteve.reinhardt@amd.com 5495798Snate@binkert.orgdef createEnumStrings(target, source, env): 5505798Snate@binkert.org assert len(target) == 1 and len(source) == 1 5515517Snate@binkert.org 5525517Snate@binkert.org name = str(source[0].get_contents()) 5537673Snate@binkert.org obj = all_enums[name] 5545517Snate@binkert.org 5555517Snate@binkert.org code = code_formatter() 5567673Snate@binkert.org obj.cxx_def(code) 5577673Snate@binkert.org code.write(target[0].abspath) 5585517Snate@binkert.org 5595798Snate@binkert.orgdef createEnumParam(target, source, env): 5605798Snate@binkert.org assert len(target) == 1 and len(source) == 1 5618333Snate@binkert.org 5627816Ssteve.reinhardt@amd.com name = str(source[0].get_contents()) 5635798Snate@binkert.org obj = all_enums[name] 5645798Snate@binkert.org 5654762Snate@binkert.org code = code_formatter() 5664762Snate@binkert.org obj.cxx_decl(code) 5674762Snate@binkert.org code.write(target[0].abspath) 5684762Snate@binkert.org 5694762Snate@binkert.orgdef createEnumSwig(target, source, env): 5708596Ssteve.reinhardt@amd.com assert len(target) == 1 and len(source) == 1 5715517Snate@binkert.org 5725517Snate@binkert.org name = str(source[0].get_contents()) 5735517Snate@binkert.org obj = all_enums[name] 5745517Snate@binkert.org 5755517Snate@binkert.org code = code_formatter() 5767673Snate@binkert.org code('''\ 5778596Ssteve.reinhardt@amd.com%module(package="m5.internal") enum_$name 5787673Snate@binkert.org 5795517Snate@binkert.org%{ 5808596Ssteve.reinhardt@amd.com#include "enums/$name.hh" 5815517Snate@binkert.org%} 5825517Snate@binkert.org 5835517Snate@binkert.org%include "enums/$name.hh" 5848596Ssteve.reinhardt@amd.com''') 5855517Snate@binkert.org code.write(target[0].abspath) 5867673Snate@binkert.org 5877673Snate@binkert.org# Generate all of the SimObject param struct header files 5887673Snate@binkert.orgparams_hh_files = [] 5895517Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 5905517Snate@binkert.org py_source = PySource.modules[simobj.__module__] 5915517Snate@binkert.org extra_deps = [ py_source.tnode ] 5925517Snate@binkert.org 5935517Snate@binkert.org hh_file = File('params/%s.hh' % name) 5945517Snate@binkert.org params_hh_files.append(hh_file) 5955517Snate@binkert.org env.Command(hh_file, Value(name), 5967673Snate@binkert.org MakeAction(createSimObjectParam, Transform("SO PARAM"))) 5977673Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 5987673Snate@binkert.org 5995517Snate@binkert.org# Generate any parameter header files needed 6008596Ssteve.reinhardt@amd.comparams_i_files = [] 6015517Snate@binkert.orgfor name,param in all_params.iteritems(): 6025517Snate@binkert.org i_file = File('python/m5/internal/%s_%s.i' % (param.file_ext, name)) 6035517Snate@binkert.org params_i_files.append(i_file) 6045517Snate@binkert.org env.Command(i_file, Value(name), 6055517Snate@binkert.org MakeAction(createSwigParam, Transform("SW PARAM"))) 6067673Snate@binkert.org env.Depends(i_file, depends) 6077673Snate@binkert.org SwigSource('m5.internal', i_file) 6087673Snate@binkert.org 6095517Snate@binkert.org# Generate all enum header files 6108596Ssteve.reinhardt@amd.comfor name,enum in sorted(all_enums.iteritems()): 6117675Snate@binkert.org py_source = PySource.modules[enum.__module__] 6127675Snate@binkert.org extra_deps = [ py_source.tnode ] 6137675Snate@binkert.org 6147675Snate@binkert.org cc_file = File('enums/%s.cc' % name) 6157675Snate@binkert.org env.Command(cc_file, Value(name), 6167675Snate@binkert.org MakeAction(createEnumStrings, Transform("ENUM STR"))) 6178596Ssteve.reinhardt@amd.com env.Depends(cc_file, depends + extra_deps) 6187675Snate@binkert.org Source(cc_file) 6197675Snate@binkert.org 6208596Ssteve.reinhardt@amd.com hh_file = File('enums/%s.hh' % name) 6218596Ssteve.reinhardt@amd.com env.Command(hh_file, Value(name), 6228596Ssteve.reinhardt@amd.com MakeAction(createEnumParam, Transform("EN PARAM"))) 6238596Ssteve.reinhardt@amd.com env.Depends(hh_file, depends + extra_deps) 6248596Ssteve.reinhardt@amd.com 6258596Ssteve.reinhardt@amd.com i_file = File('python/m5/internal/enum_%s.i' % name) 6268596Ssteve.reinhardt@amd.com env.Command(i_file, Value(name), 6278596Ssteve.reinhardt@amd.com MakeAction(createEnumSwig, Transform("ENUMSWIG"))) 6288596Ssteve.reinhardt@amd.com env.Depends(i_file, depends + extra_deps) 6294762Snate@binkert.org SwigSource('m5.internal', i_file) 6306143Snate@binkert.org 6316143Snate@binkert.orgdef buildParam(target, source, env): 6326143Snate@binkert.org name = source[0].get_contents() 6334762Snate@binkert.org obj = sim_objects[name] 6344762Snate@binkert.org class_path = obj.cxx_class.split('::') 6354762Snate@binkert.org classname = class_path[-1] 6367756SAli.Saidi@ARM.com namespaces = class_path[:-1] 6378596Ssteve.reinhardt@amd.com params = obj._params.local.values() 6384762Snate@binkert.org 6394762Snate@binkert.org code = code_formatter() 6408596Ssteve.reinhardt@amd.com 6415463Snate@binkert.org code('%module(package="m5.internal") param_$name') 6428596Ssteve.reinhardt@amd.com code() 6438596Ssteve.reinhardt@amd.com code('%{') 6445463Snate@binkert.org code('#include "params/$obj.hh"') 6457756SAli.Saidi@ARM.com for param in params: 6468596Ssteve.reinhardt@amd.com param.cxx_predecls(code) 6474762Snate@binkert.org code('%}') 6487677Snate@binkert.org code() 6494762Snate@binkert.org 6504762Snate@binkert.org for param in params: 6516143Snate@binkert.org param.swig_predecls(code) 6526143Snate@binkert.org 6536143Snate@binkert.org code() 6544762Snate@binkert.org if obj._base: 6554762Snate@binkert.org code('%import "python/m5/internal/param_${{obj._base}}.i"') 6567756SAli.Saidi@ARM.com code() 6577816Ssteve.reinhardt@amd.com obj.swig_objdecls(code) 6584762Snate@binkert.org code() 6594762Snate@binkert.org 6604762Snate@binkert.org code('%include "params/$obj.hh"') 6614762Snate@binkert.org 6627756SAli.Saidi@ARM.com code.write(target[0].abspath) 6638596Ssteve.reinhardt@amd.com 6644762Snate@binkert.orgfor name in sim_objects.iterkeys(): 6654762Snate@binkert.org params_file = File('python/m5/internal/param_%s.i' % name) 6667677Snate@binkert.org env.Command(params_file, Value(name), 6677756SAli.Saidi@ARM.com MakeAction(buildParam, Transform("BLDPARAM"))) 6688596Ssteve.reinhardt@amd.com env.Depends(params_file, depends) 6697675Snate@binkert.org SwigSource('m5.internal', params_file) 6707677Snate@binkert.org 6715517Snate@binkert.org# Generate the main swig init file 6728596Ssteve.reinhardt@amd.comdef makeEmbeddedSwigInit(target, source, env): 6739248SAndreas.Sandberg@arm.com code = code_formatter() 6749248SAndreas.Sandberg@arm.com module = source[0].get_contents() 6759248SAndreas.Sandberg@arm.com code('''\ 6769248SAndreas.Sandberg@arm.com#include "sim/init.hh" 6778596Ssteve.reinhardt@amd.com 6788596Ssteve.reinhardt@amd.comextern "C" { 6798596Ssteve.reinhardt@amd.com void init_${module}(); 6809248SAndreas.Sandberg@arm.com} 6818596Ssteve.reinhardt@amd.com 6824762Snate@binkert.orgEmbeddedSwig embed_swig_${module}(init_${module}); 6837674Snate@binkert.org''') 6847674Snate@binkert.org code.write(str(target[0])) 6857674Snate@binkert.org 6867674Snate@binkert.org# Build all swig modules 6877674Snate@binkert.orgfor swig in SwigSource.all: 6887674Snate@binkert.org env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 6897674Snate@binkert.org MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6907674Snate@binkert.org '-o ${TARGETS[0]} $SOURCES', Transform("SWIG"))) 6917674Snate@binkert.org cc_file = str(swig.tnode) 6927674Snate@binkert.org init_file = '%s/init_%s.cc' % (dirname(cc_file), basename(cc_file)) 6937674Snate@binkert.org env.Command(init_file, Value(swig.module), 6947674Snate@binkert.org MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW"))) 6957674Snate@binkert.org Source(init_file, **swig.guards) 6967674Snate@binkert.org 6977674Snate@binkert.org# 6984762Snate@binkert.org# Handle debug flags 6996143Snate@binkert.org# 7006143Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 7017756SAli.Saidi@ARM.com assert(len(target) == 1 and len(source) == 1) 7027816Ssteve.reinhardt@amd.com 7038235Snate@binkert.org val = eval(source[0].get_contents()) 7048596Ssteve.reinhardt@amd.com name, compound, desc = val 7057756SAli.Saidi@ARM.com compound = list(sorted(compound)) 7067816Ssteve.reinhardt@amd.com 7078235Snate@binkert.org code = code_formatter() 7084382Sbinkertn@umich.edu 7099396Sandreas.hansson@arm.com # file header 7109396Sandreas.hansson@arm.com code(''' 7119396Sandreas.hansson@arm.com/* 7129396Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated 7139396Sandreas.hansson@arm.com */ 7149396Sandreas.hansson@arm.com 7159396Sandreas.hansson@arm.com#include "base/debug.hh" 7169396Sandreas.hansson@arm.com''') 7179396Sandreas.hansson@arm.com 7189396Sandreas.hansson@arm.com for flag in compound: 7199396Sandreas.hansson@arm.com code('#include "debug/$flag.hh"') 7209396Sandreas.hansson@arm.com code() 7219396Sandreas.hansson@arm.com code('namespace Debug {') 7229396Sandreas.hansson@arm.com code() 7239396Sandreas.hansson@arm.com 7249396Sandreas.hansson@arm.com if not compound: 7259396Sandreas.hansson@arm.com code('SimpleFlag $name("$name", "$desc");') 7269396Sandreas.hansson@arm.com else: 7278232Snate@binkert.org code('CompoundFlag $name("$name", "$desc",') 7288232Snate@binkert.org code.indent() 7298232Snate@binkert.org last = len(compound) - 1 7308232Snate@binkert.org for i,flag in enumerate(compound): 7318232Snate@binkert.org if i != last: 7326229Snate@binkert.org code('$flag,') 7338232Snate@binkert.org else: 7348232Snate@binkert.org code('$flag);') 7358232Snate@binkert.org code.dedent() 7366229Snate@binkert.org 7377673Snate@binkert.org code() 7385517Snate@binkert.org code('} // namespace Debug') 7395517Snate@binkert.org 7407673Snate@binkert.org code.write(str(target[0])) 7415517Snate@binkert.org 7425517Snate@binkert.orgdef makeDebugFlagHH(target, source, env): 7435517Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 7445517Snate@binkert.org 7458232Snate@binkert.org val = eval(source[0].get_contents()) 7467673Snate@binkert.org name, compound, desc = val 7477673Snate@binkert.org 7488232Snate@binkert.org code = code_formatter() 7498232Snate@binkert.org 7508232Snate@binkert.org # file header boilerplate 7518232Snate@binkert.org code('''\ 7527673Snate@binkert.org/* 7535517Snate@binkert.org * DO NOT EDIT THIS FILE! 7548232Snate@binkert.org * 7558232Snate@binkert.org * Automatically generated by SCons 7568232Snate@binkert.org */ 7578232Snate@binkert.org 7587673Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 7598232Snate@binkert.org#define __DEBUG_${name}_HH__ 7608232Snate@binkert.org 7618232Snate@binkert.orgnamespace Debug { 7628232Snate@binkert.org''') 7638232Snate@binkert.org 7648232Snate@binkert.org if compound: 7657673Snate@binkert.org code('class CompoundFlag;') 7665517Snate@binkert.org code('class SimpleFlag;') 7678232Snate@binkert.org 7688232Snate@binkert.org if compound: 7695517Snate@binkert.org code('extern CompoundFlag $name;') 7707673Snate@binkert.org for flag in compound: 7715517Snate@binkert.org code('extern SimpleFlag $flag;') 7728232Snate@binkert.org else: 7738232Snate@binkert.org code('extern SimpleFlag $name;') 7745517Snate@binkert.org 7758232Snate@binkert.org code(''' 7768232Snate@binkert.org} 7778232Snate@binkert.org 7787673Snate@binkert.org#endif // __DEBUG_${name}_HH__ 7795517Snate@binkert.org''') 7805517Snate@binkert.org 7817673Snate@binkert.org code.write(str(target[0])) 7825517Snate@binkert.org 7835517Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()): 7845517Snate@binkert.org n, compound, desc = flag 7858232Snate@binkert.org assert n == name 7865517Snate@binkert.org 7875517Snate@binkert.org env.Command('debug/%s.hh' % name, Value(flag), 7888232Snate@binkert.org MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 7898232Snate@binkert.org env.Command('debug/%s.cc' % name, Value(flag), 7905517Snate@binkert.org MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 7918232Snate@binkert.org Source('debug/%s.cc' % name) 7928232Snate@binkert.org 7935517Snate@binkert.org# Embed python files. All .py files that have been indicated by a 7948232Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 7958232Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 7968232Snate@binkert.org# byte code, compress it, and then generate a c++ file that 7975517Snate@binkert.org# inserts the result into an array. 7988232Snate@binkert.orgdef embedPyFile(target, source, env): 7998232Snate@binkert.org def c_str(string): 8008232Snate@binkert.org if string is None: 8018232Snate@binkert.org return "0" 8028232Snate@binkert.org return '"%s"' % string 8038232Snate@binkert.org 8045517Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8058232Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 8068232Snate@binkert.org as just bytes with a label in the data section''' 8075517Snate@binkert.org 8088232Snate@binkert.org src = file(str(source[0]), 'r').read() 8097673Snate@binkert.org 8105517Snate@binkert.org pysource = PySource.tnodes[source[0]] 8117673Snate@binkert.org compiled = compile(src, pysource.abspath, 'exec') 8125517Snate@binkert.org marshalled = marshal.dumps(compiled) 8138232Snate@binkert.org compressed = zlib.compress(marshalled) 8148232Snate@binkert.org data = compressed 8158232Snate@binkert.org sym = pysource.symname 8165192Ssaidi@eecs.umich.edu 8178232Snate@binkert.org code = code_formatter() 8188232Snate@binkert.org code('''\ 8198232Snate@binkert.org#include "sim/init.hh" 8208232Snate@binkert.org 8218232Snate@binkert.orgnamespace { 8225192Ssaidi@eecs.umich.edu 8237674Snate@binkert.orgconst char data_${sym}[] = { 8245522Snate@binkert.org''') 8255522Snate@binkert.org code.indent() 8267674Snate@binkert.org step = 16 8277674Snate@binkert.org for i in xrange(0, len(data), step): 8287674Snate@binkert.org x = array.array('B', data[i:i+step]) 8297674Snate@binkert.org code(''.join('%d,' % d for d in x)) 8307674Snate@binkert.org code.dedent() 8317674Snate@binkert.org 8327674Snate@binkert.org code('''}; 8337674Snate@binkert.org 8345522Snate@binkert.orgEmbeddedPython embedded_${sym}( 8355522Snate@binkert.org ${{c_str(pysource.arcname)}}, 8365522Snate@binkert.org ${{c_str(pysource.abspath)}}, 8375517Snate@binkert.org ${{c_str(pysource.modpath)}}, 8385522Snate@binkert.org data_${sym}, 8395517Snate@binkert.org ${{len(data)}}, 8406143Snate@binkert.org ${{len(marshalled)}}); 8416727Ssteve.reinhardt@amd.com 8425522Snate@binkert.org} // anonymous namespace 8435522Snate@binkert.org''') 8445522Snate@binkert.org code.write(str(target[0])) 8457674Snate@binkert.org 8465517Snate@binkert.orgfor source in PySource.all: 8477673Snate@binkert.org env.Command(source.cpp, source.tnode, 8487673Snate@binkert.org MakeAction(embedPyFile, Transform("EMBED PY"))) 8497674Snate@binkert.org Source(source.cpp) 8507673Snate@binkert.org 8517674Snate@binkert.org######################################################################## 8527674Snate@binkert.org# 8538946Sandreas.hansson@arm.com# Define binaries. Each different build type (debug, opt, etc.) gets 8547674Snate@binkert.org# a slightly different build environment. 8557674Snate@binkert.org# 8567674Snate@binkert.org 8575522Snate@binkert.org# List of constructed environments to pass back to SConstruct 8585522Snate@binkert.orgenvList = [] 8597674Snate@binkert.org 8607674Snate@binkert.orgdate_source = Source('base/date.cc', skip_lib=True) 8617674Snate@binkert.org 8627674Snate@binkert.org# Function to create a new build environment as clone of current 8637673Snate@binkert.org# environment 'env' with modified object suffix and optional stripped 8647674Snate@binkert.org# binary. Additional keyword arguments are appended to corresponding 8657674Snate@binkert.org# build environment vars. 8667674Snate@binkert.orgdef makeEnv(label, objsfx, strip = False, **kwargs): 8677674Snate@binkert.org # SCons doesn't know to append a library suffix when there is a '.' in the 8687674Snate@binkert.org # name. Use '_' instead. 8697674Snate@binkert.org libname = 'm5_' + label 8707674Snate@binkert.org exename = 'm5.' + label 8717674Snate@binkert.org 8727811Ssteve.reinhardt@amd.com new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 8737674Snate@binkert.org new_env.Label = label 8747673Snate@binkert.org new_env.Append(**kwargs) 8755522Snate@binkert.org 8766143Snate@binkert.org swig_env = new_env.Clone() 8777756SAli.Saidi@ARM.com swig_env.Append(CCFLAGS='-Werror') 8787816Ssteve.reinhardt@amd.com if env['GCC']: 8797674Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-uninitialized') 8804382Sbinkertn@umich.edu swig_env.Append(CCFLAGS='-Wno-sign-compare') 8814382Sbinkertn@umich.edu swig_env.Append(CCFLAGS='-Wno-parentheses') 8824382Sbinkertn@umich.edu 8834382Sbinkertn@umich.edu werror_env = new_env.Clone() 8844382Sbinkertn@umich.edu werror_env.Append(CCFLAGS='-Werror') 8854382Sbinkertn@umich.edu 8864382Sbinkertn@umich.edu def make_obj(source, static, extra_deps = None): 8874382Sbinkertn@umich.edu '''This function adds the specified source to the correct 88810196SCurtis.Dunham@arm.com build environment, and returns the corresponding SCons Object 8894382Sbinkertn@umich.edu nodes''' 89010196SCurtis.Dunham@arm.com 89110196SCurtis.Dunham@arm.com if source.swig: 89210196SCurtis.Dunham@arm.com env = swig_env 89310196SCurtis.Dunham@arm.com elif source.Werror: 89410196SCurtis.Dunham@arm.com env = werror_env 89510196SCurtis.Dunham@arm.com else: 89610196SCurtis.Dunham@arm.com env = new_env 897955SN/A 8982655Sstever@eecs.umich.edu if static: 8992655Sstever@eecs.umich.edu obj = env.StaticObject(source.tnode) 9002655Sstever@eecs.umich.edu else: 9012655Sstever@eecs.umich.edu obj = env.SharedObject(source.tnode) 90210196SCurtis.Dunham@arm.com 9035601Snate@binkert.org if extra_deps: 9045601Snate@binkert.org env.Depends(obj, extra_deps) 90510196SCurtis.Dunham@arm.com 90610196SCurtis.Dunham@arm.com return obj 90710196SCurtis.Dunham@arm.com 9085522Snate@binkert.org sources = Source.get(main=False, skip_lib=False) 9095863Snate@binkert.org static_objs = [ make_obj(s, True) for s in sources ] 9105601Snate@binkert.org shared_objs = [ make_obj(s, False) for s in sources ] 9115601Snate@binkert.org 9125601Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 9135863Snate@binkert.org static_objs.append(static_date) 9149556Sandreas.hansson@arm.com 9159556Sandreas.hansson@arm.com shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 9169556Sandreas.hansson@arm.com shared_objs.append(shared_date) 9179556Sandreas.hansson@arm.com 9189556Sandreas.hansson@arm.com # First make a library of everything but main() so other programs can 9199556Sandreas.hansson@arm.com # link against m5. 9209556Sandreas.hansson@arm.com static_lib = new_env.StaticLibrary(libname, static_objs) 9219556Sandreas.hansson@arm.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 9229556Sandreas.hansson@arm.com 9235559Snate@binkert.org # Now link a stub with main() and the static library. 9249556Sandreas.hansson@arm.com main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 9259618Ssteve.reinhardt@amd.com 9269618Ssteve.reinhardt@amd.com for test in UnitTest.all: 9279618Ssteve.reinhardt@amd.com flags = { test.target : True } 92810238Sandreas.hansson@arm.com test_sources = Source.get(**flags) 92910238Sandreas.hansson@arm.com test_objs = [ make_obj(s, static=True) for s in test_sources ] 9309554Sandreas.hansson@arm.com testname = "unittest/%s.%s" % (test.target, label) 9319556Sandreas.hansson@arm.com new_env.Program(testname, main_objs + test_objs + static_objs) 9329556Sandreas.hansson@arm.com 9339556Sandreas.hansson@arm.com progname = exename 9349556Sandreas.hansson@arm.com if strip: 9359555Sandreas.hansson@arm.com progname += '.unstripped' 9369555Sandreas.hansson@arm.com 9379556Sandreas.hansson@arm.com targets = new_env.Program(progname, main_objs + static_objs) 9388737Skoansin.tan@gmail.com 9399556Sandreas.hansson@arm.com if strip: 9409556Sandreas.hansson@arm.com if sys.platform == 'sunos5': 9419556Sandreas.hansson@arm.com cmd = 'cp $SOURCE $TARGET; strip $TARGET' 9429554Sandreas.hansson@arm.com else: 9438945Ssteve.reinhardt@amd.com cmd = 'strip $SOURCE -o $TARGET' 9448945Ssteve.reinhardt@amd.com targets = new_env.Command(exename, progname, 9458945Ssteve.reinhardt@amd.com MakeAction(cmd, Transform("STRIP"))) 9466143Snate@binkert.org 9476143Snate@binkert.org new_env.M5Binary = targets[0] 9486143Snate@binkert.org envList.append(new_env) 9496143Snate@binkert.org 9506143Snate@binkert.org# Debug binary 9516143Snate@binkert.orgccflags = {} 9526143Snate@binkert.orgif env['GCC']: 9538945Ssteve.reinhardt@amd.com if sys.platform == 'sunos5': 9548945Ssteve.reinhardt@amd.com ccflags['debug'] = '-gstabs+' 9556143Snate@binkert.org else: 9566143Snate@binkert.org ccflags['debug'] = '-ggdb3' 9576143Snate@binkert.org ccflags['opt'] = '-g -O3' 9586143Snate@binkert.org ccflags['fast'] = '-O3' 9596143Snate@binkert.org ccflags['prof'] = '-O3 -g -pg' 9606143Snate@binkert.orgelif env['SUNCC']: 9616143Snate@binkert.org ccflags['debug'] = '-g0' 9626143Snate@binkert.org ccflags['opt'] = '-g -O' 9636143Snate@binkert.org ccflags['fast'] = '-fast' 9646143Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9656143Snate@binkert.orgelif env['ICC']: 9666143Snate@binkert.org ccflags['debug'] = '-g -O0' 9676143Snate@binkert.org ccflags['opt'] = '-g -O' 9688594Snate@binkert.org ccflags['fast'] = '-fast' 9698594Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9708594Snate@binkert.orgelse: 9718594Snate@binkert.org print 'Unknown compiler, please fix compiler options' 9726143Snate@binkert.org Exit(1) 9736143Snate@binkert.org 9746143Snate@binkert.orgmakeEnv('debug', '.do', 9756143Snate@binkert.org CCFLAGS = Split(ccflags['debug']), 9766143Snate@binkert.org CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 9776240Snate@binkert.org 9785554Snate@binkert.org# Optimized binary 9795522Snate@binkert.orgmakeEnv('opt', '.o', 9805522Snate@binkert.org CCFLAGS = Split(ccflags['opt']), 9815797Snate@binkert.org CPPDEFINES = ['TRACING_ON=1']) 9825797Snate@binkert.org 9835522Snate@binkert.org# "Fast" binary 9845601Snate@binkert.orgmakeEnv('fast', '.fo', strip = True, 9858233Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 9868233Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 9878235Snate@binkert.org 9888235Snate@binkert.org# Profiled binary 9898235Snate@binkert.orgmakeEnv('prof', '.po', 9908235Snate@binkert.org CCFLAGS = Split(ccflags['prof']), 9919003SAli.Saidi@ARM.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 9929003SAli.Saidi@ARM.com LINKFLAGS = '-pg') 99310196SCurtis.Dunham@arm.com 99410196SCurtis.Dunham@arm.comReturn('envList') 9958235Snate@binkert.org