3 # Copyright (c) 2004 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 ###################################################
31 # SCons top-level build description (SConstruct) file.
33 # To build M5, you need a directory with three things:
34 # 1. A copy of this file (named SConstruct).
35 # 2. A link named 'm5' to the top of the M5 simulator source tree.
36 # 3. A link named 'ext' to the top of the M5 external source tree.
38 # Then type 'scons' to build the default configuration (see below), or
39 # 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
40 # 'KERNEL/m5.opt' for the optimized full-system version).
42 ###################################################
44 # Python library imports
48 # The absolute path to the current directory (where this file lives).
49 ROOT
= Dir('.').abspath
51 # Paths to the M5 and external source trees (local symlinks).
52 SRCDIR
= os
.path
.join(ROOT
, 'm5')
53 EXT_SRCDIR
= os
.path
.join(ROOT
, 'ext')
55 # Check for 'm5' and 'ext' links, die if they don't exist.
56 if not os
.path
.isdir(SRCDIR
):
57 print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
60 if not os
.path
.isdir('ext'):
61 print "Error: '%s' must be a link to the M5 external source tree." \
66 ###################################################
68 # Define Configurations
70 # The build system infers the build options from the subdirectory name
71 # that the simulator is built under. The subdirectory name must be of
72 # the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
73 # (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL). The
74 # following code defines the standard configurations and options.
75 # Additional local configurations and options are read from the file
76 # 'local_configs' if it exists.
78 # Each base configuration or option is defined in two steps: a
79 # function that takes an SCons build environment and modifies it
80 # appropriately for that config or option, and an entry in the
81 # 'configs_map' or 'options_map' dictionary that maps the directory
82 # name string to the function. (The directory names are all upper
83 # case, by convention.)
85 ###################################################
87 # Base non-full-system Alpha ISA configuration.
89 env
.Replace(TARGET_ISA
= 'alpha')
90 env
.Append(CPPDEFINES
= 'SS_COMPATIBLE_FP')
92 # Base full-system configuration.
93 def KernelConfig(env
):
94 env
.Replace(TARGET_ISA
= 'alpha')
95 env
.Replace(FULL_SYSTEM
= True)
96 env
.Append(CPPDEFINES
= ['FULL_SYSTEM'])
98 # Base configurations map.
100 'ALPHA' : AlphaConfig
,
101 'KERNEL' : KernelConfig
104 # Enable detailed full-system binning.
106 env
.Replace(USE_MYSQL
= True)
107 env
.Append(CPPDEFINES
= 'FS_MEASURE')
109 # Enable MySql database output for stats.
111 env
.Replace(USE_MYSQL
= True)
113 # Disable FastAlloc object allocation.
114 def NoFastAllocOpt(env
):
115 env
.Append(CPPDEFINES
= 'NO_FAST_ALLOC')
119 env
.Append(LIBS
=['efence'])
121 # Configuration options map.
123 'MEASURE' : MeasureOpt
,
125 'NO_FAST_ALLOC' : NoFastAllocOpt
,
129 # The 'local_configs' file can be used to define additional base
130 # configurations and/or options without changing this file.
131 if os
.path
.isfile('local_configs'):
132 SConscript('local_configs', exports
= ['configs_map', 'options_map'])
134 # This function parses a directory name of the form <CONFIG>[.<OPT>]*
135 # and sets up the build environment appropriately. Returns True if
136 # successful, False if the base config or any of the options were not
138 def set_dir_options(dir, env
):
139 parts
= dir.split('.')
143 configs_map
[config
](env
)
144 map(lambda opt
: options_map
[opt
](env
), opts
)
146 except KeyError, key
:
147 print "Config/option '%s' not found." % key
150 # Set the default configuration and binary. The default target (if
151 # scons is invoked at the top level with no command-line targets) is
152 # 'ALPHA/m5.debug'. If scons is invoked in a subdirectory with no
153 # command-line targets, the configuration
155 ###################################################
157 # Figure out which configurations to set up.
160 # It's prohibitive to do all the combinations of base configurations
161 # and options, so we have to infer which ones the user wants.
163 # 1. If there are command-line targets, the configuration(s) are inferred
164 # from the directories of those targets. If scons was invoked from a
165 # subdirectory (using 'scons -u'), those targets have to be
166 # interpreted relative to that subdirectory.
168 # 2. If there are no command-line targets, and scons was invoked from a
169 # subdirectory (using 'scons -u'), the configuration is inferred from
170 # the name of the subdirectory.
172 # 3. If there are no command-line targets and scons was invoked from
173 # the root build directory, a default configuration is used. The
174 # built-in default is ALPHA, but this can be overridden by setting the
175 # M5_DEFAULT_CONFIG shell environment veriable.
177 # In cases 2 & 3, the specific file target defaults to 'm5.debug', but
178 # this can be overridden by setting the M5_DEFAULT_BINARY shell
179 # environment veriable.
181 ###################################################
183 # Find default configuration & binary.
184 default_config
= os
.environ
.get('M5_DEFAULT_CONFIG', 'ALPHA')
185 default_binary
= os
.environ
.get('M5_DEFAULT_BINARY', 'm5.debug')
187 # Ask SCons which directory it was invoked from. If you invoke SCons
188 # from a subdirectory you must use the '-u' flag.
189 launch_dir
= GetLaunchDir()
191 # Build a list 'my_targets' of all the targets relative to ROOT.
192 if launch_dir
== ROOT
:
193 # invoked from root build dir
194 if len(COMMAND_LINE_TARGETS
) != 0:
195 # easy: use specified targets as is
196 my_targets
= COMMAND_LINE_TARGETS
198 # default target (ALPHA/m5.debug, unless overridden)
199 target
= os
.path
.join(default_config
, default_binary
)
200 my_targets
= [target
]
203 # invoked from subdirectory
204 if not launch_dir
.startswith(ROOT
):
205 print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
208 # make launch_dir relative to ROOT (strip ROOT plus slash off front)
209 launch_dir
= launch_dir
[len(ROOT
)+1:]
210 if len(COMMAND_LINE_TARGETS
) != 0:
211 # make specified targets relative to ROOT
212 my_targets
= map(lambda x
: os
.path
.join(launch_dir
, x
),
213 COMMAND_LINE_TARGETS
)
215 # build default binary (m5.debug, unless overridden) using the
216 # config inferred by the invocation directory (the first
217 # subdirectory after ROOT)
218 target
= os
.path
.join(launch_dir
.split('/')[0], default_binary
)
219 my_targets
= [target
]
222 # Normalize target paths (gets rid of '..' in the middle, etc.)
223 my_targets
= map(os
.path
.normpath
, my_targets
)
225 # Generate a list of the unique configs that the collected targets reference.
228 dir = t
.split('/')[0]
229 if dir not in build_dirs
:
230 build_dirs
.append(dir)
232 ###################################################
234 # Set up the default build environment. This environment is copied
235 # and modified according to each selected configuration.
237 ###################################################
239 default_env
= Environment(ENV
= os
.environ
, # inherit user's enviroment vars
242 EXT_SRCDIR
= EXT_SRCDIR
,
247 default_env
.SConsignFile("sconsign")
249 # For some reason, the CC and CXX variables don't get passed into the
250 # environment correctly. This is probably some sort of scons bug that
251 # will eventually be fixed.
252 if os
.environ
.has_key('CC'):
253 default_env
.Replace(CC
=os
.environ
['CC'])
255 if os
.environ
.has_key('CXX'):
256 default_env
.Replace(CXX
=os
.environ
['CXX'])
258 # M5_EXT is used by isa_parser.py to find the PLY package.
259 default_env
.Append(ENV
= { 'M5_EXT' : EXT_SRCDIR
})
261 default_env
.Append(CCFLAGS
='-pipe')
262 default_env
.Append(CCFLAGS
='-fno-strict-aliasing')
263 default_env
.Append(CCFLAGS
=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
264 default_env
.Append(CPPPATH
=[os
.path
.join(EXT_SRCDIR
+ '/dnet')])
266 # libelf build is described in its own SConscript file. Using a
267 # dictionary for exports lets us export "default_env" so the
268 # SConscript will see it as "env". SConscript-global is the build in
269 # build/libelf shared among all configs.
270 default_env
.SConscript('m5/libelf/SConscript-global',
271 exports
={'env' : default_env
})
273 ###################################################
275 # Define build environments for selected configurations.
277 ###################################################
279 for build_dir
in build_dirs
:
280 # Make a copy of the default environment to use for this config.
281 env
= default_env
.Copy()
282 # Modify 'env' according to the build directory config.
283 print "Configuring options for directory '%s'." % build_dir
284 if not set_dir_options(build_dir
, env
):
285 print "Skipping directory '%s'." % build_dir
288 # The m5/SConscript file sets up the build rules in 'env' according
289 # to the configured options.
290 SConscript('m5/SConscript', build_dir
= build_dir
, exports
= 'env',
294 ###################################################
296 # Let SCons do its thing. At this point SCons will use the defined
297 # build enviornments to build the requested targets.
299 ###################################################