SConscript revision 4249
12155SN/A# -*- mode:python -*- 22155SN/A 32155SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 42155SN/A# All rights reserved. 52155SN/A# 62155SN/A# Redistribution and use in source and binary forms, with or without 72155SN/A# modification, are permitted provided that the following conditions are 82155SN/A# met: redistributions of source code must retain the above copyright 92155SN/A# notice, this list of conditions and the following disclaimer; 102155SN/A# redistributions in binary form must reproduce the above copyright 112155SN/A# notice, this list of conditions and the following disclaimer in the 122155SN/A# documentation and/or other materials provided with the distribution; 132155SN/A# neither the name of the copyright holders nor the names of its 142155SN/A# contributors may be used to endorse or promote products derived from 152155SN/A# this software without specific prior written permission. 162155SN/A# 172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302155SN/A 314202Sbinkertn@umich.eduimport os 322155SN/Aimport sys 332178SN/A 342178SN/Afrom os.path import join as joinpath 352178SN/A 362178SN/A# This file defines how to build a particular configuration of M5 372178SN/A# based on variable settings in the 'env' build environment. 382178SN/A 392178SN/AImport('*') 402178SN/A 412178SN/Asources = [] 422178SN/Adef Source(*args): 432178SN/A for arg in args: 442178SN/A if isinstance(arg, (list, tuple)): 452155SN/A # Recurse to load a list 462178SN/A Source(*arg) 472155SN/A elif isinstance(arg, str): 482155SN/A sources.extend([ File(f) for f in Split(arg) ]) 492178SN/A else: 502155SN/A sources.append(File(arg)) 512155SN/A 522623SN/AExport('env') 533918Ssaidi@eecs.umich.eduExport('Source') 542623SN/A 552623SN/A# Include file paths are rooted in this directory. SCons will 563918Ssaidi@eecs.umich.edu# automatically expand '.' to refer to both the source directory and 572155SN/A# the corresponding build directory to pick up generated include 582155SN/A# files. 592292SN/Aenv.Append(CPPPATH=Dir('.')) 603918Ssaidi@eecs.umich.edu 612292SN/A# Add a flag defining what THE_ISA should be for all compilation 622292SN/Aenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) 632292SN/A 643918Ssaidi@eecs.umich.edu# Walk the tree and execute all SConscripts 652292SN/Ascripts = [] 662292SN/Asrcdir = env['SRCDIR'] 672766Sktlim@umich.edufor root, dirs, files in os.walk(srcdir, topdown=True): 682766Sktlim@umich.edu if root == srcdir: 692766Sktlim@umich.edu # we don't want to recurse back into this SConscript 702921Sktlim@umich.edu continue 712921Sktlim@umich.edu 722766Sktlim@umich.edu if 'SConscript' in files: 732766Sktlim@umich.edu # strip off the srcdir part since scons will try to find the 742766Sktlim@umich.edu # script in the build directory 752178SN/A base = root[len(srcdir) + 1:] 762155SN/A SConscript(joinpath(base, 'SConscript')) 772155SN/A 782155SN/Afor opt in env.ExportOptions: 792155SN/A env.ConfigFile(opt) 802155SN/A 812155SN/A# This function adds the specified sources to the given build 822766Sktlim@umich.edu# environment, and returns a list of all the corresponding SCons 832155SN/A# Object nodes (including an extra one for date.cc). We explicitly 842623SN/A# add the Object nodes so we can set up special dependencies for 852155SN/A# date.cc. 862155SN/Adef make_objs(sources, env): 872155SN/A objs = [env.Object(s) for s in sources] 882155SN/A # make date.cc depend on all other objects so it always gets 892178SN/A # recompiled whenever anything else does 902178SN/A date_obj = env.Object('base/date.cc') 912178SN/A env.Depends(date_obj, objs) 922766Sktlim@umich.edu objs.append(date_obj) 932178SN/A return objs 942178SN/A 952178SN/A################################################### 962178SN/A# 972766Sktlim@umich.edu# Define binaries. Each different build type (debug, opt, etc.) gets 982766Sktlim@umich.edu# a slightly different build environment. 992766Sktlim@umich.edu# 1002788Sktlim@umich.edu################################################### 1012178SN/A 1022733Sktlim@umich.edu# List of constructed environments to pass back to SConstruct 1032733Sktlim@umich.eduenvList = [] 1042817Sksewell@umich.edu 1052733Sktlim@umich.edu# Function to create a new build environment as clone of current 1064202Sbinkertn@umich.edu# environment 'env' with modified object suffix and optional stripped 1074202Sbinkertn@umich.edu# binary. Additional keyword arguments are appended to corresponding 1084202Sbinkertn@umich.edu# build environment vars. 1094202Sbinkertn@umich.edudef makeEnv(label, objsfx, strip = False, **kwargs): 1104202Sbinkertn@umich.edu newEnv = env.Copy(OBJSUFFIX=objsfx) 1114202Sbinkertn@umich.edu newEnv.Label = label 1124202Sbinkertn@umich.edu newEnv.Append(**kwargs) 1134202Sbinkertn@umich.edu exe = 'm5.' + label # final executable 1144202Sbinkertn@umich.edu bin = exe + '.bin' # executable w/o appended Python zip archive 1154202Sbinkertn@umich.edu newEnv.Program(bin, make_objs(sources, newEnv)) 1164202Sbinkertn@umich.edu if strip: 1172155SN/A stripped_bin = bin + '.stripped' 1184202Sbinkertn@umich.edu if sys.platform == 'sunos5': 1194202Sbinkertn@umich.edu newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET') 1204202Sbinkertn@umich.edu else: 1212821Sktlim@umich.edu newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET') 1222766Sktlim@umich.edu bin = stripped_bin 1234202Sbinkertn@umich.edu targets = newEnv.Concat(exe, [bin, 'python/m5py.zip']) 1242733Sktlim@umich.edu newEnv.M5Binary = targets[0] 1252733Sktlim@umich.edu envList.append(newEnv) 1262733Sktlim@umich.edu 1272733Sktlim@umich.edu# Debug binary 1282733Sktlim@umich.educcflags = {} 1292874Sktlim@umich.eduif env['GCC']: 1302874Sktlim@umich.edu if sys.platform == 'sunos5': 1312874Sktlim@umich.edu ccflags['debug'] = '-gstabs+' 1324202Sbinkertn@umich.edu else: 1332733Sktlim@umich.edu ccflags['debug'] = '-ggdb3' 134 ccflags['opt'] = '-g -O3' 135 ccflags['fast'] = '-O3' 136 ccflags['prof'] = '-O3 -g -pg' 137elif env['SUNCC']: 138 ccflags['debug'] = '-g0' 139 ccflags['opt'] = '-g -O' 140 ccflags['fast'] = '-fast' 141 ccflags['prof'] = '-fast -g -pg' 142elif env['ICC']: 143 ccflags['debug'] = '-g -O0' 144 ccflags['opt'] = '-g -O' 145 ccflags['fast'] = '-fast' 146 ccflags['prof'] = '-fast -g -pg' 147else: 148 print 'Unknown compiler, please fix compiler options' 149 Exit(1) 150 151makeEnv('debug', '.do', 152 CCFLAGS = Split(ccflags['debug']), 153 CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 154 155# Optimized binary 156makeEnv('opt', '.o', 157 CCFLAGS = Split(ccflags['opt']), 158 CPPDEFINES = ['TRACING_ON=1']) 159 160# "Fast" binary 161makeEnv('fast', '.fo', strip = True, 162 CCFLAGS = Split(ccflags['fast']), 163 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 164 165# Profiled binary 166makeEnv('prof', '.po', 167 CCFLAGS = Split(ccflags['prof']), 168 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 169 LINKFLAGS = '-pg') 170 171Return('envList') 172