SConscript revision 8745
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 44955SN/A# This file defines how to build a particular configuration of gem5 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 526108Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 535517Snate@binkert.org 546143Snate@binkert.orgfrom m5.util import code_formatter 556143Snate@binkert.org 566143Snate@binkert.org######################################################################## 576143Snate@binkert.org# Code for adding source files of various types 586143Snate@binkert.org# 596143Snate@binkert.org# When specifying a source file of some type, a set of guards can be 606143Snate@binkert.org# specified for that file. When get() is used to find the files, if 616143Snate@binkert.org# get specifies a set of filters, only files that match those filters 626143Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 636143Snate@binkert.org# false). Current filters are: 646143Snate@binkert.org# main -- specifies the gem5 main() function 656143Snate@binkert.org# skip_lib -- do not put this file into the gem5 library 666143Snate@binkert.org# <unittest> -- unit tests use filters based on the unit test name 676143Snate@binkert.org# 686143Snate@binkert.org# A parent can now be specified for a source file and default filter 694762Snate@binkert.org# values will be retrieved recursively from parents (children override 706143Snate@binkert.org# parents). 716143Snate@binkert.org# 726143Snate@binkert.orgclass SourceMeta(type): 736143Snate@binkert.org '''Meta class for source files that keeps track of all files of a 746143Snate@binkert.org particular type and has a get function for finding all functions 756143Snate@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 806143Snate@binkert.org def get(cls, **guards): 816143Snate@binkert.org '''Find all files that match the specified guards. If a source 826143Snate@binkert.org file does not specify a flag, the default is False''' 836143Snate@binkert.org for src in cls.all: 846143Snate@binkert.org for flag,value in guards.iteritems(): 856143Snate@binkert.org # if the flag is found and has a different value, skip 866143Snate@binkert.org # this file 876143Snate@binkert.org if src.all_guards.get(flag, False) != value: 886143Snate@binkert.org break 896143Snate@binkert.org else: 906143Snate@binkert.org yield src 916143Snate@binkert.org 926143Snate@binkert.orgclass SourceFile(object): 936143Snate@binkert.org '''Base object that encapsulates the notion of a source file. 946143Snate@binkert.org This includes, the source node, target node, various manipulations 956143Snate@binkert.org of those. A source file also specifies a set of guards which 966143Snate@binkert.org describing which builds the source file applies to. A parent can 976143Snate@binkert.org also be specified to get default guards from''' 986143Snate@binkert.org __metaclass__ = SourceMeta 996143Snate@binkert.org def __init__(self, source, parent=None, **guards): 1006143Snate@binkert.org self.guards = guards 1016143Snate@binkert.org self.parent = parent 1026143Snate@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): 1126143Snate@binkert.org base.all.append(self) 1135522Snate@binkert.org 1146143Snate@binkert.org @property 1156143Snate@binkert.org def filename(self): 1166143Snate@binkert.org return str(self.tnode) 1176143Snate@binkert.org 1186143Snate@binkert.org @property 1196143Snate@binkert.org def dirname(self): 1206143Snate@binkert.org return dirname(self.filename) 1216143Snate@binkert.org 1226143Snate@binkert.org @property 1236143Snate@binkert.org def basename(self): 1245522Snate@binkert.org return basename(self.filename) 1255522Snate@binkert.org 1265522Snate@binkert.org @property 1275522Snate@binkert.org def extname(self): 1285604Snate@binkert.org index = self.basename.rfind('.') 1295604Snate@binkert.org if index <= 0: 1306143Snate@binkert.org # dot files aren't extensions 1316143Snate@binkert.org return self.basename, None 1324762Snate@binkert.org 1334762Snate@binkert.org return self.basename[:index], self.basename[index+1:] 1346143Snate@binkert.org 1356143Snate@binkert.org @property 1366143Snate@binkert.org def all_guards(self): 1376143Snate@binkert.org '''find all guards for this object getting default values 1384762Snate@binkert.org recursively from its parents''' 1396143Snate@binkert.org guards = {} 1406143Snate@binkert.org if self.parent: 1416143Snate@binkert.org guards.update(self.parent.guards) 1426143Snate@binkert.org guards.update(self.guards) 1436143Snate@binkert.org return guards 1446143Snate@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 1475604Snate@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 1514762Snate@binkert.org 1526143Snate@binkert.orgclass Source(SourceFile): 1534762Snate@binkert.org '''Add a c/c++ source file to the build''' 1544762Snate@binkert.org def __init__(self, source, Werror=True, swig=False, **guards): 1554762Snate@binkert.org '''specify the source file, and any guards''' 1566143Snate@binkert.org super(Source, self).__init__(source, **guards) 1576143Snate@binkert.org 1584762Snate@binkert.org self.Werror = Werror 1596143Snate@binkert.org self.swig = swig 1606143Snate@binkert.org 1616143Snate@binkert.orgclass PySource(SourceFile): 1626143Snate@binkert.org '''Add a python source file to the named package''' 1634762Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1646143Snate@binkert.org modules = {} 1654762Snate@binkert.org tnodes = {} 1666143Snate@binkert.org symnames = {} 1674762Snate@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) 1716143Snate@binkert.org 1726143Snate@binkert.org modname,ext = self.extname 1736143Snate@binkert.org assert ext == 'py' 1746143Snate@binkert.org 1756143Snate@binkert.org if package: 1766143Snate@binkert.org path = package.split('.') 1776143Snate@binkert.org else: 1786143Snate@binkert.org path = [] 1796143Snate@binkert.org 1806143Snate@binkert.org modpath = path[:] 181955SN/A if modname != '__init__': 1825584Snate@binkert.org modpath += [ modname ] 1835584Snate@binkert.org modpath = '.'.join(modpath) 1845584Snate@binkert.org 1855584Snate@binkert.org arcpath = path + [ self.basename ] 1866143Snate@binkert.org abspath = self.snode.abspath 1876143Snate@binkert.org if not exists(abspath): 1886143Snate@binkert.org abspath = self.tnode.abspath 1895584Snate@binkert.org 1904382Sbinkertn@umich.edu self.package = package 1914202Sbinkertn@umich.edu self.modname = modname 1924382Sbinkertn@umich.edu self.modpath = modpath 1934382Sbinkertn@umich.edu self.arcname = joinpath(*arcpath) 1944382Sbinkertn@umich.edu self.abspath = abspath 1955584Snate@binkert.org self.compiled = File(self.filename + 'c') 1964382Sbinkertn@umich.edu self.cpp = File(self.filename + '.cc') 1974382Sbinkertn@umich.edu self.symname = PySource.invalid_sym_char.sub('_', modpath) 1984382Sbinkertn@umich.edu 1995192Ssaidi@eecs.umich.edu PySource.modules[modpath] = self 2005192Ssaidi@eecs.umich.edu PySource.tnodes[self.tnode] = self 2015799Snate@binkert.org PySource.symnames[self.symname] = self 2025799Snate@binkert.org 2035799Snate@binkert.orgclass SimObject(PySource): 2045192Ssaidi@eecs.umich.edu '''Add a SimObject python file as a python source object and add 2055799Snate@binkert.org it to a list of sim object modules''' 2065192Ssaidi@eecs.umich.edu 2075799Snate@binkert.org fixed = False 2085799Snate@binkert.org modnames = [] 2095192Ssaidi@eecs.umich.edu 2105192Ssaidi@eecs.umich.edu def __init__(self, source, **guards): 2115192Ssaidi@eecs.umich.edu '''Specify the source file and any guards (automatically in 2125799Snate@binkert.org the m5.objects package)''' 2135192Ssaidi@eecs.umich.edu super(SimObject, self).__init__('m5.objects', source, **guards) 2145192Ssaidi@eecs.umich.edu if self.fixed: 2155192Ssaidi@eecs.umich.edu raise AttributeError, "Too late to call SimObject now." 2165192Ssaidi@eecs.umich.edu 2175192Ssaidi@eecs.umich.edu bisect.insort_right(SimObject.modnames, self.modname) 2185192Ssaidi@eecs.umich.edu 2194382Sbinkertn@umich.educlass SwigSource(SourceFile): 2204382Sbinkertn@umich.edu '''Add a swig file to build''' 2214382Sbinkertn@umich.edu 2222667Sstever@eecs.umich.edu def __init__(self, package, source, **guards): 2232667Sstever@eecs.umich.edu '''Specify the python package, the source file, and any guards''' 2242667Sstever@eecs.umich.edu super(SwigSource, self).__init__(source, **guards) 2252667Sstever@eecs.umich.edu 2262667Sstever@eecs.umich.edu modname,ext = self.extname 2272667Sstever@eecs.umich.edu assert ext == 'i' 2285742Snate@binkert.org 2295742Snate@binkert.org self.module = modname 2305742Snate@binkert.org cc_file = joinpath(self.dirname, modname + '_wrap.cc') 2312037SN/A py_file = joinpath(self.dirname, modname + '.py') 2322037SN/A 2332037SN/A self.cc_source = Source(cc_file, swig=True, parent=self) 2345793Snate@binkert.org self.py_source = PySource(package, py_file, parent=self) 2355793Snate@binkert.org 2365793Snate@binkert.orgclass UnitTest(object): 2375793Snate@binkert.org '''Create a UnitTest''' 2385793Snate@binkert.org 2394382Sbinkertn@umich.edu all = [] 2404762Snate@binkert.org def __init__(self, target, *sources): 2415344Sstever@gmail.com '''Specify the target name and any sources. Sources that are 2424382Sbinkertn@umich.edu not SourceFiles are evalued with Source(). All files are 2435341Sstever@gmail.com guarded with a guard of the same name as the UnitTest 2445742Snate@binkert.org target.''' 2455742Snate@binkert.org 2465742Snate@binkert.org srcs = [] 2475742Snate@binkert.org for src in sources: 2485742Snate@binkert.org if not isinstance(src, SourceFile): 2494762Snate@binkert.org src = Source(src, skip_lib=True) 2505742Snate@binkert.org src.guards[target] = True 2515742Snate@binkert.org srcs.append(src) 2525742Snate@binkert.org 2535742Snate@binkert.org self.sources = srcs 2545742Snate@binkert.org self.target = target 2555742Snate@binkert.org UnitTest.all.append(self) 2565742Snate@binkert.org 2575341Sstever@gmail.com# Children should have access 2585742Snate@binkert.orgExport('Source') 2595341Sstever@gmail.comExport('PySource') 2604773Snate@binkert.orgExport('SimObject') 2616108Snate@binkert.orgExport('SwigSource') 2621858SN/AExport('UnitTest') 2631085SN/A 2644382Sbinkertn@umich.edu######################################################################## 2654382Sbinkertn@umich.edu# 2664762Snate@binkert.org# Debug Flags 2674762Snate@binkert.org# 2684762Snate@binkert.orgdebug_flags = {} 2695517Snate@binkert.orgdef DebugFlag(name, desc=None): 2705517Snate@binkert.org if name in debug_flags: 2715517Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2725517Snate@binkert.org debug_flags[name] = (name, (), desc) 2735517Snate@binkert.org 2745517Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 2755517Snate@binkert.org if name in debug_flags: 2765517Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2775517Snate@binkert.org 2785517Snate@binkert.org compound = tuple(flags) 2795517Snate@binkert.org debug_flags[name] = (name, compound, desc) 2805517Snate@binkert.org 2815517Snate@binkert.orgExport('DebugFlag') 2825517Snate@binkert.orgExport('CompoundFlag') 2835517Snate@binkert.org 2845517Snate@binkert.org######################################################################## 2855517Snate@binkert.org# 2865798Snate@binkert.org# Set some compiler variables 2875517Snate@binkert.org# 2885517Snate@binkert.org 2895517Snate@binkert.org# Include file paths are rooted in this directory. SCons will 2905517Snate@binkert.org# automatically expand '.' to refer to both the source directory and 2915517Snate@binkert.org# the corresponding build directory to pick up generated include 2925517Snate@binkert.org# files. 2935517Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 2945517Snate@binkert.org 2956143Snate@binkert.orgfor extra_dir in extras_dir_list: 2966143Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 2975517Snate@binkert.org 2985517Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 2995517Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308 3005517Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3015517Snate@binkert.org Dir(root[len(base_dir) + 1:]) 3025517Snate@binkert.org 3035517Snate@binkert.org######################################################################## 3045517Snate@binkert.org# 3055517Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories 3065517Snate@binkert.org# 3075517Snate@binkert.org 3085517Snate@binkert.orghere = Dir('.').srcnode().abspath 3095517Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3105517Snate@binkert.org if root == here: 3115798Snate@binkert.org # we don't want to recurse back into this SConscript 3125798Snate@binkert.org continue 3135517Snate@binkert.org 3145517Snate@binkert.org if 'SConscript' in files: 3156143Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3166143Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3176143Snate@binkert.org 3186143Snate@binkert.orgfor extra_dir in extras_dir_list: 3195517Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 3206143Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 3215517Snate@binkert.org # if build lives in the extras directory, don't walk down it 3225517Snate@binkert.org if 'build' in dirs: 3235517Snate@binkert.org dirs.remove('build') 3245517Snate@binkert.org 3255517Snate@binkert.org if 'SConscript' in files: 3265517Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3276143Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3286143Snate@binkert.org 3295517Snate@binkert.orgfor opt in export_vars: 3304762Snate@binkert.org env.ConfigFile(opt) 3315517Snate@binkert.org 3324762Snate@binkert.orgdef makeTheISA(source, target, env): 3335517Snate@binkert.org isas = [ src.get_contents() for src in source ] 3345517Snate@binkert.org target_isa = env['TARGET_ISA'] 3356143Snate@binkert.org def define(isa): 3366143Snate@binkert.org return isa.upper() + '_ISA' 3375517Snate@binkert.org 3385517Snate@binkert.org def namespace(isa): 3395517Snate@binkert.org return isa[0].upper() + isa[1:].lower() + 'ISA' 3405517Snate@binkert.org 3415517Snate@binkert.org 3425517Snate@binkert.org code = code_formatter() 3435517Snate@binkert.org code('''\ 3445517Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 3455517Snate@binkert.org#define __CONFIG_THE_ISA_HH__ 3465517Snate@binkert.org 3476143Snate@binkert.org''') 3485517Snate@binkert.org 3495517Snate@binkert.org for i,isa in enumerate(isas): 3505517Snate@binkert.org code('#define $0 $1', define(isa), i + 1) 3515517Snate@binkert.org 3525517Snate@binkert.org code(''' 3535517Snate@binkert.org 3544762Snate@binkert.org#define THE_ISA ${{define(target_isa)}} 3554762Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 3564762Snate@binkert.org 3574762Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''') 3584762Snate@binkert.org 3594762Snate@binkert.org code.write(str(target[0])) 3606143Snate@binkert.org 3614762Snate@binkert.orgenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3624762Snate@binkert.org MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3634762Snate@binkert.org 3644762Snate@binkert.org######################################################################## 3654382Sbinkertn@umich.edu# 3664382Sbinkertn@umich.edu# Prevent any SimObjects from being added after this point, they 3675517Snate@binkert.org# should all have been added in the SConscripts above 3685517Snate@binkert.org# 3695517Snate@binkert.orgSimObject.fixed = True 3705517Snate@binkert.org 3715798Snate@binkert.orgclass DictImporter(object): 3725798Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 3735824Ssaidi@eecs.umich.edu map to arbitrary filenames.''' 3745517Snate@binkert.org def __init__(self, modules): 3755517Snate@binkert.org self.modules = modules 3765863Snate@binkert.org self.installed = set() 3775798Snate@binkert.org 3785798Snate@binkert.org def __del__(self): 3795798Snate@binkert.org self.unload() 3805798Snate@binkert.org 3815517Snate@binkert.org def unload(self): 3825517Snate@binkert.org import sys 3835517Snate@binkert.org for module in self.installed: 3845517Snate@binkert.org del sys.modules[module] 3855517Snate@binkert.org self.installed = set() 3865517Snate@binkert.org 3875517Snate@binkert.org def find_module(self, fullname, path): 3885517Snate@binkert.org if fullname == 'm5.defines': 3895798Snate@binkert.org return self 3905798Snate@binkert.org 3915798Snate@binkert.org if fullname == 'm5.objects': 3925798Snate@binkert.org return self 3935798Snate@binkert.org 3945798Snate@binkert.org if fullname.startswith('m5.internal'): 3955517Snate@binkert.org return None 3965517Snate@binkert.org 3975517Snate@binkert.org source = self.modules.get(fullname, None) 3985517Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 3995517Snate@binkert.org return self 4005517Snate@binkert.org 4015517Snate@binkert.org return None 4025517Snate@binkert.org 4035517Snate@binkert.org def load_module(self, fullname): 4044762Snate@binkert.org mod = imp.new_module(fullname) 4054382Sbinkertn@umich.edu sys.modules[fullname] = mod 4066143Snate@binkert.org self.installed.add(fullname) 4075517Snate@binkert.org 4084382Sbinkertn@umich.edu mod.__loader__ = self 4094382Sbinkertn@umich.edu if fullname == 'm5.objects': 4104762Snate@binkert.org mod.__path__ = fullname.split('.') 4114762Snate@binkert.org return mod 4124762Snate@binkert.org 4134762Snate@binkert.org if fullname == 'm5.defines': 4144762Snate@binkert.org mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 4155517Snate@binkert.org return mod 4165517Snate@binkert.org 4175517Snate@binkert.org source = self.modules[fullname] 4185517Snate@binkert.org if source.modname == '__init__': 4195517Snate@binkert.org mod.__path__ = source.modpath 4205517Snate@binkert.org mod.__file__ = source.abspath 4215517Snate@binkert.org 4225517Snate@binkert.org exec file(source.abspath, 'r') in mod.__dict__ 4236143Snate@binkert.org 4245517Snate@binkert.org return mod 4255517Snate@binkert.org 4265517Snate@binkert.orgimport m5.SimObject 4275517Snate@binkert.orgimport m5.params 4285517Snate@binkert.orgfrom m5.util import code_formatter 4295517Snate@binkert.org 4305517Snate@binkert.orgm5.SimObject.clear() 4315517Snate@binkert.orgm5.params.clear() 4325517Snate@binkert.org 4335517Snate@binkert.org# install the python importer so we can grab stuff from the source 4346143Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 4355517Snate@binkert.org# else we won't know about them for the rest of the stuff. 4365517Snate@binkert.orgimporter = DictImporter(PySource.modules) 4375517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 4385517Snate@binkert.org 4395517Snate@binkert.org# import all sim objects so we can populate the all_objects list 4405517Snate@binkert.org# make sure that we're working with a list, then let's sort it 4415517Snate@binkert.orgfor modname in SimObject.modnames: 4425517Snate@binkert.org exec('from m5.objects import %s' % modname) 4435517Snate@binkert.org 4445517Snate@binkert.org# we need to unload all of the currently imported modules so that they 4455517Snate@binkert.org# will be re-imported the next time the sconscript is run 4465517Snate@binkert.orgimporter.unload() 4475517Snate@binkert.orgsys.meta_path.remove(importer) 4485517Snate@binkert.org 4495517Snate@binkert.orgsim_objects = m5.SimObject.allClasses 4505517Snate@binkert.orgall_enums = m5.params.allEnums 4515517Snate@binkert.org 4525517Snate@binkert.orgall_params = {} 4535517Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 4546143Snate@binkert.org for param in obj._params.local.values(): 4555517Snate@binkert.org # load the ptype attribute now because it depends on the 4564762Snate@binkert.org # current version of SimObject.allClasses, but when scons 4574762Snate@binkert.org # actually uses the value, all versions of 4586143Snate@binkert.org # SimObject.allClasses will have been loaded 4596143Snate@binkert.org param.ptype 4606143Snate@binkert.org 4614762Snate@binkert.org if not hasattr(param, 'swig_decl'): 4624762Snate@binkert.org continue 4634762Snate@binkert.org pname = param.ptype_str 4645517Snate@binkert.org if pname not in all_params: 4654762Snate@binkert.org all_params[pname] = param 4664762Snate@binkert.org 4674762Snate@binkert.org######################################################################## 4685463Snate@binkert.org# 4695517Snate@binkert.org# calculate extra dependencies 4704762Snate@binkert.org# 4714762Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 4724762Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 4734762Snate@binkert.org 4744762Snate@binkert.org######################################################################## 4754762Snate@binkert.org# 4765463Snate@binkert.org# Commands for the basic automatically generated python files 4775517Snate@binkert.org# 4784762Snate@binkert.org 4794762Snate@binkert.org# Generate Python file containing a dict specifying the current 4804762Snate@binkert.org# buildEnv flags. 4816143Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 4826143Snate@binkert.org build_env = source[0].get_contents() 4836143Snate@binkert.org 4844762Snate@binkert.org code = code_formatter() 4854762Snate@binkert.org code(""" 4865517Snate@binkert.orgimport m5.internal 4874762Snate@binkert.orgimport m5.util 4884762Snate@binkert.org 4894762Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 4904762Snate@binkert.org 4915517Snate@binkert.orgcompileDate = m5.internal.core.compileDate 4924762Snate@binkert.org_globals = globals() 4934762Snate@binkert.orgfor key,val in m5.internal.core.__dict__.iteritems(): 4944762Snate@binkert.org if key.startswith('flag_'): 4954762Snate@binkert.org flag = key[5:] 4965517Snate@binkert.org _globals[flag] = val 4975517Snate@binkert.orgdel _globals 4985517Snate@binkert.org""") 4995517Snate@binkert.org code.write(target[0].abspath) 5005517Snate@binkert.org 5015517Snate@binkert.orgdefines_info = Value(build_env) 5025517Snate@binkert.org# Generate a file with all of the compile options in it 5035517Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info, 5045517Snate@binkert.org MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5055517Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 5065517Snate@binkert.org 5075517Snate@binkert.org# Generate python file containing info about the M5 source code 5085517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 5095517Snate@binkert.org code = code_formatter() 5105517Snate@binkert.org for src in source: 5115517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 5125517Snate@binkert.org code('$src = ${{repr(data)}}') 5135517Snate@binkert.org code.write(str(target[0])) 5145517Snate@binkert.org 5155517Snate@binkert.org# Generate a file that wraps the basic top level files 5165517Snate@binkert.orgenv.Command('python/m5/info.py', 5175517Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 5185517Snate@binkert.org MakeAction(makeInfoPyFile, Transform("INFO"))) 5195517Snate@binkert.orgPySource('m5', 'python/m5/info.py') 5205517Snate@binkert.org 5215517Snate@binkert.org######################################################################## 5225517Snate@binkert.org# 5235517Snate@binkert.org# Create all of the SimObject param headers and enum headers 5245517Snate@binkert.org# 5255517Snate@binkert.org 5265517Snate@binkert.orgdef createSimObjectParam(target, source, env): 5275517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5285517Snate@binkert.org 5295517Snate@binkert.org name = str(source[0].get_contents()) 5305517Snate@binkert.org obj = sim_objects[name] 5315517Snate@binkert.org 5325517Snate@binkert.org code = code_formatter() 5335517Snate@binkert.org obj.cxx_decl(code) 5345517Snate@binkert.org code.write(target[0].abspath) 5355517Snate@binkert.org 5365517Snate@binkert.orgdef createSwigParam(target, source, env): 5375517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5385517Snate@binkert.org 5395517Snate@binkert.org name = str(source[0].get_contents()) 5405517Snate@binkert.org param = all_params[name] 5415517Snate@binkert.org 5425517Snate@binkert.org code = code_formatter() 5435517Snate@binkert.org code('%module(package="m5.internal") $0_${name}', param.file_ext) 5445517Snate@binkert.org param.swig_decl(code) 5455517Snate@binkert.org code.write(target[0].abspath) 5465517Snate@binkert.org 5475517Snate@binkert.orgdef createEnumStrings(target, source, env): 5485517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5495517Snate@binkert.org 5505517Snate@binkert.org name = str(source[0].get_contents()) 5515517Snate@binkert.org obj = all_enums[name] 5525517Snate@binkert.org 5535517Snate@binkert.org code = code_formatter() 5545517Snate@binkert.org obj.cxx_def(code) 5555517Snate@binkert.org code.write(target[0].abspath) 5565517Snate@binkert.org 5575517Snate@binkert.orgdef createEnumParam(target, source, env): 5585517Snate@binkert.org assert len(target) == 1 and len(source) == 1 5595517Snate@binkert.org 5605517Snate@binkert.org name = str(source[0].get_contents()) 5615517Snate@binkert.org obj = all_enums[name] 5625610Snate@binkert.org 5635623Snate@binkert.org code = code_formatter() 5645623Snate@binkert.org obj.cxx_decl(code) 5655623Snate@binkert.org code.write(target[0].abspath) 5665610Snate@binkert.org 5675517Snate@binkert.orgdef createEnumSwig(target, source, env): 5685623Snate@binkert.org assert len(target) == 1 and len(source) == 1 5695623Snate@binkert.org 5705623Snate@binkert.org name = str(source[0].get_contents()) 5715623Snate@binkert.org obj = all_enums[name] 5725623Snate@binkert.org 5735623Snate@binkert.org code = code_formatter() 5745623Snate@binkert.org code('''\ 5755517Snate@binkert.org%module(package="m5.internal") enum_$name 5765610Snate@binkert.org 5775610Snate@binkert.org%{ 5785610Snate@binkert.org#include "enums/$name.hh" 5795610Snate@binkert.org%} 5805517Snate@binkert.org 5815517Snate@binkert.org%include "enums/$name.hh" 5825610Snate@binkert.org''') 5835610Snate@binkert.org code.write(target[0].abspath) 5845517Snate@binkert.org 5855517Snate@binkert.org# Generate all of the SimObject param struct header files 5865517Snate@binkert.orgparams_hh_files = [] 5875517Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 5885517Snate@binkert.org py_source = PySource.modules[simobj.__module__] 5895517Snate@binkert.org extra_deps = [ py_source.tnode ] 5905517Snate@binkert.org 5915517Snate@binkert.org hh_file = File('params/%s.hh' % name) 5925517Snate@binkert.org params_hh_files.append(hh_file) 5935517Snate@binkert.org env.Command(hh_file, Value(name), 5944762Snate@binkert.org MakeAction(createSimObjectParam, Transform("SO PARAM"))) 5956143Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 5966143Snate@binkert.org 5975463Snate@binkert.org# Generate any parameter header files needed 5984762Snate@binkert.orgparams_i_files = [] 5994762Snate@binkert.orgfor name,param in all_params.iteritems(): 6004762Snate@binkert.org i_file = File('python/m5/internal/%s_%s.i' % (param.file_ext, name)) 6016143Snate@binkert.org params_i_files.append(i_file) 6026143Snate@binkert.org env.Command(i_file, Value(name), 6034382Sbinkertn@umich.edu MakeAction(createSwigParam, Transform("SW PARAM"))) 6044382Sbinkertn@umich.edu env.Depends(i_file, depends) 6056143Snate@binkert.org SwigSource('m5.internal', i_file) 6066143Snate@binkert.org 6074382Sbinkertn@umich.edu# Generate all enum header files 6084762Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 6095517Snate@binkert.org py_source = PySource.modules[enum.__module__] 6105517Snate@binkert.org extra_deps = [ py_source.tnode ] 6115517Snate@binkert.org 6125517Snate@binkert.org cc_file = File('enums/%s.cc' % name) 6135517Snate@binkert.org env.Command(cc_file, Value(name), 6145517Snate@binkert.org MakeAction(createEnumStrings, Transform("ENUM STR"))) 6155522Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 6165517Snate@binkert.org Source(cc_file) 6175517Snate@binkert.org 6185517Snate@binkert.org hh_file = File('enums/%s.hh' % name) 6195517Snate@binkert.org env.Command(hh_file, Value(name), 6205517Snate@binkert.org MakeAction(createEnumParam, Transform("EN PARAM"))) 6216143Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6226143Snate@binkert.org 6236143Snate@binkert.org i_file = File('python/m5/internal/enum_%s.i' % name) 6245522Snate@binkert.org env.Command(i_file, Value(name), 6254382Sbinkertn@umich.edu MakeAction(createEnumSwig, Transform("ENUMSWIG"))) 6266229Snate@binkert.org env.Depends(i_file, depends + extra_deps) 6276229Snate@binkert.org SwigSource('m5.internal', i_file) 6286229Snate@binkert.org 6296229Snate@binkert.orgdef buildParam(target, source, env): 6306229Snate@binkert.org name = source[0].get_contents() 6316229Snate@binkert.org obj = sim_objects[name] 6326229Snate@binkert.org class_path = obj.cxx_class.split('::') 6336229Snate@binkert.org classname = class_path[-1] 6346229Snate@binkert.org namespaces = class_path[:-1] 6356229Snate@binkert.org params = obj._params.local.values() 6366229Snate@binkert.org 6376229Snate@binkert.org code = code_formatter() 6386229Snate@binkert.org 6396229Snate@binkert.org code('%module(package="m5.internal") param_$name') 6406229Snate@binkert.org code() 6416229Snate@binkert.org code('%{') 6426229Snate@binkert.org code('#include "params/$obj.hh"') 6436229Snate@binkert.org for param in params: 6446229Snate@binkert.org param.cxx_predecls(code) 6456229Snate@binkert.org code('%}') 6466229Snate@binkert.org code() 6475192Ssaidi@eecs.umich.edu 6485517Snate@binkert.org for param in params: 6495517Snate@binkert.org param.swig_predecls(code) 6505517Snate@binkert.org 6515517Snate@binkert.org code() 6526229Snate@binkert.org if obj._base: 6536229Snate@binkert.org code('%import "python/m5/internal/param_${{obj._base}}.i"') 6545799Snate@binkert.org code() 6555799Snate@binkert.org obj.swig_objdecls(code) 6565517Snate@binkert.org code() 6575517Snate@binkert.org 6585517Snate@binkert.org code('%include "params/$obj.hh"') 6595517Snate@binkert.org 6605517Snate@binkert.org code.write(target[0].abspath) 6615517Snate@binkert.org 6625799Snate@binkert.orgfor name in sim_objects.iterkeys(): 6635517Snate@binkert.org params_file = File('python/m5/internal/param_%s.i' % name) 6645517Snate@binkert.org env.Command(params_file, Value(name), 6655517Snate@binkert.org MakeAction(buildParam, Transform("BLDPARAM"))) 6665517Snate@binkert.org env.Depends(params_file, depends) 6675517Snate@binkert.org SwigSource('m5.internal', params_file) 6685517Snate@binkert.org 6695517Snate@binkert.org# Generate the main swig init file 6705799Snate@binkert.orgdef makeEmbeddedSwigInit(target, source, env): 6715517Snate@binkert.org code = code_formatter() 6725517Snate@binkert.org module = source[0].get_contents() 6735799Snate@binkert.org code('''\ 6745517Snate@binkert.org#include "sim/init.hh" 6755517Snate@binkert.org 6765517Snate@binkert.orgextern "C" { 6775517Snate@binkert.org void init_${module}(); 6785517Snate@binkert.org} 6795517Snate@binkert.org 6805517Snate@binkert.orgEmbeddedSwig embed_swig_${module}(init_${module}); 6815517Snate@binkert.org''') 6825799Snate@binkert.org code.write(str(target[0])) 6835517Snate@binkert.org 6845517Snate@binkert.org# Build all swig modules 6855517Snate@binkert.orgfor swig in SwigSource.all: 6865517Snate@binkert.org env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 6875517Snate@binkert.org MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 6885517Snate@binkert.org '-o ${TARGETS[0]} $SOURCES', Transform("SWIG"))) 6895517Snate@binkert.org cc_file = str(swig.tnode) 6905517Snate@binkert.org init_file = '%s/init_%s.cc' % (dirname(cc_file), basename(cc_file)) 6915517Snate@binkert.org env.Command(init_file, Value(swig.module), 6925517Snate@binkert.org MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW"))) 6935517Snate@binkert.org Source(init_file, **swig.guards) 6945517Snate@binkert.org 6956229Snate@binkert.org# 6965517Snate@binkert.org# Handle debug flags 6975517Snate@binkert.org# 6985517Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 6995517Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 7005517Snate@binkert.org 7015517Snate@binkert.org val = eval(source[0].get_contents()) 7025517Snate@binkert.org name, compound, desc = val 7035517Snate@binkert.org compound = list(sorted(compound)) 7045517Snate@binkert.org 7055517Snate@binkert.org code = code_formatter() 7065517Snate@binkert.org 7075517Snate@binkert.org # file header 7085517Snate@binkert.org code(''' 7095517Snate@binkert.org/* 7105517Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated 7115517Snate@binkert.org */ 7125517Snate@binkert.org 7135517Snate@binkert.org#include "base/debug.hh" 7145517Snate@binkert.org''') 7155517Snate@binkert.org 7165517Snate@binkert.org for flag in compound: 7175517Snate@binkert.org code('#include "debug/$flag.hh"') 7185517Snate@binkert.org code() 7195517Snate@binkert.org code('namespace Debug {') 7205517Snate@binkert.org code() 7215517Snate@binkert.org 7225517Snate@binkert.org if not compound: 7235517Snate@binkert.org code('SimpleFlag $name("$name", "$desc");') 7245517Snate@binkert.org else: 7255517Snate@binkert.org code('CompoundFlag $name("$name", "$desc",') 7265517Snate@binkert.org code.indent() 7275517Snate@binkert.org last = len(compound) - 1 7285517Snate@binkert.org for i,flag in enumerate(compound): 7295517Snate@binkert.org if i != last: 7305517Snate@binkert.org code('$flag,') 7315517Snate@binkert.org else: 7325517Snate@binkert.org code('$flag);') 7335517Snate@binkert.org code.dedent() 7345517Snate@binkert.org 7355517Snate@binkert.org code() 7365517Snate@binkert.org code('} // namespace Debug') 7375517Snate@binkert.org 7385517Snate@binkert.org code.write(str(target[0])) 7395517Snate@binkert.org 7405517Snate@binkert.orgdef makeDebugFlagHH(target, source, env): 7415517Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 7425517Snate@binkert.org 7435517Snate@binkert.org val = eval(source[0].get_contents()) 7445517Snate@binkert.org name, compound, desc = val 7455517Snate@binkert.org 7465517Snate@binkert.org code = code_formatter() 7475517Snate@binkert.org 7485517Snate@binkert.org # file header boilerplate 7495517Snate@binkert.org code('''\ 7505517Snate@binkert.org/* 7515517Snate@binkert.org * DO NOT EDIT THIS FILE! 7525517Snate@binkert.org * 7535517Snate@binkert.org * Automatically generated by SCons 7545517Snate@binkert.org */ 7555517Snate@binkert.org 7565517Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 7575517Snate@binkert.org#define __DEBUG_${name}_HH__ 7585517Snate@binkert.org 7595517Snate@binkert.orgnamespace Debug { 7605517Snate@binkert.org''') 7615517Snate@binkert.org 7625517Snate@binkert.org if compound: 7635517Snate@binkert.org code('class CompoundFlag;') 7645517Snate@binkert.org code('class SimpleFlag;') 7655517Snate@binkert.org 7665517Snate@binkert.org if compound: 7675517Snate@binkert.org code('extern CompoundFlag $name;') 7686229Snate@binkert.org for flag in compound: 7695517Snate@binkert.org code('extern SimpleFlag $flag;') 7705517Snate@binkert.org else: 7715517Snate@binkert.org code('extern SimpleFlag $name;') 7725517Snate@binkert.org 7735517Snate@binkert.org code(''' 7745517Snate@binkert.org} 7755517Snate@binkert.org 7765517Snate@binkert.org#endif // __DEBUG_${name}_HH__ 7775517Snate@binkert.org''') 7785517Snate@binkert.org 7795517Snate@binkert.org code.write(str(target[0])) 7805517Snate@binkert.org 7815517Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()): 7825517Snate@binkert.org n, compound, desc = flag 7835517Snate@binkert.org assert n == name 7845517Snate@binkert.org 7855517Snate@binkert.org env.Command('debug/%s.hh' % name, Value(flag), 7865517Snate@binkert.org MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 7875517Snate@binkert.org env.Command('debug/%s.cc' % name, Value(flag), 7885517Snate@binkert.org MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 7895517Snate@binkert.org Source('debug/%s.cc' % name) 7905517Snate@binkert.org 7915517Snate@binkert.org# Embed python files. All .py files that have been indicated by a 7925517Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 7935517Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 7945517Snate@binkert.org# byte code, compress it, and then generate a c++ file that 7955517Snate@binkert.org# inserts the result into an array. 7965517Snate@binkert.orgdef embedPyFile(target, source, env): 7975517Snate@binkert.org def c_str(string): 7985517Snate@binkert.org if string is None: 7995517Snate@binkert.org return "0" 8005517Snate@binkert.org return '"%s"' % string 8015517Snate@binkert.org 8025517Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8035517Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 8045517Snate@binkert.org as just bytes with a label in the data section''' 8055517Snate@binkert.org 8065517Snate@binkert.org src = file(str(source[0]), 'r').read() 8075517Snate@binkert.org 8085517Snate@binkert.org pysource = PySource.tnodes[source[0]] 8095517Snate@binkert.org compiled = compile(src, pysource.abspath, 'exec') 8105517Snate@binkert.org marshalled = marshal.dumps(compiled) 8115517Snate@binkert.org compressed = zlib.compress(marshalled) 8125517Snate@binkert.org data = compressed 8135517Snate@binkert.org sym = pysource.symname 8145517Snate@binkert.org 8155517Snate@binkert.org code = code_formatter() 8165517Snate@binkert.org code('''\ 8175517Snate@binkert.org#include "sim/init.hh" 8185517Snate@binkert.org 8195517Snate@binkert.orgnamespace { 8205517Snate@binkert.org 8215517Snate@binkert.orgconst char data_${sym}[] = { 8225517Snate@binkert.org''') 8235517Snate@binkert.org code.indent() 8245517Snate@binkert.org step = 16 8255517Snate@binkert.org for i in xrange(0, len(data), step): 8265517Snate@binkert.org x = array.array('B', data[i:i+step]) 8275517Snate@binkert.org code(''.join('%d,' % d for d in x)) 8285517Snate@binkert.org code.dedent() 8295517Snate@binkert.org 8306143Snate@binkert.org code('''}; 8315517Snate@binkert.org 8325192Ssaidi@eecs.umich.eduEmbeddedPython embedded_${sym}( 8335192Ssaidi@eecs.umich.edu ${{c_str(pysource.arcname)}}, 8345517Snate@binkert.org ${{c_str(pysource.abspath)}}, 8355517Snate@binkert.org ${{c_str(pysource.modpath)}}, 8365192Ssaidi@eecs.umich.edu data_${sym}, 8375192Ssaidi@eecs.umich.edu ${{len(data)}}, 8385522Snate@binkert.org ${{len(marshalled)}}); 8395522Snate@binkert.org 8405522Snate@binkert.org} // anonymous namespace 8415522Snate@binkert.org''') 8425522Snate@binkert.org code.write(str(target[0])) 8435522Snate@binkert.org 8445522Snate@binkert.orgfor source in PySource.all: 8455522Snate@binkert.org env.Command(source.cpp, source.tnode, 8465522Snate@binkert.org MakeAction(embedPyFile, Transform("EMBED PY"))) 8475522Snate@binkert.org Source(source.cpp) 8485517Snate@binkert.org 8495522Snate@binkert.org######################################################################## 8505522Snate@binkert.org# 8515517Snate@binkert.org# Define binaries. Each different build type (debug, opt, etc.) gets 8526143Snate@binkert.org# a slightly different build environment. 8535604Snate@binkert.org# 8545522Snate@binkert.org 8555522Snate@binkert.org# List of constructed environments to pass back to SConstruct 8565522Snate@binkert.orgenvList = [] 8575517Snate@binkert.org 8585522Snate@binkert.orgdate_source = Source('base/date.cc', skip_lib=True) 8595522Snate@binkert.org 8605522Snate@binkert.org# Function to create a new build environment as clone of current 8615522Snate@binkert.org# environment 'env' with modified object suffix and optional stripped 8625522Snate@binkert.org# binary. Additional keyword arguments are appended to corresponding 8635522Snate@binkert.org# build environment vars. 8645522Snate@binkert.orgdef makeEnv(label, objsfx, strip = False, **kwargs): 8655522Snate@binkert.org # SCons doesn't know to append a library suffix when there is a '.' in the 8665522Snate@binkert.org # name. Use '_' instead. 8675522Snate@binkert.org libname = 'gem5_' + label 8685522Snate@binkert.org exename = 'gem5.' + label 8695522Snate@binkert.org secondary_exename = 'm5.' + label 8705522Snate@binkert.org 8715522Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 8725522Snate@binkert.org new_env.Label = label 8735522Snate@binkert.org new_env.Append(**kwargs) 8745522Snate@binkert.org 8755522Snate@binkert.org swig_env = new_env.Clone() 8765522Snate@binkert.org swig_env.Append(CCFLAGS='-Werror') 8776143Snate@binkert.org if env['GCC']: 8785522Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-uninitialized') 8795522Snate@binkert.org swig_env.Append(CCFLAGS='-Wno-sign-compare') 8804382Sbinkertn@umich.edu swig_env.Append(CCFLAGS='-Wno-parentheses') 8815522Snate@binkert.org 8825522Snate@binkert.org werror_env = new_env.Clone() 8835522Snate@binkert.org werror_env.Append(CCFLAGS='-Werror') 8845522Snate@binkert.org 8855522Snate@binkert.org def make_obj(source, static, extra_deps = None): 8865522Snate@binkert.org '''This function adds the specified source to the correct 8875522Snate@binkert.org build environment, and returns the corresponding SCons Object 8884382Sbinkertn@umich.edu nodes''' 8895522Snate@binkert.org 8906143Snate@binkert.org if source.swig: 8915522Snate@binkert.org env = swig_env 8925522Snate@binkert.org elif source.Werror: 8935522Snate@binkert.org env = werror_env 8945522Snate@binkert.org else: 8955522Snate@binkert.org env = new_env 8965522Snate@binkert.org 8975522Snate@binkert.org if static: 8985522Snate@binkert.org obj = env.StaticObject(source.tnode) 8995522Snate@binkert.org else: 9005522Snate@binkert.org obj = env.SharedObject(source.tnode) 9015522Snate@binkert.org 9025522Snate@binkert.org if extra_deps: 9035522Snate@binkert.org env.Depends(obj, extra_deps) 9045522Snate@binkert.org 9055522Snate@binkert.org return obj 9065522Snate@binkert.org 9075522Snate@binkert.org sources = Source.get(main=False, skip_lib=False) 9085522Snate@binkert.org static_objs = [ make_obj(s, True) for s in sources ] 9095522Snate@binkert.org shared_objs = [ make_obj(s, False) for s in sources ] 9105522Snate@binkert.org 9115522Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 9125522Snate@binkert.org static_objs.append(static_date) 9135522Snate@binkert.org 9145522Snate@binkert.org shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 9155522Snate@binkert.org shared_objs.append(shared_date) 9165522Snate@binkert.org 9176143Snate@binkert.org # First make a library of everything but main() so other programs can 9186143Snate@binkert.org # link against m5. 9196143Snate@binkert.org static_lib = new_env.StaticLibrary(libname, static_objs) 9206143Snate@binkert.org shared_lib = new_env.SharedLibrary(libname, shared_objs) 9215522Snate@binkert.org 9224382Sbinkertn@umich.edu # Now link a stub with main() and the static library. 9234382Sbinkertn@umich.edu main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 9244382Sbinkertn@umich.edu 9254382Sbinkertn@umich.edu for test in UnitTest.all: 9264382Sbinkertn@umich.edu flags = { test.target : True } 9274382Sbinkertn@umich.edu test_sources = Source.get(**flags) 9284382Sbinkertn@umich.edu test_objs = [ make_obj(s, static=True) for s in test_sources ] 9294382Sbinkertn@umich.edu testname = "unittest/%s.%s" % (test.target, label) 9304382Sbinkertn@umich.edu new_env.Program(testname, main_objs + test_objs + static_objs) 9314382Sbinkertn@umich.edu 9326143Snate@binkert.org progname = exename 933955SN/A if strip: 9342655Sstever@eecs.umich.edu progname += '.unstripped' 9352655Sstever@eecs.umich.edu 9362655Sstever@eecs.umich.edu targets = new_env.Program(progname, main_objs + static_objs) 9372655Sstever@eecs.umich.edu 9382655Sstever@eecs.umich.edu if strip: 9395601Snate@binkert.org if sys.platform == 'sunos5': 9405601Snate@binkert.org cmd = 'cp $SOURCE $TARGET; strip $TARGET' 9415601Snate@binkert.org else: 9425601Snate@binkert.org cmd = 'strip $SOURCE -o $TARGET' 9435522Snate@binkert.org targets = new_env.Command(exename, progname, 9445863Snate@binkert.org MakeAction(cmd, Transform("STRIP"))) 9455601Snate@binkert.org 9465601Snate@binkert.org new_env.Command(secondary_exename, exename, 9475601Snate@binkert.org MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 9485863Snate@binkert.org 9496143Snate@binkert.org new_env.M5Binary = targets[0] 9505559Snate@binkert.org envList.append(new_env) 9515559Snate@binkert.org 9525559Snate@binkert.org# Debug binary 9535559Snate@binkert.orgccflags = {} 9545601Snate@binkert.orgif env['GCC']: 9556143Snate@binkert.org if sys.platform == 'sunos5': 9566143Snate@binkert.org ccflags['debug'] = '-gstabs+' 9576143Snate@binkert.org else: 9586143Snate@binkert.org ccflags['debug'] = '-ggdb3' 9596143Snate@binkert.org ccflags['opt'] = '-g -O3' 9606143Snate@binkert.org ccflags['fast'] = '-O3' 9616143Snate@binkert.org ccflags['prof'] = '-O3 -g -pg' 9626143Snate@binkert.orgelif env['SUNCC']: 9636143Snate@binkert.org ccflags['debug'] = '-g0' 9646143Snate@binkert.org ccflags['opt'] = '-g -O' 9656143Snate@binkert.org ccflags['fast'] = '-fast' 9666143Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9676143Snate@binkert.orgelif env['ICC']: 9686143Snate@binkert.org ccflags['debug'] = '-g -O0' 9696143Snate@binkert.org ccflags['opt'] = '-g -O' 9706143Snate@binkert.org ccflags['fast'] = '-fast' 9716143Snate@binkert.org ccflags['prof'] = '-fast -g -pg' 9726143Snate@binkert.orgelse: 9736143Snate@binkert.org print 'Unknown compiler, please fix compiler options' 9746143Snate@binkert.org Exit(1) 9756143Snate@binkert.org 9766143Snate@binkert.orgmakeEnv('debug', '.do', 9776143Snate@binkert.org CCFLAGS = Split(ccflags['debug']), 9786143Snate@binkert.org CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 9796143Snate@binkert.org 9806143Snate@binkert.org# Optimized binary 9816143Snate@binkert.orgmakeEnv('opt', '.o', 9826143Snate@binkert.org CCFLAGS = Split(ccflags['opt']), 9836143Snate@binkert.org CPPDEFINES = ['TRACING_ON=1']) 9846143Snate@binkert.org 9856143Snate@binkert.org# "Fast" binary 9866143Snate@binkert.orgmakeEnv('fast', '.fo', strip = True, 9876240Snate@binkert.org CCFLAGS = Split(ccflags['fast']), 9885554Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 9895522Snate@binkert.org 9905522Snate@binkert.org# Profiled binary 9915797Snate@binkert.orgmakeEnv('prof', '.po', 9925797Snate@binkert.org CCFLAGS = Split(ccflags['prof']), 9935522Snate@binkert.org CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 9945584Snate@binkert.org LINKFLAGS = '-pg') 9956143Snate@binkert.org 9965862Snate@binkert.orgReturn('envList') 9975584Snate@binkert.org