SConscript revision 4381:d1e914d47111
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
36import SCons
37
38# This file defines how to build a particular configuration of M5
39# based on variable settings in the 'env' build environment.
40
41Import('*')
42
43sources = []
44def Source(source):
45    if isinstance(source, SCons.Node.FS.File):
46        sources.append(source)
47    else:
48        sources.append(File(source))
49
50Export('env')
51Export('Source')
52
53# Include file paths are rooted in this directory.  SCons will
54# automatically expand '.' to refer to both the source directory and
55# the corresponding build directory to pick up generated include
56# files.
57env.Append(CPPPATH=Dir('.'))
58
59# Add a flag defining what THE_ISA should be for all compilation
60env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
61
62# Walk the tree and execute all SConscripts
63scripts = []
64srcdir = env['SRCDIR']
65for root, dirs, files in os.walk(srcdir, topdown=True):
66    if root == srcdir:
67        # we don't want to recurse back into this SConscript
68        continue
69    
70    if 'SConscript' in files:
71        # strip off the srcdir part since scons will try to find the
72        # script in the build directory
73        base = root[len(srcdir) + 1:]
74        SConscript(joinpath(base, 'SConscript'))
75
76for opt in env.ExportOptions:
77    env.ConfigFile(opt)
78
79# This function adds the specified sources to the given build
80# environment, and returns a list of all the corresponding SCons
81# Object nodes (including an extra one for date.cc).  We explicitly
82# add the Object nodes so we can set up special dependencies for
83# date.cc.
84def make_objs(sources, env):
85    objs = [env.Object(s) for s in sources]
86    # make date.cc depend on all other objects so it always gets
87    # recompiled whenever anything else does
88    date_obj = env.Object('base/date.cc')
89    env.Depends(date_obj, objs)
90    objs.append(date_obj)
91    return objs
92
93###################################################
94#
95# Define binaries.  Each different build type (debug, opt, etc.) gets
96# a slightly different build environment.
97#
98###################################################
99
100# List of constructed environments to pass back to SConstruct
101envList = []
102
103# Function to create a new build environment as clone of current
104# environment 'env' with modified object suffix and optional stripped
105# binary.  Additional keyword arguments are appended to corresponding
106# build environment vars.
107def makeEnv(label, objsfx, strip = False, **kwargs):
108    newEnv = env.Copy(OBJSUFFIX=objsfx)
109    newEnv.Label = label
110    newEnv.Append(**kwargs)
111    exe = 'm5.' + label  # final executable
112    bin = exe + '.bin'   # executable w/o appended Python zip archive
113    newEnv.Program(bin, make_objs(sources, newEnv))
114    if strip:
115        stripped_bin = bin + '.stripped'
116        if sys.platform == 'sunos5':
117            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
118        else:
119            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
120        bin = stripped_bin
121    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
122    newEnv.M5Binary = targets[0]
123    envList.append(newEnv)
124
125# Debug binary
126ccflags = {}
127if env['GCC']:
128    if sys.platform == 'sunos5':
129        ccflags['debug'] = '-gstabs+'
130    else:
131        ccflags['debug'] = '-ggdb3'
132    ccflags['opt'] = '-g -O3'
133    ccflags['fast'] = '-O3'
134    ccflags['prof'] = '-O3 -g -pg'
135elif env['SUNCC']:
136    ccflags['debug'] = '-g0'
137    ccflags['opt'] = '-g -O'
138    ccflags['fast'] = '-fast'
139    ccflags['prof'] = '-fast -g -pg'
140elif env['ICC']:
141    ccflags['debug'] = '-g -O0'
142    ccflags['opt'] = '-g -O'
143    ccflags['fast'] = '-fast'
144    ccflags['prof'] = '-fast -g -pg'
145else:
146    print 'Unknown compiler, please fix compiler options'
147    Exit(1)    
148
149makeEnv('debug', '.do',
150        CCFLAGS = Split(ccflags['debug']),
151        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
152
153# Optimized binary
154makeEnv('opt', '.o',
155        CCFLAGS = Split(ccflags['opt']),
156        CPPDEFINES = ['TRACING_ON=1'])
157
158# "Fast" binary
159makeEnv('fast', '.fo', strip = True,
160        CCFLAGS = Split(ccflags['fast']),
161        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
162
163# Profiled binary
164makeEnv('prof', '.po',
165        CCFLAGS = Split(ccflags['prof']),
166        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
167        LINKFLAGS = '-pg')
168
169Return('envList')
170