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#
294762Snate@binkert.org# Authors: Steve Reinhardt
30955SN/A
315522Snate@binkert.orgimport os
326143Snate@binkert.orgimport sys
334762Snate@binkert.org
345522Snate@binkert.orgfrom os.path import join as joinpath
35955SN/A
365522Snate@binkert.org# This file defines how to build a particular configuration of M5
37955SN/A# based on variable settings in the 'env' build environment.
385522Snate@binkert.org
394202Sbinkertn@umich.eduImport('*')
405742Snate@binkert.org
41955SN/Asources = []
424381Sbinkertn@umich.edudef Source(*args):
434381Sbinkertn@umich.edu    for arg in args:
448334Snate@binkert.org        if isinstance(arg, (list, tuple)):
45955SN/A            # Recurse to load a list
46955SN/A            Source(*arg)
474202Sbinkertn@umich.edu        elif isinstance(arg, str):
48955SN/A            sources.extend([ File(f) for f in Split(arg) ])
494382Sbinkertn@umich.edu        else:
504382Sbinkertn@umich.edu            sources.append(File(arg))
514382Sbinkertn@umich.edu
526654Snate@binkert.orgExport('env')
535517Snate@binkert.orgExport('Source')
548614Sgblack@eecs.umich.edu
557674Snate@binkert.org# Include file paths are rooted in this directory.  SCons will
566143Snate@binkert.org# automatically expand '.' to refer to both the source directory and
576143Snate@binkert.org# the corresponding build directory to pick up generated include
586143Snate@binkert.org# files.
598233Snate@binkert.orgenv.Append(CPPPATH=Dir('.'))
608233Snate@binkert.org
618233Snate@binkert.org# Add a flag defining what THE_ISA should be for all compilation
628233Snate@binkert.orgenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
638233Snate@binkert.org
648334Snate@binkert.org# Walk the tree and execute all SConscripts
658334Snate@binkert.orgscripts = []
6610453SAndrew.Bardsley@arm.comsrcdir = env['SRCDIR']
6710453SAndrew.Bardsley@arm.comfor root, dirs, files in os.walk(srcdir, topdown=True):
688233Snate@binkert.org    if root == srcdir:
698233Snate@binkert.org        # we don't want to recurse back into this SConscript
708233Snate@binkert.org        continue
718233Snate@binkert.org    
728233Snate@binkert.org    if 'SConscript' in files:
738233Snate@binkert.org        # strip off the srcdir part since scons will try to find the
746143Snate@binkert.org        # script in the build directory
758233Snate@binkert.org        base = root[len(srcdir) + 1:]
768233Snate@binkert.org        SConscript(joinpath(base, 'SConscript'))
778233Snate@binkert.org
786143Snate@binkert.orgfor opt in env.ExportOptions:
796143Snate@binkert.org    env.ConfigFile(opt)
806143Snate@binkert.org
816143Snate@binkert.org# This function adds the specified sources to the given build
828233Snate@binkert.org# environment, and returns a list of all the corresponding SCons
838233Snate@binkert.org# Object nodes (including an extra one for date.cc).  We explicitly
848233Snate@binkert.org# add the Object nodes so we can set up special dependencies for
856143Snate@binkert.org# date.cc.
868233Snate@binkert.orgdef make_objs(sources, env):
878233Snate@binkert.org    objs = [env.Object(s) for s in sources]
888233Snate@binkert.org    # make date.cc depend on all other objects so it always gets
898233Snate@binkert.org    # recompiled whenever anything else does
906143Snate@binkert.org    date_obj = env.Object('base/date.cc')
916143Snate@binkert.org    env.Depends(date_obj, objs)
926143Snate@binkert.org    objs.append(date_obj)
934762Snate@binkert.org    return objs
946143Snate@binkert.org
958233Snate@binkert.org###################################################
968233Snate@binkert.org#
978233Snate@binkert.org# Define binaries.  Each different build type (debug, opt, etc.) gets
988233Snate@binkert.org# a slightly different build environment.
998233Snate@binkert.org#
1006143Snate@binkert.org###################################################
1018233Snate@binkert.org
1028233Snate@binkert.org# List of constructed environments to pass back to SConstruct
1038233Snate@binkert.orgenvList = []
1048233Snate@binkert.org
1056143Snate@binkert.org# Function to create a new build environment as clone of current
1066143Snate@binkert.org# environment 'env' with modified object suffix and optional stripped
1076143Snate@binkert.org# binary.  Additional keyword arguments are appended to corresponding
1086143Snate@binkert.org# build environment vars.
1096143Snate@binkert.orgdef makeEnv(label, objsfx, strip = False, **kwargs):
1106143Snate@binkert.org    newEnv = env.Copy(OBJSUFFIX=objsfx)
1116143Snate@binkert.org    newEnv.Label = label
1126143Snate@binkert.org    newEnv.Append(**kwargs)
1136143Snate@binkert.org    exe = 'm5.' + label  # final executable
1147065Snate@binkert.org    bin = exe + '.bin'   # executable w/o appended Python zip archive
1156143Snate@binkert.org    newEnv.Program(bin, make_objs(sources, newEnv))
1168233Snate@binkert.org    if strip:
1178233Snate@binkert.org        stripped_bin = bin + '.stripped'
1188233Snate@binkert.org        if sys.platform == 'sunos5':
1198233Snate@binkert.org            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
1208233Snate@binkert.org        else:
1218233Snate@binkert.org            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
1228233Snate@binkert.org        bin = stripped_bin
1238233Snate@binkert.org    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
1248233Snate@binkert.org    newEnv.M5Binary = targets[0]
1258233Snate@binkert.org    envList.append(newEnv)
1268233Snate@binkert.org
1278233Snate@binkert.org# Debug binary
1288233Snate@binkert.orgccflags = {}
1298233Snate@binkert.orgif env['GCC']:
1308233Snate@binkert.org    if sys.platform == 'sunos5':
1318233Snate@binkert.org        ccflags['debug'] = '-gstabs+'
1328233Snate@binkert.org    else:
1338233Snate@binkert.org        ccflags['debug'] = '-ggdb3'
1348233Snate@binkert.org    ccflags['opt'] = '-g -O3'
1358233Snate@binkert.org    ccflags['fast'] = '-O3'
1368233Snate@binkert.org    ccflags['prof'] = '-O3 -g -pg'
1378233Snate@binkert.orgelif env['SUNCC']:
1388233Snate@binkert.org    ccflags['debug'] = '-g0'
1398233Snate@binkert.org    ccflags['opt'] = '-g -O'
1408233Snate@binkert.org    ccflags['fast'] = '-fast'
1418233Snate@binkert.org    ccflags['prof'] = '-fast -g -pg'
1428233Snate@binkert.orgelif env['ICC']:
1438233Snate@binkert.org    ccflags['debug'] = '-g -O0'
1448233Snate@binkert.org    ccflags['opt'] = '-g -O'
1458233Snate@binkert.org    ccflags['fast'] = '-fast'
1468233Snate@binkert.org    ccflags['prof'] = '-fast -g -pg'
1476143Snate@binkert.orgelse:
1486143Snate@binkert.org    print 'Unknown compiler, please fix compiler options'
1496143Snate@binkert.org    Exit(1)    
1506143Snate@binkert.org
1516143Snate@binkert.orgmakeEnv('debug', '.do',
1526143Snate@binkert.org        CCFLAGS = Split(ccflags['debug']),
1539982Satgutier@umich.edu        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
15410196SCurtis.Dunham@arm.com
15510196SCurtis.Dunham@arm.com# Optimized binary
15610196SCurtis.Dunham@arm.commakeEnv('opt', '.o',
15710196SCurtis.Dunham@arm.com        CCFLAGS = Split(ccflags['opt']),
15810196SCurtis.Dunham@arm.com        CPPDEFINES = ['TRACING_ON=1'])
15910196SCurtis.Dunham@arm.com
16010196SCurtis.Dunham@arm.com# "Fast" binary
16110196SCurtis.Dunham@arm.commakeEnv('fast', '.fo', strip = True,
1626143Snate@binkert.org        CCFLAGS = Split(ccflags['fast']),
1636143Snate@binkert.org        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
1648945Ssteve.reinhardt@amd.com
1658233Snate@binkert.org# Profiled binary
1668233Snate@binkert.orgmakeEnv('prof', '.po',
1676143Snate@binkert.org        CCFLAGS = Split(ccflags['prof']),
1688945Ssteve.reinhardt@amd.com        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1696143Snate@binkert.org        LINKFLAGS = '-pg')
1706143Snate@binkert.org
1716143Snate@binkert.orgReturn('envList')
1726143Snate@binkert.org