SConscript revision 4218
12929Sktlim@umich.edu# -*- mode:python -*-
22929Sktlim@umich.edu
32932Sktlim@umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan
42929Sktlim@umich.edu# All rights reserved.
52929Sktlim@umich.edu#
62929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without
72929Sktlim@umich.edu# modification, are permitted provided that the following conditions are
82929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright
92929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer;
102929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright
112929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the
122929Sktlim@umich.edu# documentation and/or other materials provided with the distribution;
132929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its
142929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from
152929Sktlim@umich.edu# this software without specific prior written permission.
162929Sktlim@umich.edu#
172929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282932Sktlim@umich.edu#
292932Sktlim@umich.edu# Authors: Steve Reinhardt
302932Sktlim@umich.edu
312929Sktlim@umich.eduimport os
326007Ssteve.reinhardt@amd.comimport sys
337735SAli.Saidi@ARM.com
342929Sktlim@umich.edufrom os.path import join as joinpath
352929Sktlim@umich.edu
362929Sktlim@umich.edu# This file defines how to build a particular configuration of M5
372929Sktlim@umich.edu# based on variable settings in the 'env' build environment.
382929Sktlim@umich.edu
392929Sktlim@umich.eduImport('*')
402929Sktlim@umich.edu
412929Sktlim@umich.edusources = []
422929Sktlim@umich.edudef Source(*args):
432929Sktlim@umich.edu    for arg in args:
442929Sktlim@umich.edu        if isinstance(arg, (list, tuple)):
452929Sktlim@umich.edu            # Recurse to load a list
462929Sktlim@umich.edu            Source(*arg)
476007Ssteve.reinhardt@amd.com        elif isinstance(arg, str):
486007Ssteve.reinhardt@amd.com            sources.extend([ File(f) for f in Split(arg) ])
496007Ssteve.reinhardt@amd.com        else:
506007Ssteve.reinhardt@amd.com            sources.append(File(arg))
516007Ssteve.reinhardt@amd.com
526007Ssteve.reinhardt@amd.comExport('env')
536007Ssteve.reinhardt@amd.comExport('Source')
546007Ssteve.reinhardt@amd.com
556007Ssteve.reinhardt@amd.com# Include file paths are rooted in this directory.  SCons will
566007Ssteve.reinhardt@amd.com# automatically expand '.' to refer to both the source directory and
576007Ssteve.reinhardt@amd.com# the corresponding build directory to pick up generated include
586007Ssteve.reinhardt@amd.com# files.
596007Ssteve.reinhardt@amd.comenv.Append(CPPPATH=Dir('.'))
606007Ssteve.reinhardt@amd.com
616007Ssteve.reinhardt@amd.com# Add a flag defining what THE_ISA should be for all compilation
626007Ssteve.reinhardt@amd.comenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
636007Ssteve.reinhardt@amd.com
646007Ssteve.reinhardt@amd.com# Walk the tree and execute all SConscripts
656007Ssteve.reinhardt@amd.comscripts = []
666007Ssteve.reinhardt@amd.comsrcdir = env['SRCDIR']
676007Ssteve.reinhardt@amd.comfor root, dirs, files in os.walk(srcdir, topdown=True):
686007Ssteve.reinhardt@amd.com    if root == srcdir:
696007Ssteve.reinhardt@amd.com        # we don't want to recurse back into this SConscript
706007Ssteve.reinhardt@amd.com        continue
716007Ssteve.reinhardt@amd.com    
726007Ssteve.reinhardt@amd.com    if 'SConscript' in files:
736007Ssteve.reinhardt@amd.com        # strip off the srcdir part since scons will try to find the
746007Ssteve.reinhardt@amd.com        # script in the build directory
756007Ssteve.reinhardt@amd.com        base = root[len(srcdir) + 1:]
762929Sktlim@umich.edu        SConscript(joinpath(base, 'SConscript'))
772929Sktlim@umich.edu
782929Sktlim@umich.edufor opt in env.ExportOptions:
796007Ssteve.reinhardt@amd.com    env.ConfigFile(opt)
806007Ssteve.reinhardt@amd.com
816007Ssteve.reinhardt@amd.com# This function adds the specified sources to the given build
826007Ssteve.reinhardt@amd.com# environment, and returns a list of all the corresponding SCons
836007Ssteve.reinhardt@amd.com# Object nodes (including an extra one for date.cc).  We explicitly
846007Ssteve.reinhardt@amd.com# add the Object nodes so we can set up special dependencies for
852929Sktlim@umich.edu# date.cc.
862929Sktlim@umich.edudef make_objs(sources, env):
872929Sktlim@umich.edu    objs = [env.Object(s) for s in sources]
882929Sktlim@umich.edu    # make date.cc depend on all other objects so it always gets
892929Sktlim@umich.edu    # recompiled whenever anything else does
906011Ssteve.reinhardt@amd.com    date_obj = env.Object('base/date.cc')
916007Ssteve.reinhardt@amd.com    env.Depends(date_obj, objs)
926007Ssteve.reinhardt@amd.com    objs.append(date_obj)
936007Ssteve.reinhardt@amd.com    return objs
946007Ssteve.reinhardt@amd.com
956007Ssteve.reinhardt@amd.com###################################################
966007Ssteve.reinhardt@amd.com#
976007Ssteve.reinhardt@amd.com# Define binaries.  Each different build type (debug, opt, etc.) gets
986007Ssteve.reinhardt@amd.com# a slightly different build environment.
996007Ssteve.reinhardt@amd.com#
1006007Ssteve.reinhardt@amd.com###################################################
1016007Ssteve.reinhardt@amd.com
1026007Ssteve.reinhardt@amd.com# List of constructed environments to pass back to SConstruct
1036007Ssteve.reinhardt@amd.comenvList = []
1046007Ssteve.reinhardt@amd.com
1057735SAli.Saidi@ARM.com# Function to create a new build environment as clone of current
1066011Ssteve.reinhardt@amd.com# environment 'env' with modified object suffix and optional stripped
1076007Ssteve.reinhardt@amd.com# binary.  Additional keyword arguments are appended to corresponding
1086007Ssteve.reinhardt@amd.com# build environment vars.
1096007Ssteve.reinhardt@amd.comdef makeEnv(label, objsfx, strip = False, **kwargs):
1106007Ssteve.reinhardt@amd.com    newEnv = env.Copy(OBJSUFFIX=objsfx)
1117735SAli.Saidi@ARM.com    newEnv.Label = label
1127735SAli.Saidi@ARM.com    newEnv.Append(**kwargs)
1137735SAli.Saidi@ARM.com    exe = 'm5.' + label  # final executable
1147735SAli.Saidi@ARM.com    bin = exe + '.bin'   # executable w/o appended Python zip archive
1157735SAli.Saidi@ARM.com    newEnv.Program(bin, make_objs(sources, newEnv))
1167735SAli.Saidi@ARM.com    if strip:
1177735SAli.Saidi@ARM.com        stripped_bin = bin + '.stripped'
1187735SAli.Saidi@ARM.com        if sys.platform == 'sunos5':
1197735SAli.Saidi@ARM.com            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
1207735SAli.Saidi@ARM.com        else:
1217735SAli.Saidi@ARM.com            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
1227735SAli.Saidi@ARM.com        bin = stripped_bin
1237735SAli.Saidi@ARM.com    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
1247735SAli.Saidi@ARM.com    newEnv.M5Binary = targets[0]
1256007Ssteve.reinhardt@amd.com    envList.append(newEnv)
1267685Ssteve.reinhardt@amd.com
1276007Ssteve.reinhardt@amd.com# Debug binary
1286011Ssteve.reinhardt@amd.comccflags = {}
1296007Ssteve.reinhardt@amd.comif env['GCC']:
1306007Ssteve.reinhardt@amd.com    if sys.platform == 'sunos5':
1316007Ssteve.reinhardt@amd.com        ccflags['debug'] = '-gstabs+'
1326007Ssteve.reinhardt@amd.com    else:
1336007Ssteve.reinhardt@amd.com        ccflags['debug'] = '-ggdb3'
1346007Ssteve.reinhardt@amd.com    ccflags['opt'] = '-g -O3'
1356011Ssteve.reinhardt@amd.com    ccflags['fast'] = '-O3'
1366007Ssteve.reinhardt@amd.com    ccflags['prof'] = '-O3 -g -pg'
1376007Ssteve.reinhardt@amd.comelif env['SUNCC']:
1386007Ssteve.reinhardt@amd.com    ccflags['debug'] = '-g0'
1396007Ssteve.reinhardt@amd.com    ccflags['opt'] = '-g -O'
1406007Ssteve.reinhardt@amd.com    ccflags['fast'] = '-fast'
1416008Ssteve.reinhardt@amd.com    ccflags['prof'] = '-fast -g -pg'
1426007Ssteve.reinhardt@amd.comelif env['ICC']:
1436008Ssteve.reinhardt@amd.com    ccflags['debug'] = '-g -O0'
1446008Ssteve.reinhardt@amd.com    ccflags['opt'] = '-g -O'
1456008Ssteve.reinhardt@amd.com    ccflags['fast'] = '-fast'
1466008Ssteve.reinhardt@amd.com    ccflags['prof'] = '-fast -g -pg'
1476008Ssteve.reinhardt@amd.comelse:
1486008Ssteve.reinhardt@amd.com    print 'Unknown compiler, please fix compiler options'
1496008Ssteve.reinhardt@amd.com    Exit(1)    
1506007Ssteve.reinhardt@amd.com
1516007Ssteve.reinhardt@amd.commakeEnv('debug', '.do',
1526007Ssteve.reinhardt@amd.com        CCFLAGS = Split(ccflags['debug']),
1536007Ssteve.reinhardt@amd.com        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
1546007Ssteve.reinhardt@amd.com
1552929Sktlim@umich.edu# Optimized binary
1562929Sktlim@umich.edumakeEnv('opt', '.o',
1572929Sktlim@umich.edu        CCFLAGS = Split(ccflags['opt']),
1582929Sktlim@umich.edu        CPPDEFINES = ['TRACING_ON=1'])
1596007Ssteve.reinhardt@amd.com
1606007Ssteve.reinhardt@amd.com# "Fast" binary
1612929Sktlim@umich.edumakeEnv('fast', '.fo', strip = True,
1622929Sktlim@umich.edu        CCFLAGS = Split(ccflags['fast']),
1632929Sktlim@umich.edu        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
1642929Sktlim@umich.edu
1656007Ssteve.reinhardt@amd.com# Profiled binary
1666007Ssteve.reinhardt@amd.commakeEnv('prof', '.po',
1672929Sktlim@umich.edu        CCFLAGS = Split(ccflags['prof']),
1682929Sktlim@umich.edu        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1696007Ssteve.reinhardt@amd.com        LINKFLAGS = '-pg')
1702929Sktlim@umich.edu
1712929Sktlim@umich.eduReturn('envList')
1722929Sktlim@umich.edu