SConscript revision 4202
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
36955SN/A# This file defines how to build a particular configuration of M5
37955SN/A# based on variable settings in the 'env' build environment.
38955SN/A
394202Sbinkertn@umich.eduImport('*')
40955SN/A
414202Sbinkertn@umich.edusources = []
424202Sbinkertn@umich.edudef Source(*args):
434202Sbinkertn@umich.edu    for arg in args:
444202Sbinkertn@umich.edu        if isinstance(arg, (list, tuple)):
454202Sbinkertn@umich.edu            # Recurse to load a list
464202Sbinkertn@umich.edu            Source(*arg)
474202Sbinkertn@umich.edu        elif isinstance(arg, str):
484202Sbinkertn@umich.edu            sources.extend([ File(f) for f in Split(arg) ])
494202Sbinkertn@umich.edu        else:
504202Sbinkertn@umich.edu            sources.append(File(arg))
51955SN/A
524202Sbinkertn@umich.eduExport('env')
534202Sbinkertn@umich.eduExport('Source')
54955SN/A
552667Sstever@eecs.umich.edu# Include file paths are rooted in this directory.  SCons will
562667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and
572667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include
582667Sstever@eecs.umich.edu# files.
592667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.'))
602667Sstever@eecs.umich.edu
612037SN/A# Add a flag defining what THE_ISA should be for all compilation
622037SN/Aenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
632037SN/A
644202Sbinkertn@umich.edu# Walk the tree and execute all SConscripts
654202Sbinkertn@umich.eduscripts = []
664202Sbinkertn@umich.edusrcdir = env['SRCDIR']
674202Sbinkertn@umich.edufor root, dirs, files in os.walk(srcdir, topdown=True):
684202Sbinkertn@umich.edu    if root == srcdir:
694202Sbinkertn@umich.edu        # we don't want to recurse back into this SConscript
704202Sbinkertn@umich.edu        continue
714202Sbinkertn@umich.edu    
724202Sbinkertn@umich.edu    if 'SConscript' in files:
734202Sbinkertn@umich.edu        # strip off the srcdir part since scons will try to find the
744202Sbinkertn@umich.edu        # script in the build directory
754202Sbinkertn@umich.edu        base = root[len(srcdir) + 1:]
764202Sbinkertn@umich.edu        SConscript(joinpath(base, 'SConscript'))
771858SN/A
781858SN/Afor opt in env.ExportOptions:
791858SN/A    env.ConfigFile(opt)
801085SN/A
81955SN/A# This function adds the specified sources to the given build
82955SN/A# environment, and returns a list of all the corresponding SCons
83955SN/A# Object nodes (including an extra one for date.cc).  We explicitly
84955SN/A# add the Object nodes so we can set up special dependencies for
851108SN/A# date.cc.
86955SN/Adef make_objs(sources, env):
87955SN/A    objs = [env.Object(s) for s in sources]
88955SN/A    # make date.cc depend on all other objects so it always gets
89955SN/A    # recompiled whenever anything else does
90955SN/A    date_obj = env.Object('base/date.cc')
91955SN/A    env.Depends(date_obj, objs)
92955SN/A    objs.append(date_obj)
93955SN/A    return objs
94955SN/A
95955SN/A###################################################
96955SN/A#
97955SN/A# Define binaries.  Each different build type (debug, opt, etc.) gets
98955SN/A# a slightly different build environment.
99955SN/A#
100955SN/A###################################################
101955SN/A
1022655Sstever@eecs.umich.edu# List of constructed environments to pass back to SConstruct
1032655Sstever@eecs.umich.eduenvList = []
1042655Sstever@eecs.umich.edu
1052655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current
1062655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped
1072655Sstever@eecs.umich.edu# binary.  Additional keyword arguments are appended to corresponding
1082655Sstever@eecs.umich.edu# build environment vars.
1092655Sstever@eecs.umich.edudef makeEnv(label, objsfx, strip = False, **kwargs):
1102655Sstever@eecs.umich.edu    newEnv = env.Copy(OBJSUFFIX=objsfx)
1112655Sstever@eecs.umich.edu    newEnv.Label = label
1122655Sstever@eecs.umich.edu    newEnv.Append(**kwargs)
1132655Sstever@eecs.umich.edu    exe = 'm5.' + label  # final executable
1142655Sstever@eecs.umich.edu    bin = exe + '.bin'   # executable w/o appended Python zip archive
1152655Sstever@eecs.umich.edu    newEnv.Program(bin, make_objs(sources, newEnv))
1162655Sstever@eecs.umich.edu    if strip:
1172655Sstever@eecs.umich.edu        stripped_bin = bin + '.stripped'
1184007Ssaidi@eecs.umich.edu        if sys.platform == 'sunos5':
1194007Ssaidi@eecs.umich.edu            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
1204007Ssaidi@eecs.umich.edu        else:
1214007Ssaidi@eecs.umich.edu            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
1222655Sstever@eecs.umich.edu        bin = stripped_bin
1232655Sstever@eecs.umich.edu    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
1242655Sstever@eecs.umich.edu    newEnv.M5Binary = targets[0]
1252655Sstever@eecs.umich.edu    envList.append(newEnv)
1262655Sstever@eecs.umich.edu
127955SN/A# Debug binary
1283918Ssaidi@eecs.umich.educcflags = {}
1293918Ssaidi@eecs.umich.eduif env['GCC']:
1303918Ssaidi@eecs.umich.edu    if sys.platform == 'sunos5':
1313918Ssaidi@eecs.umich.edu        ccflags['debug'] = '-gstabs+'
1323918Ssaidi@eecs.umich.edu    else:
1333918Ssaidi@eecs.umich.edu        ccflags['debug'] = '-ggdb3'
1343918Ssaidi@eecs.umich.edu    ccflags['opt'] = '-g -O3'
1353918Ssaidi@eecs.umich.edu    ccflags['fast'] = '-O3'
1363918Ssaidi@eecs.umich.edu    ccflags['prof'] = '-O3 -g -pg'
1373918Ssaidi@eecs.umich.eduelif env['SUNCC']:
1383918Ssaidi@eecs.umich.edu    ccflags['debug'] = '-g0'
1393918Ssaidi@eecs.umich.edu    ccflags['opt'] = '-g -O'
1403918Ssaidi@eecs.umich.edu    ccflags['fast'] = '-fast'
1413918Ssaidi@eecs.umich.edu    ccflags['prof'] = '-fast -g -pg'
1423940Ssaidi@eecs.umich.eduelif env['ICC']:
1433940Ssaidi@eecs.umich.edu    ccflags['debug'] = '-g -O0'
1443940Ssaidi@eecs.umich.edu    ccflags['opt'] = '-g -O'
1453942Ssaidi@eecs.umich.edu    ccflags['fast'] = '-fast'
1463940Ssaidi@eecs.umich.edu    ccflags['prof'] = '-fast -g -pg'
1473515Ssaidi@eecs.umich.eduelse:
1483918Ssaidi@eecs.umich.edu    print 'Unknown compiler, please fix compiler options'
1493918Ssaidi@eecs.umich.edu    Exit(1)    
1503515Ssaidi@eecs.umich.edu
1512655Sstever@eecs.umich.edumakeEnv('debug', '.do',
1523918Ssaidi@eecs.umich.edu        CCFLAGS = Split(ccflags['debug']),
1533619Sbinkertn@umich.edu        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
154955SN/A
155955SN/A# Optimized binary
1562655Sstever@eecs.umich.edumakeEnv('opt', '.o',
1573918Ssaidi@eecs.umich.edu        CCFLAGS = Split(ccflags['opt']),
1583619Sbinkertn@umich.edu        CPPDEFINES = ['TRACING_ON=1'])
159955SN/A
160955SN/A# "Fast" binary
1612655Sstever@eecs.umich.edumakeEnv('fast', '.fo', strip = True,
1623918Ssaidi@eecs.umich.edu        CCFLAGS = Split(ccflags['fast']),
1633619Sbinkertn@umich.edu        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
164955SN/A
165955SN/A# Profiled binary
1662655Sstever@eecs.umich.edumakeEnv('prof', '.po',
1673918Ssaidi@eecs.umich.edu        CCFLAGS = Split(ccflags['prof']),
1683683Sstever@eecs.umich.edu        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1692655Sstever@eecs.umich.edu        LINKFLAGS = '-pg')
1701869SN/A
1711869SN/AReturn('envList')
172