SConscript revision 4381
17860SN/A# -*- mode:python -*- 27860SN/A 37860SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 49988Snilay@cs.wisc.edu# All rights reserved. 58825Snilay@cs.wisc.edu# 69988Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 77935SN/A# modification, are permitted provided that the following conditions are 87935SN/A# met: redistributions of source code must retain the above copyright 97935SN/A# notice, this list of conditions and the following disclaimer; 107860SN/A# redistributions in binary form must reproduce the above copyright 117860SN/A# notice, this list of conditions and the following disclaimer in the 127860SN/A# documentation and/or other materials provided with the distribution; 1310315Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its 148825Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from 159885Sstever@gmail.com# this software without specific prior written permission. 169885Sstever@gmail.com# 179988Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 188825Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 198825Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2010315Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 218825Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2210038SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 239449SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 249449SAli.Saidi@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 258464SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2610798Ssteve.reinhardt@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 278721SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 288825Snilay@cs.wisc.edu# 298825Snilay@cs.wisc.edu# Authors: Steve Reinhardt 307935SN/A 317935SN/Aimport os 327935SN/Aimport sys 337935SN/A 347935SN/Afrom os.path import join as joinpath 357935SN/A 367935SN/Aimport SCons 378893Ssaidi@eecs.umich.edu 387860SN/A# This file defines how to build a particular configuration of M5 399885Sstever@gmail.com# based on variable settings in the 'env' build environment. 409885Sstever@gmail.com 419885Sstever@gmail.comImport('*') 4210315Snilay@cs.wisc.edu 439988Snilay@cs.wisc.edusources = [] 4410315Snilay@cs.wisc.edudef Source(source): 459885Sstever@gmail.com if isinstance(source, SCons.Node.FS.File): 469885Sstever@gmail.com sources.append(source) 477860SN/A else: 487860SN/A sources.append(File(source)) 4910038SAli.Saidi@ARM.com 507860SN/AExport('env') 5110451Snilay@cs.wisc.eduExport('Source') 528210SN/A 5310451Snilay@cs.wisc.edu# Include file paths are rooted in this directory. SCons will 5410451Snilay@cs.wisc.edu# automatically expand '.' to refer to both the source directory and 557860SN/A# the corresponding build directory to pick up generated include 567860SN/A# files. 577860SN/Aenv.Append(CPPPATH=Dir('.')) 589481Snilay@cs.wisc.edu 597860SN/A# Add a flag defining what THE_ISA should be for all compilation 607860SN/Aenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) 619885Sstever@gmail.com 627860SN/A# Walk the tree and execute all SConscripts 637860SN/Ascripts = [] 647860SN/Asrcdir = env['SRCDIR'] 657860SN/Afor root, dirs, files in os.walk(srcdir, topdown=True): 667860SN/A if root == srcdir: 677860SN/A # we don't want to recurse back into this SConscript 687860SN/A continue 6910451Snilay@cs.wisc.edu 7010451Snilay@cs.wisc.edu if 'SConscript' in files: 7110451Snilay@cs.wisc.edu # strip off the srcdir part since scons will try to find the 727860SN/A # script in the build directory 738825Snilay@cs.wisc.edu base = root[len(srcdir) + 1:] 747860SN/A SConscript(joinpath(base, 'SConscript')) 7510038SAli.Saidi@ARM.com 767860SN/Afor opt in env.ExportOptions: 779988Snilay@cs.wisc.edu env.ConfigFile(opt) 7810451Snilay@cs.wisc.edu 7910451Snilay@cs.wisc.edu# This function adds the specified sources to the given build 8010451Snilay@cs.wisc.edu# environment, and returns a list of all the corresponding SCons 817860SN/A# Object nodes (including an extra one for date.cc). We explicitly 8210451Snilay@cs.wisc.edu# add the Object nodes so we can set up special dependencies for 837860SN/A# date.cc. 847860SN/Adef make_objs(sources, env): 857860SN/A objs = [env.Object(s) for s in sources] 867860SN/A # make date.cc depend on all other objects so it always gets 877860SN/A # recompiled whenever anything else does 887860SN/A date_obj = env.Object('base/date.cc') 897860SN/A env.Depends(date_obj, objs) 907860SN/A objs.append(date_obj) 918825Snilay@cs.wisc.edu return objs 929449SAli.Saidi@ARM.com 937860SN/A################################################### 947860SN/A# 9510038SAli.Saidi@ARM.com# Define binaries. Each different build type (debug, opt, etc.) gets 967860SN/A# a slightly different build environment. 977860SN/A# 987860SN/A################################################### 997860SN/A 1007860SN/A# List of constructed environments to pass back to SConstruct 1018825Snilay@cs.wisc.eduenvList = [] 10210451Snilay@cs.wisc.edu 10310451Snilay@cs.wisc.edu# Function to create a new build environment as clone of current 10410451Snilay@cs.wisc.edu# environment 'env' with modified object suffix and optional stripped 10510451Snilay@cs.wisc.edu# binary. Additional keyword arguments are appended to corresponding 10610451Snilay@cs.wisc.edu# build environment vars. 1077860SN/Adef makeEnv(label, objsfx, strip = False, **kwargs): 1087860SN/A newEnv = env.Copy(OBJSUFFIX=objsfx) 1098825Snilay@cs.wisc.edu newEnv.Label = label 1107860SN/A newEnv.Append(**kwargs) 1117860SN/A exe = 'm5.' + label # final executable 1127860SN/A bin = exe + '.bin' # executable w/o appended Python zip archive 11310451Snilay@cs.wisc.edu newEnv.Program(bin, make_objs(sources, newEnv)) 1147860SN/A if strip: 11510451Snilay@cs.wisc.edu stripped_bin = bin + '.stripped' 1169885Sstever@gmail.com if sys.platform == 'sunos5': 1177860SN/A newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET') 1187860SN/A else: 1197860SN/A newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET') 1207860SN/A bin = stripped_bin 1217860SN/A targets = newEnv.Concat(exe, [bin, 'python/m5py.zip']) 1227860SN/A newEnv.M5Binary = targets[0] 1237860SN/A envList.append(newEnv) 1247860SN/A 1257860SN/A# Debug binary 12610242Ssteve.reinhardt@amd.comccflags = {} 1277860SN/Aif env['GCC']: 1288521SN/A if sys.platform == 'sunos5': 1299449SAli.Saidi@ARM.com ccflags['debug'] = '-gstabs+' 1307860SN/A else: 1317860SN/A ccflags['debug'] = '-ggdb3' 1327860SN/A ccflags['opt'] = '-g -O3' 1337860SN/A ccflags['fast'] = '-O3' 1347860SN/A ccflags['prof'] = '-O3 -g -pg' 1357860SN/Aelif env['SUNCC']: 1367860SN/A ccflags['debug'] = '-g0' 1377860SN/A ccflags['opt'] = '-g -O' 1389481Snilay@cs.wisc.edu ccflags['fast'] = '-fast' 13910798Ssteve.reinhardt@amd.com ccflags['prof'] = '-fast -g -pg' 14010451Snilay@cs.wisc.eduelif env['ICC']: 14110451Snilay@cs.wisc.edu ccflags['debug'] = '-g -O0' 1429481Snilay@cs.wisc.edu ccflags['opt'] = '-g -O' 1439481Snilay@cs.wisc.edu ccflags['fast'] = '-fast' 1449481Snilay@cs.wisc.edu ccflags['prof'] = '-fast -g -pg' 1459988Snilay@cs.wisc.eduelse: 1469481Snilay@cs.wisc.edu print 'Unknown compiler, please fix compiler options' 1479481Snilay@cs.wisc.edu Exit(1) 1489481Snilay@cs.wisc.edu 1499481Snilay@cs.wisc.edumakeEnv('debug', '.do', 1509481Snilay@cs.wisc.edu CCFLAGS = Split(ccflags['debug']), 1517860SN/A CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 1527860SN/A 1539885Sstever@gmail.com# Optimized binary 1548893Ssaidi@eecs.umich.edumakeEnv('opt', '.o', 1557860SN/A CCFLAGS = Split(ccflags['opt']), 1569885Sstever@gmail.com CPPDEFINES = ['TRACING_ON=1']) 15710798Ssteve.reinhardt@amd.com 1589988Snilay@cs.wisc.edu# "Fast" binary 1597860SN/AmakeEnv('fast', '.fo', strip = True, 1609348SAli.Saidi@ARM.com CCFLAGS = Split(ccflags['fast']), 1618150SN/A CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 1627860SN/A 16310451Snilay@cs.wisc.edu# Profiled binary 1647860SN/AmakeEnv('prof', '.po', 1658835SAli.Saidi@ARM.com CCFLAGS = Split(ccflags['prof']), 1669348SAli.Saidi@ARM.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 16710036SAli.Saidi@ARM.com LINKFLAGS = '-pg') 16810451Snilay@cs.wisc.edu 1698835SAli.Saidi@ARM.comReturn('envList') 1709885Sstever@gmail.com