SConscript revision 4249
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Steve Reinhardt
30
31import os
32import sys
33
34from os.path import join as joinpath
35
36# This file defines how to build a particular configuration of M5
37# based on variable settings in the 'env' build environment.
38
39Import('*')
40
41sources = []
42def Source(*args):
43    for arg in args:
44        if isinstance(arg, (list, tuple)):
45            # Recurse to load a list
46            Source(*arg)
47        elif isinstance(arg, str):
48            sources.extend([ File(f) for f in Split(arg) ])
49        else:
50            sources.append(File(arg))
51
52Export('env')
53Export('Source')
54
55# Include file paths are rooted in this directory.  SCons will
56# automatically expand '.' to refer to both the source directory and
57# the corresponding build directory to pick up generated include
58# files.
59env.Append(CPPPATH=Dir('.'))
60
61# Add a flag defining what THE_ISA should be for all compilation
62env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
63
64# Walk the tree and execute all SConscripts
65scripts = []
66srcdir = env['SRCDIR']
67for root, dirs, files in os.walk(srcdir, topdown=True):
68    if root == srcdir:
69        # we don't want to recurse back into this SConscript
70        continue
71    
72    if 'SConscript' in files:
73        # strip off the srcdir part since scons will try to find the
74        # script in the build directory
75        base = root[len(srcdir) + 1:]
76        SConscript(joinpath(base, 'SConscript'))
77
78for opt in env.ExportOptions:
79    env.ConfigFile(opt)
80
81# This function adds the specified sources to the given build
82# environment, and returns a list of all the corresponding SCons
83# Object nodes (including an extra one for date.cc).  We explicitly
84# add the Object nodes so we can set up special dependencies for
85# date.cc.
86def make_objs(sources, env):
87    objs = [env.Object(s) for s in sources]
88    # make date.cc depend on all other objects so it always gets
89    # recompiled whenever anything else does
90    date_obj = env.Object('base/date.cc')
91    env.Depends(date_obj, objs)
92    objs.append(date_obj)
93    return objs
94
95###################################################
96#
97# Define binaries.  Each different build type (debug, opt, etc.) gets
98# a slightly different build environment.
99#
100###################################################
101
102# List of constructed environments to pass back to SConstruct
103envList = []
104
105# Function to create a new build environment as clone of current
106# environment 'env' with modified object suffix and optional stripped
107# binary.  Additional keyword arguments are appended to corresponding
108# build environment vars.
109def makeEnv(label, objsfx, strip = False, **kwargs):
110    newEnv = env.Copy(OBJSUFFIX=objsfx)
111    newEnv.Label = label
112    newEnv.Append(**kwargs)
113    exe = 'm5.' + label  # final executable
114    bin = exe + '.bin'   # executable w/o appended Python zip archive
115    newEnv.Program(bin, make_objs(sources, newEnv))
116    if strip:
117        stripped_bin = bin + '.stripped'
118        if sys.platform == 'sunos5':
119            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
120        else:
121            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
122        bin = stripped_bin
123    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
124    newEnv.M5Binary = targets[0]
125    envList.append(newEnv)
126
127# Debug binary
128ccflags = {}
129if env['GCC']:
130    if sys.platform == 'sunos5':
131        ccflags['debug'] = '-gstabs+'
132    else:
133        ccflags['debug'] = '-ggdb3'
134    ccflags['opt'] = '-g -O3'
135    ccflags['fast'] = '-O3'
136    ccflags['prof'] = '-O3 -g -pg'
137elif env['SUNCC']:
138    ccflags['debug'] = '-g0'
139    ccflags['opt'] = '-g -O'
140    ccflags['fast'] = '-fast'
141    ccflags['prof'] = '-fast -g -pg'
142elif env['ICC']:
143    ccflags['debug'] = '-g -O0'
144    ccflags['opt'] = '-g -O'
145    ccflags['fast'] = '-fast'
146    ccflags['prof'] = '-fast -g -pg'
147else:
148    print 'Unknown compiler, please fix compiler options'
149    Exit(1)    
150
151makeEnv('debug', '.do',
152        CCFLAGS = Split(ccflags['debug']),
153        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
154
155# Optimized binary
156makeEnv('opt', '.o',
157        CCFLAGS = Split(ccflags['opt']),
158        CPPDEFINES = ['TRACING_ON=1'])
159
160# "Fast" binary
161makeEnv('fast', '.fo', strip = True,
162        CCFLAGS = Split(ccflags['fast']),
163        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
164
165# Profiled binary
166makeEnv('prof', '.po',
167        CCFLAGS = Split(ccflags['prof']),
168        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
169        LINKFLAGS = '-pg')
170
171Return('envList')
172