SConscript revision 5517
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 314762Snate@binkert.orgimport imp 32955SN/Aimport os 335517Snate@binkert.orgimport py_compile 34955SN/Aimport sys 355517Snate@binkert.orgimport zipfile 364202Sbinkertn@umich.edu 375342Sstever@gmail.comfrom os.path import basename, exists, isdir, isfile, join as joinpath 38955SN/A 394381Sbinkertn@umich.eduimport SCons 404381Sbinkertn@umich.edu 41955SN/A# This file defines how to build a particular configuration of M5 42955SN/A# based on variable settings in the 'env' build environment. 43955SN/A 444202Sbinkertn@umich.eduImport('*') 45955SN/A 464382Sbinkertn@umich.edu# Children need to see the environment 474382Sbinkertn@umich.eduExport('env') 484382Sbinkertn@umich.edu 495517Snate@binkert.orgbuild_env = dict([(opt, env[opt]) for opt in env.ExportOptions]) 505517Snate@binkert.org 514762Snate@binkert.orgdef sort_list(_list): 524762Snate@binkert.org """return a sorted copy of '_list'""" 534762Snate@binkert.org if isinstance(_list, list): 544762Snate@binkert.org _list = _list[:] 554762Snate@binkert.org else: 564762Snate@binkert.org _list = list(_list) 574762Snate@binkert.org _list.sort() 584762Snate@binkert.org return _list 594762Snate@binkert.org 604762Snate@binkert.orgclass PySourceFile(object): 614762Snate@binkert.org def __init__(self, package, source): 624762Snate@binkert.org filename = str(source) 634762Snate@binkert.org pyname = basename(filename) 644762Snate@binkert.org assert pyname.endswith('.py') 654762Snate@binkert.org name = pyname[:-3] 664762Snate@binkert.org path = package.split('.') 674762Snate@binkert.org modpath = path 684762Snate@binkert.org if name != '__init__': 694762Snate@binkert.org modpath += [name] 704762Snate@binkert.org modpath = '.'.join(modpath) 714762Snate@binkert.org 724762Snate@binkert.org arcpath = package.split('.') + [ pyname + 'c' ] 734762Snate@binkert.org arcname = joinpath(*arcpath) 744762Snate@binkert.org 754762Snate@binkert.org self.source = source 764762Snate@binkert.org self.pyname = pyname 774762Snate@binkert.org self.srcpath = source.srcnode().abspath 784762Snate@binkert.org self.package = package 794762Snate@binkert.org self.modpath = modpath 804762Snate@binkert.org self.arcname = arcname 814762Snate@binkert.org self.filename = filename 824762Snate@binkert.org self.compiled = File(filename + 'c') 834762Snate@binkert.org 844382Sbinkertn@umich.edu######################################################################## 854762Snate@binkert.org# Code for adding source files of various types 864382Sbinkertn@umich.edu# 874762Snate@binkert.orgcc_sources = [] 884381Sbinkertn@umich.edudef Source(source): 894762Snate@binkert.org '''Add a C/C++ source file to the build''' 904762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 914762Snate@binkert.org source = File(source) 924762Snate@binkert.org 934762Snate@binkert.org cc_sources.append(source) 944762Snate@binkert.org 954762Snate@binkert.orgpy_sources = [] 964762Snate@binkert.orgdef PySource(package, source): 974762Snate@binkert.org '''Add a python source file to the named package''' 984762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 994762Snate@binkert.org source = File(source) 1004762Snate@binkert.org 1014762Snate@binkert.org source = PySourceFile(package, source) 1024762Snate@binkert.org py_sources.append(source) 1034762Snate@binkert.org 1044762Snate@binkert.orgsim_objects_fixed = False 1054762Snate@binkert.orgsim_object_modfiles = set() 1064762Snate@binkert.orgdef SimObject(source): 1074762Snate@binkert.org '''Add a SimObject python file as a python source object and add 1084762Snate@binkert.org it to a list of sim object modules''' 1094762Snate@binkert.org 1104762Snate@binkert.org if sim_objects_fixed: 1114762Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 1124762Snate@binkert.org 1134762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1144762Snate@binkert.org source = File(source) 1154762Snate@binkert.org 1164762Snate@binkert.org PySource('m5.objects', source) 1174762Snate@binkert.org modfile = basename(str(source)) 1184762Snate@binkert.org assert modfile.endswith('.py') 1194762Snate@binkert.org modname = modfile[:-3] 1204762Snate@binkert.org sim_object_modfiles.add(modname) 1214762Snate@binkert.org 1224762Snate@binkert.orgswig_sources = [] 1234762Snate@binkert.orgdef SwigSource(package, source): 1244762Snate@binkert.org '''Add a swig file to build''' 1254762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1264762Snate@binkert.org source = File(source) 1274762Snate@binkert.org val = source,package 1284762Snate@binkert.org swig_sources.append(val) 129955SN/A 1304382Sbinkertn@umich.edu# Children should have access 1314202Sbinkertn@umich.eduExport('Source') 1324382Sbinkertn@umich.eduExport('PySource') 1334382Sbinkertn@umich.eduExport('SimObject') 1344382Sbinkertn@umich.eduExport('SwigSource') 1354382Sbinkertn@umich.edu 1364382Sbinkertn@umich.edu######################################################################## 1374382Sbinkertn@umich.edu# 1385192Ssaidi@eecs.umich.edu# Trace Flags 1395192Ssaidi@eecs.umich.edu# 1405192Ssaidi@eecs.umich.eduall_flags = {} 1415192Ssaidi@eecs.umich.edutrace_flags = [] 1425192Ssaidi@eecs.umich.edudef TraceFlag(name, desc=''): 1435192Ssaidi@eecs.umich.edu if name in all_flags: 1445192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 1455192Ssaidi@eecs.umich.edu flag = (name, (), desc) 1465192Ssaidi@eecs.umich.edu trace_flags.append(flag) 1475192Ssaidi@eecs.umich.edu all_flags[name] = () 1485192Ssaidi@eecs.umich.edu 1495192Ssaidi@eecs.umich.edudef CompoundFlag(name, flags, desc=''): 1505192Ssaidi@eecs.umich.edu if name in all_flags: 1515192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 1525192Ssaidi@eecs.umich.edu 1535192Ssaidi@eecs.umich.edu compound = tuple(flags) 1545192Ssaidi@eecs.umich.edu for flag in compound: 1555192Ssaidi@eecs.umich.edu if flag not in all_flags: 1565192Ssaidi@eecs.umich.edu raise AttributeError, "Trace flag %s not found" % flag 1575192Ssaidi@eecs.umich.edu if all_flags[flag]: 1585192Ssaidi@eecs.umich.edu raise AttributeError, \ 1595192Ssaidi@eecs.umich.edu "Compound flag can't point to another compound flag" 1605192Ssaidi@eecs.umich.edu 1615192Ssaidi@eecs.umich.edu flag = (name, compound, desc) 1625192Ssaidi@eecs.umich.edu trace_flags.append(flag) 1635192Ssaidi@eecs.umich.edu all_flags[name] = compound 1645192Ssaidi@eecs.umich.edu 1655192Ssaidi@eecs.umich.eduExport('TraceFlag') 1665192Ssaidi@eecs.umich.eduExport('CompoundFlag') 1675192Ssaidi@eecs.umich.edu 1685192Ssaidi@eecs.umich.edu######################################################################## 1695192Ssaidi@eecs.umich.edu# 1704382Sbinkertn@umich.edu# Set some compiler variables 1714382Sbinkertn@umich.edu# 1724382Sbinkertn@umich.edu 1732667Sstever@eecs.umich.edu# Include file paths are rooted in this directory. SCons will 1742667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and 1752667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include 1762667Sstever@eecs.umich.edu# files. 1772667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.')) 1782667Sstever@eecs.umich.edu 1792037SN/A# Add a flag defining what THE_ISA should be for all compilation 1802037SN/Aenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) 1812037SN/A 1824382Sbinkertn@umich.edu######################################################################## 1834762Snate@binkert.org# 1845344Sstever@gmail.com# Walk the tree and execute all SConscripts in subdirectories 1854382Sbinkertn@umich.edu# 1865341Sstever@gmail.com 1875341Sstever@gmail.comfor base_dir in base_dir_list: 1885341Sstever@gmail.com here = Dir('.').srcnode().abspath 1895344Sstever@gmail.com for root, dirs, files in os.walk(base_dir, topdown=True): 1905341Sstever@gmail.com if root == here: 1915341Sstever@gmail.com # we don't want to recurse back into this SConscript 1925341Sstever@gmail.com continue 1934762Snate@binkert.org 1945341Sstever@gmail.com if 'SConscript' in files: 1955344Sstever@gmail.com build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 1965341Sstever@gmail.com SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) 1974773Snate@binkert.org 1981858SN/Afor opt in env.ExportOptions: 1991858SN/A env.ConfigFile(opt) 2001085SN/A 2014382Sbinkertn@umich.edu######################################################################## 2024382Sbinkertn@umich.edu# 2034762Snate@binkert.org# Prevent any SimObjects from being added after this point, they 2044762Snate@binkert.org# should all have been added in the SConscripts above 2054762Snate@binkert.org# 2065517Snate@binkert.orgclass DictImporter(object): 2075517Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 2085517Snate@binkert.org map to arbitrary filenames.''' 2095517Snate@binkert.org def __init__(self, modules): 2105517Snate@binkert.org self.modules = modules 2115517Snate@binkert.org self.installed = set() 2125517Snate@binkert.org 2135517Snate@binkert.org def __del__(self): 2145517Snate@binkert.org self.unload() 2155517Snate@binkert.org 2165517Snate@binkert.org def unload(self): 2175517Snate@binkert.org import sys 2185517Snate@binkert.org for module in self.installed: 2195517Snate@binkert.org del sys.modules[module] 2205517Snate@binkert.org self.installed = set() 2215517Snate@binkert.org 2225517Snate@binkert.org def find_module(self, fullname, path): 2235517Snate@binkert.org if fullname == '__scons': 2245517Snate@binkert.org return self 2255517Snate@binkert.org 2265517Snate@binkert.org if fullname == 'm5.objects': 2275517Snate@binkert.org return self 2285517Snate@binkert.org 2295517Snate@binkert.org if fullname.startswith('m5.internal'): 2305517Snate@binkert.org return None 2315517Snate@binkert.org 2325517Snate@binkert.org if fullname in self.modules and exists(self.modules[fullname]): 2335517Snate@binkert.org return self 2345517Snate@binkert.org 2355517Snate@binkert.org return None 2365517Snate@binkert.org 2375517Snate@binkert.org def load_module(self, fullname): 2385517Snate@binkert.org mod = imp.new_module(fullname) 2395517Snate@binkert.org sys.modules[fullname] = mod 2405517Snate@binkert.org self.installed.add(fullname) 2415517Snate@binkert.org 2425517Snate@binkert.org mod.__loader__ = self 2435517Snate@binkert.org if fullname == 'm5.objects': 2445517Snate@binkert.org mod.__path__ = fullname.split('.') 2455517Snate@binkert.org return mod 2465517Snate@binkert.org 2475517Snate@binkert.org if fullname == '__scons': 2485517Snate@binkert.org mod.__dict__['m5_build_env'] = build_env 2495517Snate@binkert.org return mod 2505517Snate@binkert.org 2515517Snate@binkert.org srcfile = self.modules[fullname] 2525517Snate@binkert.org if basename(srcfile) == '__init__.py': 2535517Snate@binkert.org mod.__path__ = fullname.split('.') 2545517Snate@binkert.org mod.__file__ = srcfile 2555517Snate@binkert.org 2565517Snate@binkert.org exec file(srcfile, 'r') in mod.__dict__ 2575517Snate@binkert.org 2585517Snate@binkert.org return mod 2595517Snate@binkert.org 2605517Snate@binkert.orgclass ordered_dict(dict): 2615517Snate@binkert.org def keys(self): 2625517Snate@binkert.org keys = super(ordered_dict, self).keys() 2635517Snate@binkert.org keys.sort() 2645517Snate@binkert.org return keys 2655517Snate@binkert.org 2665517Snate@binkert.org def values(self): 2675517Snate@binkert.org return [ self[key] for key in self.keys() ] 2685517Snate@binkert.org 2695517Snate@binkert.org def items(self): 2705517Snate@binkert.org return [ (key,self[key]) for key in self.keys() ] 2715517Snate@binkert.org 2725517Snate@binkert.org def iterkeys(self): 2735517Snate@binkert.org for key in self.keys(): 2745517Snate@binkert.org yield key 2755517Snate@binkert.org 2765517Snate@binkert.org def itervalues(self): 2775517Snate@binkert.org for value in self.values(): 2785517Snate@binkert.org yield value 2795517Snate@binkert.org 2805517Snate@binkert.org def iteritems(self): 2815517Snate@binkert.org for key,value in self.items(): 2825517Snate@binkert.org yield key, value 2835517Snate@binkert.org 2845517Snate@binkert.orgpy_modules = {} 2855517Snate@binkert.orgfor source in py_sources: 2865517Snate@binkert.org py_modules[source.modpath] = source.srcpath 2875517Snate@binkert.org 2885517Snate@binkert.org# install the python importer so we can grab stuff from the source 2895517Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 2905517Snate@binkert.org# else we won't know about them for the rest of the stuff. 2914762Snate@binkert.orgsim_objects_fixed = True 2925517Snate@binkert.orgimporter = DictImporter(py_modules) 2935517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 2944762Snate@binkert.org 2955517Snate@binkert.orgimport m5 2964762Snate@binkert.org 2975517Snate@binkert.org# import all sim objects so we can populate the all_objects list 2985517Snate@binkert.org# make sure that we're working with a list, then let's sort it 2995517Snate@binkert.orgsim_objects = list(sim_object_modfiles) 3005517Snate@binkert.orgsim_objects.sort() 3015517Snate@binkert.orgfor simobj in sim_objects: 3025517Snate@binkert.org exec('from m5.objects import %s' % simobj) 3035517Snate@binkert.org 3045517Snate@binkert.org# we need to unload all of the currently imported modules so that they 3055517Snate@binkert.org# will be re-imported the next time the sconscript is run 3065517Snate@binkert.orgimporter.unload() 3075517Snate@binkert.orgsys.meta_path.remove(importer) 3085517Snate@binkert.org 3095517Snate@binkert.orgsim_objects = m5.SimObject.allClasses 3105517Snate@binkert.orgall_enums = m5.params.allEnums 3115517Snate@binkert.org 3125517Snate@binkert.orgall_params = {} 3135517Snate@binkert.orgfor name,obj in sim_objects.iteritems(): 3145517Snate@binkert.org for param in obj._params.local.values(): 3155517Snate@binkert.org if not hasattr(param, 'swig_decl'): 3165517Snate@binkert.org continue 3175517Snate@binkert.org pname = param.ptype_str 3185517Snate@binkert.org if pname not in all_params: 3195517Snate@binkert.org all_params[pname] = param 3204762Snate@binkert.org 3214762Snate@binkert.org######################################################################## 3224762Snate@binkert.org# 3234762Snate@binkert.org# calculate extra dependencies 3244762Snate@binkert.org# 3254762Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 3265517Snate@binkert.orgdepends = [ File(py_modules[dep]) for dep in module_depends ] 3274762Snate@binkert.org 3284762Snate@binkert.org######################################################################## 3294762Snate@binkert.org# 3304762Snate@binkert.org# Commands for the basic automatically generated python files 3314382Sbinkertn@umich.edu# 3324382Sbinkertn@umich.edu 3335517Snate@binkert.org# Generate Python file containing a dict specifying the current 3345517Snate@binkert.org# build_env flags. 3355517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 3365517Snate@binkert.org f = file(str(target[0]), 'w') 3375517Snate@binkert.org print >>f, "m5_build_env = ", source[0] 3385517Snate@binkert.org f.close() 3395517Snate@binkert.org 3405517Snate@binkert.org# Generate python file containing info about the M5 source code 3415517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 3425517Snate@binkert.org f = file(str(target[0]), 'w') 3435517Snate@binkert.org for src in source: 3445517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 3455517Snate@binkert.org print >>f, "%s = %s" % (src, repr(data)) 3465517Snate@binkert.org f.close() 3475517Snate@binkert.org 3485517Snate@binkert.org# Generate the __init__.py file for m5.objects 3495517Snate@binkert.orgdef makeObjectsInitFile(target, source, env): 3505517Snate@binkert.org f = file(str(target[0]), 'w') 3515517Snate@binkert.org print >>f, 'from params import *' 3525517Snate@binkert.org print >>f, 'from m5.SimObject import *' 3535517Snate@binkert.org for module in source: 3545517Snate@binkert.org print >>f, 'from %s import *' % module.get_contents() 3555517Snate@binkert.org f.close() 3565517Snate@binkert.org 3574762Snate@binkert.org# Generate a file with all of the compile options in it 3585517Snate@binkert.orgenv.Command('python/m5/defines.py', Value(build_env), makeDefinesPyFile) 3594382Sbinkertn@umich.eduPySource('m5', 'python/m5/defines.py') 3604382Sbinkertn@umich.edu 3614762Snate@binkert.org# Generate a file that wraps the basic top level files 3624382Sbinkertn@umich.eduenv.Command('python/m5/info.py', 3634382Sbinkertn@umich.edu [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 3645517Snate@binkert.org makeInfoPyFile) 3654382Sbinkertn@umich.eduPySource('m5', 'python/m5/info.py') 3664382Sbinkertn@umich.edu 3674762Snate@binkert.org# Generate an __init__.py file for the objects package 3684382Sbinkertn@umich.eduenv.Command('python/m5/objects/__init__.py', 3694762Snate@binkert.org [ Value(o) for o in sort_list(sim_object_modfiles) ], 3705517Snate@binkert.org makeObjectsInitFile) 3714382Sbinkertn@umich.eduPySource('m5.objects', 'python/m5/objects/__init__.py') 3724382Sbinkertn@umich.edu 3734762Snate@binkert.org######################################################################## 3744762Snate@binkert.org# 3754762Snate@binkert.org# Create all of the SimObject param headers and enum headers 3764762Snate@binkert.org# 3774762Snate@binkert.org 3785517Snate@binkert.orgdef createSimObjectParam(target, source, env): 3795517Snate@binkert.org assert len(target) == 1 and len(source) == 1 3805517Snate@binkert.org 3815517Snate@binkert.org hh_file = file(target[0].abspath, 'w') 3825517Snate@binkert.org name = str(source[0].get_contents()) 3835517Snate@binkert.org obj = sim_objects[name] 3845517Snate@binkert.org 3855517Snate@binkert.org print >>hh_file, obj.cxx_decl() 3865517Snate@binkert.org 3875517Snate@binkert.orgdef createSwigParam(target, source, env): 3885517Snate@binkert.org assert len(target) == 1 and len(source) == 1 3895517Snate@binkert.org 3905517Snate@binkert.org i_file = file(target[0].abspath, 'w') 3915517Snate@binkert.org name = str(source[0].get_contents()) 3925517Snate@binkert.org param = all_params[name] 3935517Snate@binkert.org 3945517Snate@binkert.org for line in param.swig_decl(): 3955517Snate@binkert.org print >>i_file, line 3965517Snate@binkert.org 3975517Snate@binkert.orgdef createEnumStrings(target, source, env): 3985517Snate@binkert.org assert len(target) == 1 and len(source) == 1 3995517Snate@binkert.org 4005517Snate@binkert.org cc_file = file(target[0].abspath, 'w') 4015517Snate@binkert.org name = str(source[0].get_contents()) 4025517Snate@binkert.org obj = all_enums[name] 4035517Snate@binkert.org 4045517Snate@binkert.org print >>cc_file, obj.cxx_def() 4055517Snate@binkert.org cc_file.close() 4065517Snate@binkert.org 4075517Snate@binkert.orgdef createEnumParam(target, source, env): 4085517Snate@binkert.org assert len(target) == 1 and len(source) == 1 4095517Snate@binkert.org 4105517Snate@binkert.org hh_file = file(target[0].abspath, 'w') 4115517Snate@binkert.org name = str(source[0].get_contents()) 4125517Snate@binkert.org obj = all_enums[name] 4135517Snate@binkert.org 4145517Snate@binkert.org print >>hh_file, obj.cxx_decl() 4155517Snate@binkert.org 4164762Snate@binkert.org# Generate all of the SimObject param struct header files 4174762Snate@binkert.orgparams_hh_files = [] 4185517Snate@binkert.orgfor name,simobj in sim_objects.iteritems(): 4195517Snate@binkert.org extra_deps = [ File(py_modules[simobj.__module__]) ] 4204762Snate@binkert.org 4214762Snate@binkert.org hh_file = File('params/%s.hh' % name) 4224762Snate@binkert.org params_hh_files.append(hh_file) 4235517Snate@binkert.org env.Command(hh_file, Value(name), createSimObjectParam) 4244762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 4254762Snate@binkert.org 4264762Snate@binkert.org# Generate any parameter header files needed 4275463Snate@binkert.orgparams_i_files = [] 4285517Snate@binkert.orgfor name,param in all_params.iteritems(): 4294762Snate@binkert.org if isinstance(param, m5.params.VectorParamDesc): 4304762Snate@binkert.org ext = 'vptype' 4314762Snate@binkert.org else: 4324762Snate@binkert.org ext = 'ptype' 4334762Snate@binkert.org 4344762Snate@binkert.org i_file = File('params/%s_%s.i' % (name, ext)) 4355463Snate@binkert.org params_i_files.append(i_file) 4365517Snate@binkert.org env.Command(i_file, Value(name), createSwigParam) 4374762Snate@binkert.org env.Depends(i_file, depends) 4384762Snate@binkert.org 4394762Snate@binkert.org# Generate all enum header files 4405517Snate@binkert.orgfor name,enum in all_enums.iteritems(): 4415517Snate@binkert.org extra_deps = [ File(py_modules[enum.__module__]) ] 4424762Snate@binkert.org 4434762Snate@binkert.org cc_file = File('enums/%s.cc' % name) 4445517Snate@binkert.org env.Command(cc_file, Value(name), createEnumStrings) 4454762Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 4464762Snate@binkert.org Source(cc_file) 4474762Snate@binkert.org 4484762Snate@binkert.org hh_file = File('enums/%s.hh' % name) 4495517Snate@binkert.org env.Command(hh_file, Value(name), createEnumParam) 4504762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 4514762Snate@binkert.org 4524762Snate@binkert.org# Build the big monolithic swigged params module (wraps all SimObject 4534762Snate@binkert.org# param structs and enum structs) 4545517Snate@binkert.orgdef buildParams(target, source, env): 4555517Snate@binkert.org names = [ s.get_contents() for s in source ] 4565517Snate@binkert.org objs = [ sim_objects[name] for name in names ] 4575517Snate@binkert.org out = file(target[0].abspath, 'w') 4585517Snate@binkert.org 4595517Snate@binkert.org ordered_objs = [] 4605517Snate@binkert.org obj_seen = set() 4615517Snate@binkert.org def order_obj(obj): 4625517Snate@binkert.org name = str(obj) 4635517Snate@binkert.org if name in obj_seen: 4645517Snate@binkert.org return 4655517Snate@binkert.org 4665517Snate@binkert.org obj_seen.add(name) 4675517Snate@binkert.org if str(obj) != 'SimObject': 4685517Snate@binkert.org order_obj(obj.__bases__[0]) 4695517Snate@binkert.org 4705517Snate@binkert.org ordered_objs.append(obj) 4715517Snate@binkert.org 4725517Snate@binkert.org for obj in objs: 4735517Snate@binkert.org order_obj(obj) 4745517Snate@binkert.org 4755517Snate@binkert.org enums = set() 4765517Snate@binkert.org predecls = [] 4775517Snate@binkert.org pd_seen = set() 4785517Snate@binkert.org 4795517Snate@binkert.org def add_pds(*pds): 4805517Snate@binkert.org for pd in pds: 4815517Snate@binkert.org if pd not in pd_seen: 4825517Snate@binkert.org predecls.append(pd) 4835517Snate@binkert.org pd_seen.add(pd) 4845517Snate@binkert.org 4855517Snate@binkert.org for obj in ordered_objs: 4865517Snate@binkert.org params = obj._params.local.values() 4875517Snate@binkert.org for param in params: 4885517Snate@binkert.org ptype = param.ptype 4895517Snate@binkert.org if issubclass(ptype, m5.params.Enum): 4905517Snate@binkert.org if ptype not in enums: 4915517Snate@binkert.org enums.add(ptype) 4925517Snate@binkert.org pds = param.swig_predecls() 4935517Snate@binkert.org if isinstance(pds, (list, tuple)): 4945517Snate@binkert.org add_pds(*pds) 4955517Snate@binkert.org else: 4965517Snate@binkert.org add_pds(pds) 4975517Snate@binkert.org 4985517Snate@binkert.org print >>out, '%module params' 4995517Snate@binkert.org 5005517Snate@binkert.org print >>out, '%{' 5015517Snate@binkert.org for obj in ordered_objs: 5025517Snate@binkert.org print >>out, '#include "params/%s.hh"' % obj 5035517Snate@binkert.org print >>out, '%}' 5045517Snate@binkert.org 5055517Snate@binkert.org for pd in predecls: 5065517Snate@binkert.org print >>out, pd 5075517Snate@binkert.org 5085517Snate@binkert.org enums = list(enums) 5095517Snate@binkert.org enums.sort() 5105517Snate@binkert.org for enum in enums: 5115517Snate@binkert.org print >>out, '%%include "enums/%s.hh"' % enum.__name__ 5125517Snate@binkert.org print >>out 5135517Snate@binkert.org 5145517Snate@binkert.org for obj in ordered_objs: 5155517Snate@binkert.org if obj.swig_objdecls: 5165517Snate@binkert.org for decl in obj.swig_objdecls: 5175517Snate@binkert.org print >>out, decl 5185517Snate@binkert.org continue 5195517Snate@binkert.org 5205517Snate@binkert.org code = '' 5215517Snate@binkert.org base = obj.get_base() 5225517Snate@binkert.org 5235517Snate@binkert.org code += '// stop swig from creating/wrapping default ctor/dtor\n' 5245517Snate@binkert.org code += '%%nodefault %s;\n' % obj.cxx_class 5255517Snate@binkert.org code += 'class %s ' % obj.cxx_class 5265517Snate@binkert.org if base: 5275517Snate@binkert.org code += ': public %s' % base 5285517Snate@binkert.org code += ' {};\n' 5295517Snate@binkert.org 5305517Snate@binkert.org klass = obj.cxx_class; 5315517Snate@binkert.org if hasattr(obj, 'cxx_namespace'): 5325517Snate@binkert.org new_code = 'namespace %s {\n' % obj.cxx_namespace 5335517Snate@binkert.org new_code += code 5345517Snate@binkert.org new_code += '}\n' 5355517Snate@binkert.org code = new_code 5365517Snate@binkert.org klass = '%s::%s' % (obj.cxx_namespace, klass) 5375517Snate@binkert.org 5385517Snate@binkert.org print >>out, code 5395517Snate@binkert.org 5405517Snate@binkert.org print >>out, '%%include "src/sim/sim_object_params.hh"' % obj 5415517Snate@binkert.org for obj in ordered_objs: 5425517Snate@binkert.org print >>out, '%%include "params/%s.hh"' % obj 5435517Snate@binkert.org 5444762Snate@binkert.orgparams_file = File('params/params.i') 5455517Snate@binkert.orgnames = sort_list(sim_objects.keys()) 5465517Snate@binkert.orgenv.Command(params_file, [ Value(v) for v in names ], buildParams) 5475463Snate@binkert.orgenv.Depends(params_file, params_hh_files + params_i_files + depends) 5484762Snate@binkert.orgSwigSource('m5.objects', params_file) 5494762Snate@binkert.org 5504762Snate@binkert.org# Build all swig modules 5514382Sbinkertn@umich.eduswig_modules = [] 5524762Snate@binkert.orgfor source,package in swig_sources: 5534382Sbinkertn@umich.edu filename = str(source) 5544762Snate@binkert.org assert filename.endswith('.i') 5554382Sbinkertn@umich.edu 5564762Snate@binkert.org base = '.'.join(filename.split('.')[:-1]) 5574762Snate@binkert.org module = basename(base) 5584762Snate@binkert.org cc_file = base + '_wrap.cc' 5594762Snate@binkert.org py_file = base + '.py' 5604382Sbinkertn@umich.edu 5614382Sbinkertn@umich.edu env.Command([cc_file, py_file], source, 5624382Sbinkertn@umich.edu '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 5634382Sbinkertn@umich.edu '-o ${TARGETS[0]} $SOURCES') 5644382Sbinkertn@umich.edu env.Depends(py_file, source) 5654382Sbinkertn@umich.edu env.Depends(cc_file, source) 5664762Snate@binkert.org 5674382Sbinkertn@umich.edu swig_modules.append(Value(module)) 5684382Sbinkertn@umich.edu Source(cc_file) 5694382Sbinkertn@umich.edu PySource(package, py_file) 5704382Sbinkertn@umich.edu 5714762Snate@binkert.org# Generate the main swig init file 5725517Snate@binkert.orgdef makeSwigInit(target, source, env): 5735517Snate@binkert.org f = file(str(target[0]), 'w') 5745517Snate@binkert.org print >>f, 'extern "C" {' 5755517Snate@binkert.org for module in source: 5765517Snate@binkert.org print >>f, ' void init_%s();' % module.get_contents() 5775517Snate@binkert.org print >>f, '}' 5785517Snate@binkert.org print >>f, 'void init_swig() {' 5795517Snate@binkert.org for module in source: 5805517Snate@binkert.org print >>f, ' init_%s();' % module.get_contents() 5815517Snate@binkert.org print >>f, '}' 5825517Snate@binkert.org f.close() 5835517Snate@binkert.org 5845517Snate@binkert.orgenv.Command('swig/init.cc', swig_modules, makeSwigInit) 5854762Snate@binkert.orgSource('swig/init.cc') 5864382Sbinkertn@umich.edu 5875192Ssaidi@eecs.umich.edu# Generate traceflags.py 5885517Snate@binkert.orgdef traceFlagsPy(target, source, env): 5895517Snate@binkert.org assert(len(target) == 1) 5905517Snate@binkert.org 5915517Snate@binkert.org f = file(str(target[0]), 'w') 5925517Snate@binkert.org 5935517Snate@binkert.org allFlags = [] 5945517Snate@binkert.org for s in source: 5955517Snate@binkert.org val = eval(s.get_contents()) 5965517Snate@binkert.org allFlags.append(val) 5975517Snate@binkert.org 5985517Snate@binkert.org print >>f, 'baseFlags = [' 5995517Snate@binkert.org for flag, compound, desc in allFlags: 6005517Snate@binkert.org if not compound: 6015517Snate@binkert.org print >>f, " '%s'," % flag 6025517Snate@binkert.org print >>f, " ]" 6035517Snate@binkert.org print >>f 6045517Snate@binkert.org 6055517Snate@binkert.org print >>f, 'compoundFlags = [' 6065517Snate@binkert.org print >>f, " 'All'," 6075517Snate@binkert.org for flag, compound, desc in allFlags: 6085517Snate@binkert.org if compound: 6095517Snate@binkert.org print >>f, " '%s'," % flag 6105517Snate@binkert.org print >>f, " ]" 6115517Snate@binkert.org print >>f 6125517Snate@binkert.org 6135517Snate@binkert.org print >>f, "allFlags = frozenset(baseFlags + compoundFlags)" 6145517Snate@binkert.org print >>f 6155517Snate@binkert.org 6165517Snate@binkert.org print >>f, 'compoundFlagMap = {' 6175517Snate@binkert.org all = tuple([flag for flag,compound,desc in allFlags if not compound]) 6185517Snate@binkert.org print >>f, " 'All' : %s," % (all, ) 6195517Snate@binkert.org for flag, compound, desc in allFlags: 6205517Snate@binkert.org if compound: 6215517Snate@binkert.org print >>f, " '%s' : %s," % (flag, compound) 6225517Snate@binkert.org print >>f, " }" 6235517Snate@binkert.org print >>f 6245517Snate@binkert.org 6255517Snate@binkert.org print >>f, 'flagDescriptions = {' 6265517Snate@binkert.org print >>f, " 'All' : 'All flags'," 6275517Snate@binkert.org for flag, compound, desc in allFlags: 6285517Snate@binkert.org print >>f, " '%s' : '%s'," % (flag, desc) 6295517Snate@binkert.org print >>f, " }" 6305517Snate@binkert.org 6315517Snate@binkert.org f.close() 6325517Snate@binkert.org 6335517Snate@binkert.orgdef traceFlagsCC(target, source, env): 6345517Snate@binkert.org assert(len(target) == 1) 6355517Snate@binkert.org 6365517Snate@binkert.org f = file(str(target[0]), 'w') 6375517Snate@binkert.org 6385517Snate@binkert.org allFlags = [] 6395517Snate@binkert.org for s in source: 6405517Snate@binkert.org val = eval(s.get_contents()) 6415517Snate@binkert.org allFlags.append(val) 6425517Snate@binkert.org 6435517Snate@binkert.org # file header 6445517Snate@binkert.org print >>f, ''' 6455517Snate@binkert.org/* 6465517Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated 6475517Snate@binkert.org */ 6485517Snate@binkert.org 6495517Snate@binkert.org#include "base/traceflags.hh" 6505517Snate@binkert.org 6515517Snate@binkert.orgusing namespace Trace; 6525517Snate@binkert.org 6535517Snate@binkert.orgconst char *Trace::flagStrings[] = 6545517Snate@binkert.org{''' 6555517Snate@binkert.org 6565517Snate@binkert.org # The string array is used by SimpleEnumParam to map the strings 6575517Snate@binkert.org # provided by the user to enum values. 6585517Snate@binkert.org for flag, compound, desc in allFlags: 6595517Snate@binkert.org if not compound: 6605517Snate@binkert.org print >>f, ' "%s",' % flag 6615517Snate@binkert.org 6625517Snate@binkert.org print >>f, ' "All",' 6635517Snate@binkert.org for flag, compound, desc in allFlags: 6645517Snate@binkert.org if compound: 6655517Snate@binkert.org print >>f, ' "%s",' % flag 6665517Snate@binkert.org 6675517Snate@binkert.org print >>f, '};' 6685517Snate@binkert.org print >>f 6695517Snate@binkert.org print >>f, 'const int Trace::numFlagStrings = %d;' % (len(allFlags) + 1) 6705517Snate@binkert.org print >>f 6715517Snate@binkert.org 6725517Snate@binkert.org # 6735517Snate@binkert.org # Now define the individual compound flag arrays. There is an array 6745517Snate@binkert.org # for each compound flag listing the component base flags. 6755517Snate@binkert.org # 6765517Snate@binkert.org all = tuple([flag for flag,compound,desc in allFlags if not compound]) 6775517Snate@binkert.org print >>f, 'static const Flags AllMap[] = {' 6785517Snate@binkert.org for flag, compound, desc in allFlags: 6795517Snate@binkert.org if not compound: 6805517Snate@binkert.org print >>f, " %s," % flag 6815517Snate@binkert.org print >>f, '};' 6825517Snate@binkert.org print >>f 6835517Snate@binkert.org 6845517Snate@binkert.org for flag, compound, desc in allFlags: 6855517Snate@binkert.org if not compound: 6865517Snate@binkert.org continue 6875517Snate@binkert.org print >>f, 'static const Flags %sMap[] = {' % flag 6885517Snate@binkert.org for flag in compound: 6895517Snate@binkert.org print >>f, " %s," % flag 6905517Snate@binkert.org print >>f, " (Flags)-1" 6915517Snate@binkert.org print >>f, '};' 6925517Snate@binkert.org print >>f 6935517Snate@binkert.org 6945517Snate@binkert.org # 6955517Snate@binkert.org # Finally the compoundFlags[] array maps the compound flags 6965517Snate@binkert.org # to their individual arrays/ 6975517Snate@binkert.org # 6985517Snate@binkert.org print >>f, 'const Flags *Trace::compoundFlags[] =' 6995517Snate@binkert.org print >>f, '{' 7005517Snate@binkert.org print >>f, ' AllMap,' 7015517Snate@binkert.org for flag, compound, desc in allFlags: 7025517Snate@binkert.org if compound: 7035517Snate@binkert.org print >>f, ' %sMap,' % flag 7045517Snate@binkert.org # file trailer 7055517Snate@binkert.org print >>f, '};' 7065517Snate@binkert.org 7075517Snate@binkert.org f.close() 7085517Snate@binkert.org 7095517Snate@binkert.orgdef traceFlagsHH(target, source, env): 7105517Snate@binkert.org assert(len(target) == 1) 7115517Snate@binkert.org 7125517Snate@binkert.org f = file(str(target[0]), 'w') 7135517Snate@binkert.org 7145517Snate@binkert.org allFlags = [] 7155517Snate@binkert.org for s in source: 7165517Snate@binkert.org val = eval(s.get_contents()) 7175517Snate@binkert.org allFlags.append(val) 7185517Snate@binkert.org 7195517Snate@binkert.org # file header boilerplate 7205517Snate@binkert.org print >>f, ''' 7215517Snate@binkert.org/* 7225517Snate@binkert.org * DO NOT EDIT THIS FILE! 7235517Snate@binkert.org * 7245517Snate@binkert.org * Automatically generated from traceflags.py 7255517Snate@binkert.org */ 7265517Snate@binkert.org 7275517Snate@binkert.org#ifndef __BASE_TRACE_FLAGS_HH__ 7285517Snate@binkert.org#define __BASE_TRACE_FLAGS_HH__ 7295517Snate@binkert.org 7305517Snate@binkert.orgnamespace Trace { 7315517Snate@binkert.org 7325517Snate@binkert.orgenum Flags {''' 7335517Snate@binkert.org 7345517Snate@binkert.org # Generate the enum. Base flags come first, then compound flags. 7355517Snate@binkert.org idx = 0 7365517Snate@binkert.org for flag, compound, desc in allFlags: 7375517Snate@binkert.org if not compound: 7385517Snate@binkert.org print >>f, ' %s = %d,' % (flag, idx) 7395517Snate@binkert.org idx += 1 7405517Snate@binkert.org 7415517Snate@binkert.org numBaseFlags = idx 7425517Snate@binkert.org print >>f, ' NumFlags = %d,' % idx 7435517Snate@binkert.org 7445517Snate@binkert.org # put a comment in here to separate base from compound flags 7455517Snate@binkert.org print >>f, ''' 7465517Snate@binkert.org// The remaining enum values are *not* valid indices for Trace::flags. 7475517Snate@binkert.org// They are "compound" flags, which correspond to sets of base 7485517Snate@binkert.org// flags, and are used by changeFlag.''' 7495517Snate@binkert.org 7505517Snate@binkert.org print >>f, ' All = %d,' % idx 7515517Snate@binkert.org idx += 1 7525517Snate@binkert.org for flag, compound, desc in allFlags: 7535517Snate@binkert.org if compound: 7545517Snate@binkert.org print >>f, ' %s = %d,' % (flag, idx) 7555517Snate@binkert.org idx += 1 7565517Snate@binkert.org 7575517Snate@binkert.org numCompoundFlags = idx - numBaseFlags 7585517Snate@binkert.org print >>f, ' NumCompoundFlags = %d' % numCompoundFlags 7595517Snate@binkert.org 7605517Snate@binkert.org # trailer boilerplate 7615517Snate@binkert.org print >>f, '''\ 7625517Snate@binkert.org}; // enum Flags 7635517Snate@binkert.org 7645517Snate@binkert.org// Array of strings for SimpleEnumParam 7655517Snate@binkert.orgextern const char *flagStrings[]; 7665517Snate@binkert.orgextern const int numFlagStrings; 7675517Snate@binkert.org 7685517Snate@binkert.org// Array of arraay pointers: for each compound flag, gives the list of 7695517Snate@binkert.org// base flags to set. Inidividual flag arrays are terminated by -1. 7705517Snate@binkert.orgextern const Flags *compoundFlags[]; 7715517Snate@binkert.org 7725517Snate@binkert.org/* namespace Trace */ } 7735517Snate@binkert.org 7745517Snate@binkert.org#endif // __BASE_TRACE_FLAGS_HH__ 7755517Snate@binkert.org''' 7765517Snate@binkert.org 7775517Snate@binkert.org f.close() 7785517Snate@binkert.org 7795192Ssaidi@eecs.umich.eduflags = [ Value(f) for f in trace_flags ] 7805517Snate@binkert.orgenv.Command('base/traceflags.py', flags, traceFlagsPy) 7815192Ssaidi@eecs.umich.eduPySource('m5', 'base/traceflags.py') 7825192Ssaidi@eecs.umich.edu 7835517Snate@binkert.orgenv.Command('base/traceflags.hh', flags, traceFlagsHH) 7845517Snate@binkert.orgenv.Command('base/traceflags.cc', flags, traceFlagsCC) 7855192Ssaidi@eecs.umich.eduSource('base/traceflags.cc') 7865192Ssaidi@eecs.umich.edu 7875456Ssaidi@eecs.umich.edu# Generate program_info.cc 7885517Snate@binkert.orgdef programInfo(target, source, env): 7895517Snate@binkert.org def gen_file(target, rev, node, date): 7905517Snate@binkert.org pi_stats = file(target, 'w') 7915517Snate@binkert.org print >>pi_stats, 'const char *hgRev = "%s:%s";' % (rev, node) 7925517Snate@binkert.org print >>pi_stats, 'const char *hgDate = "%s";' % date 7935517Snate@binkert.org pi_stats.close() 7945517Snate@binkert.org 7955517Snate@binkert.org target = str(target[0]) 7965517Snate@binkert.org scons_dir = str(source[0].get_contents()) 7975517Snate@binkert.org try: 7985517Snate@binkert.org import mercurial.demandimport, mercurial.hg, mercurial.ui 7995517Snate@binkert.org import mercurial.util, mercurial.node 8005517Snate@binkert.org if not exists(scons_dir) or not isdir(scons_dir) or \ 8015517Snate@binkert.org not exists(joinpath(scons_dir, ".hg")): 8025517Snate@binkert.org raise ValueError 8035517Snate@binkert.org repo = mercurial.hg.repository(mercurial.ui.ui(), scons_dir) 8045517Snate@binkert.org rev = mercurial.node.nullrev + repo.changelog.count() 8055517Snate@binkert.org changenode = repo.changelog.node(rev) 8065517Snate@binkert.org changes = repo.changelog.read(changenode) 8075517Snate@binkert.org date = mercurial.util.datestr(changes[2]) 8085517Snate@binkert.org 8095517Snate@binkert.org gen_file(target, rev, mercurial.node.hex(changenode), date) 8105517Snate@binkert.org 8115517Snate@binkert.org mercurial.demandimport.disable() 8125517Snate@binkert.org except ImportError: 8135517Snate@binkert.org gen_file(target, "Unknown", "Unknown", "Unknown") 8145517Snate@binkert.org 8155517Snate@binkert.org except: 8165517Snate@binkert.org print "in except" 8175517Snate@binkert.org gen_file(target, "Unknown", "Unknown", "Unknown") 8185517Snate@binkert.org mercurial.demandimport.disable() 8195517Snate@binkert.org 8205456Ssaidi@eecs.umich.eduenv.Command('base/program_info.cc', 8215461Snate@binkert.org Value(str(SCons.Node.FS.default_fs.SConstruct_dir)), 8225517Snate@binkert.org programInfo) 8235456Ssaidi@eecs.umich.edu 8244762Snate@binkert.org# Build the zip file 8255517Snate@binkert.orgdef compilePyFile(target, source, env): 8265517Snate@binkert.org '''Action function to compile a .py into a .pyc''' 8275517Snate@binkert.org py_compile.compile(str(source[0]), str(target[0])) 8285517Snate@binkert.org 8295517Snate@binkert.orgdef buildPyZip(target, source, env): 8305517Snate@binkert.org '''Action function to build the zip archive. Uses the 8315517Snate@binkert.org PyZipFile module included in the standard Python library.''' 8325517Snate@binkert.org 8335517Snate@binkert.org py_compiled = {} 8345517Snate@binkert.org for s in py_sources: 8355517Snate@binkert.org compname = str(s.compiled) 8365517Snate@binkert.org assert compname not in py_compiled 8375517Snate@binkert.org py_compiled[compname] = s 8385517Snate@binkert.org 8395517Snate@binkert.org zf = zipfile.ZipFile(str(target[0]), 'w') 8405517Snate@binkert.org for s in source: 8415517Snate@binkert.org zipname = str(s) 8425517Snate@binkert.org arcname = py_compiled[zipname].arcname 8435517Snate@binkert.org zf.write(zipname, arcname) 8445517Snate@binkert.org zf.close() 8455517Snate@binkert.org 8464382Sbinkertn@umich.edupy_compiled = [] 8474382Sbinkertn@umich.edupy_zip_depends = [] 8484382Sbinkertn@umich.edufor source in py_sources: 8495517Snate@binkert.org env.Command(source.compiled, source.source, compilePyFile) 8504762Snate@binkert.org py_compiled.append(source.compiled) 8514382Sbinkertn@umich.edu 8524382Sbinkertn@umich.edu # make the zipfile depend on the archive name so that the archive 8534382Sbinkertn@umich.edu # is rebuilt if the name changes 8544762Snate@binkert.org py_zip_depends.append(Value(source.arcname)) 8554382Sbinkertn@umich.edu 8564382Sbinkertn@umich.edu# Add the zip file target to the environment. 8574762Snate@binkert.orgm5zip = File('m5py.zip') 8585517Snate@binkert.orgenv.Command(m5zip, py_compiled, buildPyZip) 8594762Snate@binkert.orgenv.Depends(m5zip, py_zip_depends) 8604382Sbinkertn@umich.edu 8614382Sbinkertn@umich.edu######################################################################## 8624382Sbinkertn@umich.edu# 8634382Sbinkertn@umich.edu# Define binaries. Each different build type (debug, opt, etc.) gets 8644382Sbinkertn@umich.edu# a slightly different build environment. 8654382Sbinkertn@umich.edu# 8664382Sbinkertn@umich.edu 8674382Sbinkertn@umich.edu# List of constructed environments to pass back to SConstruct 8684382Sbinkertn@umich.eduenvList = [] 8694382Sbinkertn@umich.edu 870955SN/A# This function adds the specified sources to the given build 871955SN/A# environment, and returns a list of all the corresponding SCons 872955SN/A# Object nodes (including an extra one for date.cc). We explicitly 873955SN/A# add the Object nodes so we can set up special dependencies for 8741108SN/A# date.cc. 875955SN/Adef make_objs(sources, env): 876955SN/A objs = [env.Object(s) for s in sources] 8775456Ssaidi@eecs.umich.edu 878955SN/A # make date.cc depend on all other objects so it always gets 879955SN/A # recompiled whenever anything else does 880955SN/A date_obj = env.Object('base/date.cc') 8815456Ssaidi@eecs.umich.edu 8825456Ssaidi@eecs.umich.edu # Make the generation of program_info.cc dependend on all 8835456Ssaidi@eecs.umich.edu # the other cc files and the compiling of program_info.cc 8845456Ssaidi@eecs.umich.edu # dependent on all the objects but program_info.o 8855456Ssaidi@eecs.umich.edu pinfo_obj = env.Object('base/program_info.cc') 8865456Ssaidi@eecs.umich.edu env.Depends('base/program_info.cc', sources) 887955SN/A env.Depends(date_obj, objs) 8885456Ssaidi@eecs.umich.edu env.Depends(pinfo_obj, objs) 8895456Ssaidi@eecs.umich.edu objs.extend([date_obj,pinfo_obj]) 890955SN/A return objs 891955SN/A 8922655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current 8932655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped 8942655Sstever@eecs.umich.edu# binary. Additional keyword arguments are appended to corresponding 8952655Sstever@eecs.umich.edu# build environment vars. 8962655Sstever@eecs.umich.edudef makeEnv(label, objsfx, strip = False, **kwargs): 8972655Sstever@eecs.umich.edu newEnv = env.Copy(OBJSUFFIX=objsfx) 8982655Sstever@eecs.umich.edu newEnv.Label = label 8992655Sstever@eecs.umich.edu newEnv.Append(**kwargs) 9002655Sstever@eecs.umich.edu exe = 'm5.' + label # final executable 9012655Sstever@eecs.umich.edu bin = exe + '.bin' # executable w/o appended Python zip archive 9024762Snate@binkert.org newEnv.Program(bin, make_objs(cc_sources, newEnv)) 9032655Sstever@eecs.umich.edu if strip: 9042655Sstever@eecs.umich.edu stripped_bin = bin + '.stripped' 9054007Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 9064596Sbinkertn@umich.edu cmd = 'cp $SOURCE $TARGET; strip $TARGET' 9074007Ssaidi@eecs.umich.edu else: 9084596Sbinkertn@umich.edu cmd = 'strip $SOURCE -o $TARGET' 9094596Sbinkertn@umich.edu newEnv.Command(stripped_bin, bin, cmd) 9102655Sstever@eecs.umich.edu bin = stripped_bin 9114382Sbinkertn@umich.edu targets = newEnv.Concat(exe, [bin, 'm5py.zip']) 9122655Sstever@eecs.umich.edu newEnv.M5Binary = targets[0] 9132655Sstever@eecs.umich.edu envList.append(newEnv) 9142655Sstever@eecs.umich.edu 915955SN/A# Debug binary 9163918Ssaidi@eecs.umich.educcflags = {} 9173918Ssaidi@eecs.umich.eduif env['GCC']: 9183918Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 9193918Ssaidi@eecs.umich.edu ccflags['debug'] = '-gstabs+' 9203918Ssaidi@eecs.umich.edu else: 9213918Ssaidi@eecs.umich.edu ccflags['debug'] = '-ggdb3' 9223918Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O3' 9233918Ssaidi@eecs.umich.edu ccflags['fast'] = '-O3' 9243918Ssaidi@eecs.umich.edu ccflags['prof'] = '-O3 -g -pg' 9253918Ssaidi@eecs.umich.eduelif env['SUNCC']: 9263918Ssaidi@eecs.umich.edu ccflags['debug'] = '-g0' 9273918Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O' 9283918Ssaidi@eecs.umich.edu ccflags['fast'] = '-fast' 9293918Ssaidi@eecs.umich.edu ccflags['prof'] = '-fast -g -pg' 9303940Ssaidi@eecs.umich.eduelif env['ICC']: 9313940Ssaidi@eecs.umich.edu ccflags['debug'] = '-g -O0' 9323940Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O' 9333942Ssaidi@eecs.umich.edu ccflags['fast'] = '-fast' 9343940Ssaidi@eecs.umich.edu ccflags['prof'] = '-fast -g -pg' 9353515Ssaidi@eecs.umich.eduelse: 9363918Ssaidi@eecs.umich.edu print 'Unknown compiler, please fix compiler options' 9374762Snate@binkert.org Exit(1) 9383515Ssaidi@eecs.umich.edu 9392655Sstever@eecs.umich.edumakeEnv('debug', '.do', 9403918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['debug']), 9413619Sbinkertn@umich.edu CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 942955SN/A 943955SN/A# Optimized binary 9442655Sstever@eecs.umich.edumakeEnv('opt', '.o', 9453918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['opt']), 9463619Sbinkertn@umich.edu CPPDEFINES = ['TRACING_ON=1']) 947955SN/A 948955SN/A# "Fast" binary 9492655Sstever@eecs.umich.edumakeEnv('fast', '.fo', strip = True, 9503918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['fast']), 9513619Sbinkertn@umich.edu CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 952955SN/A 953955SN/A# Profiled binary 9542655Sstever@eecs.umich.edumakeEnv('prof', '.po', 9553918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['prof']), 9563683Sstever@eecs.umich.edu CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 9572655Sstever@eecs.umich.edu LINKFLAGS = '-pg') 9581869SN/A 9591869SN/AReturn('envList') 960