SConscript revision 4381
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# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 30955SN/A 31955SN/Aimport os 32955SN/Aimport sys 334202Sbinkertn@umich.edu 344202Sbinkertn@umich.edufrom os.path import join as joinpath 35955SN/A 364381Sbinkertn@umich.eduimport SCons 374381Sbinkertn@umich.edu 38955SN/A# This file defines how to build a particular configuration of M5 39955SN/A# based on variable settings in the 'env' build environment. 40955SN/A 414202Sbinkertn@umich.eduImport('*') 42955SN/A 434202Sbinkertn@umich.edusources = [] 444381Sbinkertn@umich.edudef Source(source): 454381Sbinkertn@umich.edu if isinstance(source, SCons.Node.FS.File): 464381Sbinkertn@umich.edu sources.append(source) 474381Sbinkertn@umich.edu else: 484381Sbinkertn@umich.edu sources.append(File(source)) 49955SN/A 504202Sbinkertn@umich.eduExport('env') 514202Sbinkertn@umich.eduExport('Source') 52955SN/A 532667Sstever@eecs.umich.edu# Include file paths are rooted in this directory. SCons will 542667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and 552667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include 562667Sstever@eecs.umich.edu# files. 572667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.')) 582667Sstever@eecs.umich.edu 592037SN/A# Add a flag defining what THE_ISA should be for all compilation 602037SN/Aenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) 612037SN/A 624202Sbinkertn@umich.edu# Walk the tree and execute all SConscripts 634202Sbinkertn@umich.eduscripts = [] 644202Sbinkertn@umich.edusrcdir = env['SRCDIR'] 654202Sbinkertn@umich.edufor root, dirs, files in os.walk(srcdir, topdown=True): 664202Sbinkertn@umich.edu if root == srcdir: 674202Sbinkertn@umich.edu # we don't want to recurse back into this SConscript 684202Sbinkertn@umich.edu continue 694202Sbinkertn@umich.edu 704202Sbinkertn@umich.edu if 'SConscript' in files: 714202Sbinkertn@umich.edu # strip off the srcdir part since scons will try to find the 724202Sbinkertn@umich.edu # script in the build directory 734202Sbinkertn@umich.edu base = root[len(srcdir) + 1:] 744202Sbinkertn@umich.edu SConscript(joinpath(base, 'SConscript')) 751858SN/A 761858SN/Afor opt in env.ExportOptions: 771858SN/A env.ConfigFile(opt) 781085SN/A 79955SN/A# This function adds the specified sources to the given build 80955SN/A# environment, and returns a list of all the corresponding SCons 81955SN/A# Object nodes (including an extra one for date.cc). We explicitly 82955SN/A# add the Object nodes so we can set up special dependencies for 831108SN/A# date.cc. 84955SN/Adef make_objs(sources, env): 85955SN/A objs = [env.Object(s) for s in sources] 86955SN/A # make date.cc depend on all other objects so it always gets 87955SN/A # recompiled whenever anything else does 88955SN/A date_obj = env.Object('base/date.cc') 89955SN/A env.Depends(date_obj, objs) 90955SN/A objs.append(date_obj) 91955SN/A return objs 92955SN/A 93955SN/A################################################### 94955SN/A# 95955SN/A# Define binaries. Each different build type (debug, opt, etc.) gets 96955SN/A# a slightly different build environment. 97955SN/A# 98955SN/A################################################### 99955SN/A 1002655Sstever@eecs.umich.edu# List of constructed environments to pass back to SConstruct 1012655Sstever@eecs.umich.eduenvList = [] 1022655Sstever@eecs.umich.edu 1032655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current 1042655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped 1052655Sstever@eecs.umich.edu# binary. Additional keyword arguments are appended to corresponding 1062655Sstever@eecs.umich.edu# build environment vars. 1072655Sstever@eecs.umich.edudef makeEnv(label, objsfx, strip = False, **kwargs): 1082655Sstever@eecs.umich.edu newEnv = env.Copy(OBJSUFFIX=objsfx) 1092655Sstever@eecs.umich.edu newEnv.Label = label 1102655Sstever@eecs.umich.edu newEnv.Append(**kwargs) 1112655Sstever@eecs.umich.edu exe = 'm5.' + label # final executable 1122655Sstever@eecs.umich.edu bin = exe + '.bin' # executable w/o appended Python zip archive 1132655Sstever@eecs.umich.edu newEnv.Program(bin, make_objs(sources, newEnv)) 1142655Sstever@eecs.umich.edu if strip: 1152655Sstever@eecs.umich.edu stripped_bin = bin + '.stripped' 1164007Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 1174007Ssaidi@eecs.umich.edu newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET') 1184007Ssaidi@eecs.umich.edu else: 1194007Ssaidi@eecs.umich.edu newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET') 1202655Sstever@eecs.umich.edu bin = stripped_bin 1212655Sstever@eecs.umich.edu targets = newEnv.Concat(exe, [bin, 'python/m5py.zip']) 1222655Sstever@eecs.umich.edu newEnv.M5Binary = targets[0] 1232655Sstever@eecs.umich.edu envList.append(newEnv) 1242655Sstever@eecs.umich.edu 125955SN/A# Debug binary 1263918Ssaidi@eecs.umich.educcflags = {} 1273918Ssaidi@eecs.umich.eduif env['GCC']: 1283918Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 1293918Ssaidi@eecs.umich.edu ccflags['debug'] = '-gstabs+' 1303918Ssaidi@eecs.umich.edu else: 1313918Ssaidi@eecs.umich.edu ccflags['debug'] = '-ggdb3' 1323918Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O3' 1333918Ssaidi@eecs.umich.edu ccflags['fast'] = '-O3' 1343918Ssaidi@eecs.umich.edu ccflags['prof'] = '-O3 -g -pg' 1353918Ssaidi@eecs.umich.eduelif env['SUNCC']: 1363918Ssaidi@eecs.umich.edu ccflags['debug'] = '-g0' 1373918Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O' 1383918Ssaidi@eecs.umich.edu ccflags['fast'] = '-fast' 1393918Ssaidi@eecs.umich.edu ccflags['prof'] = '-fast -g -pg' 1403940Ssaidi@eecs.umich.eduelif env['ICC']: 1413940Ssaidi@eecs.umich.edu ccflags['debug'] = '-g -O0' 1423940Ssaidi@eecs.umich.edu ccflags['opt'] = '-g -O' 1433942Ssaidi@eecs.umich.edu ccflags['fast'] = '-fast' 1443940Ssaidi@eecs.umich.edu ccflags['prof'] = '-fast -g -pg' 1453515Ssaidi@eecs.umich.eduelse: 1463918Ssaidi@eecs.umich.edu print 'Unknown compiler, please fix compiler options' 1473918Ssaidi@eecs.umich.edu Exit(1) 1483515Ssaidi@eecs.umich.edu 1492655Sstever@eecs.umich.edumakeEnv('debug', '.do', 1503918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['debug']), 1513619Sbinkertn@umich.edu CPPDEFINES = ['DEBUG', 'TRACING_ON=1']) 152955SN/A 153955SN/A# Optimized binary 1542655Sstever@eecs.umich.edumakeEnv('opt', '.o', 1553918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['opt']), 1563619Sbinkertn@umich.edu CPPDEFINES = ['TRACING_ON=1']) 157955SN/A 158955SN/A# "Fast" binary 1592655Sstever@eecs.umich.edumakeEnv('fast', '.fo', strip = True, 1603918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['fast']), 1613619Sbinkertn@umich.edu CPPDEFINES = ['NDEBUG', 'TRACING_ON=0']) 162955SN/A 163955SN/A# Profiled binary 1642655Sstever@eecs.umich.edumakeEnv('prof', '.po', 1653918Ssaidi@eecs.umich.edu CCFLAGS = Split(ccflags['prof']), 1663683Sstever@eecs.umich.edu CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1672655Sstever@eecs.umich.edu LINKFLAGS = '-pg') 1681869SN/A 1691869SN/AReturn('envList') 170