3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
29 # Authors: Steve Reinhardt
34 from os.path import join as joinpath
38 # This file defines how to build a particular configuration of M5
39 # based on variable settings in the 'env' build environment.
45 if isinstance(source, SCons.Node.FS.File):
46 sources.append(source)
48 sources.append(File(source))
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
57 env.Append(CPPPATH=Dir('.'))
59 # Add a flag defining what THE_ISA should be for all compilation
60 env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
62 # Walk the tree and execute all SConscripts
64 srcdir = env['SRCDIR']
65 for root, dirs, files in os.walk(srcdir, topdown=True):
67 # we don't want to recurse back into this SConscript
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'))
76 for opt in env.ExportOptions:
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
84 def 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)
93 ###################################################
95 # Define binaries. Each different build type (debug, opt, etc.) gets
96 # a slightly different build environment.
98 ###################################################
100 # List of constructed environments to pass back to SConstruct
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.
107 def makeEnv(label, objsfx, strip = False, **kwargs):
108 newEnv = env.Copy(OBJSUFFIX=objsfx)
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))
115 stripped_bin = bin + '.stripped'
116 if sys.platform == 'sunos5':
117 newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
119 newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
121 targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
122 newEnv.M5Binary = targets[0]
123 envList.append(newEnv)
128 if sys.platform == 'sunos5':
129 ccflags['debug'] = '-gstabs+'
131 ccflags['debug'] = '-ggdb3'
132 ccflags['opt'] = '-g -O3'
133 ccflags['fast'] = '-O3'
134 ccflags['prof'] = '-O3 -g -pg'
136 ccflags['debug'] = '-g0'
137 ccflags['opt'] = '-g -O'
138 ccflags['fast'] = '-fast'
139 ccflags['prof'] = '-fast -g -pg'
141 ccflags['debug'] = '-g -O0'
142 ccflags['opt'] = '-g -O'
143 ccflags['fast'] = '-fast'
144 ccflags['prof'] = '-fast -g -pg'
146 print 'Unknown compiler, please fix compiler options'
149 makeEnv('debug', '.do',
150 CCFLAGS = Split(ccflags['debug']),
151 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
155 CCFLAGS = Split(ccflags['opt']),
156 CPPDEFINES = ['TRACING_ON=1'])
159 makeEnv('fast', '.fo', strip = True,
160 CCFLAGS = Split(ccflags['fast']),
161 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
164 makeEnv('prof', '.po',
165 CCFLAGS = Split(ccflags['prof']),
166 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],