1 #!/usr/bin/env python2.7
2 # Copyright (c) 2006 The Regents of The University of Michigan
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Authors: Nathan Binkert
31 from os
.path
import isdir
, isfile
, join
as joinpath
33 homedir
= os
.environ
['HOME']
39 search_dirs
= [ joinpath(homedir
, 'local/lib'), '/opt/local/lib',
40 '/usr/local/lib', '/usr/lib' ]
42 if os
.environ
.has_key("SCONS_LIB_DIR"):
43 search_dirs
.append(os
.environ
["SCONS_LIB_DIR"])
45 local
= re
.compile(r
'^scons-local-([0-9]*)\.([0-9]*)\.([0-9]*)$')
46 standard
= re
.compile(r
'^scons-([0-9]*)\.([0-9]*)\.([0-9]*)$')
49 for dir in search_dirs
:
53 entries
= os
.listdir(dir)
55 if not entry
.startswith('scons'):
59 path
= joinpath(dir, entry
)
61 match
= local
.search(entry
)
63 match
= standard
.search(entry
)
66 version
= match
.group(1), match
.group(2), match
.group(3)
68 scons_dirs
.append((version
, path
))
75 "could not find scons in the following dirs: %s" % search_dirs
78 sys
.path
= [ scons_dirs
[0][1] ] + sys
.path
87 progname
= sys
.argv
[0]
91 usage
= '''%prog [compile options] <version> [SCons options]
93 %prog assumes that the user has a directory called ~/m5/<version> where
94 the source tree resides, and a directory called ~/build, where %prog
95 will create ~/build/<version> if it does not exist and build the resulting
98 If ~/build is set up in such a way that it points to a local disk on
99 each host, compiles will be very efficient. For example:
100 ~/build -> /z/<username>/.build (Assuming that /z is a local disk and
101 not NFS mounted, whereas your home directory is NFS mounted).
103 version
= '%prog 0.1'
104 parser
= optparse
.OptionParser(usage
=usage
, version
=version
,
105 formatter
=optparse
.TitledHelpFormatter())
106 parser
.disable_interspersed_args()
108 # current option group
111 def set_group(*args
, **kwargs
):
112 '''set the current option group'''
114 if not args
and not kwargs
:
117 group
= parser
.add_option_group(*args
, **kwargs
)
119 def add_option(*args
, **kwargs
):
121 return group
.add_option(*args
, **kwargs
)
123 return parser
.add_option(*args
, **kwargs
)
125 def bool_option(name
, default
, help):
126 '''add a boolean option called --name and --no-name.
127 Display help depending on which is the default'''
129 tname
= '--%s' % name
130 fname
= '--no-%s' % name
131 dest
= name
.replace('-', '_')
133 thelp
= optparse
.SUPPRESS_HELP
137 fhelp
= optparse
.SUPPRESS_HELP
139 add_option(tname
, action
="store_true", default
=default
, help=thelp
)
140 add_option(fname
, action
="store_false", dest
=dest
, help=fhelp
)
142 add_option('-n', '--no-compile', default
=False, action
='store_true',
143 help="don't actually compile, just echo SCons command line")
144 add_option('--everything', default
=False, action
='store_true',
145 help="compile everything that can be compiled")
146 add_option('-E', "--experimental", action
='store_true', default
=False,
147 help="enable experimental builds")
148 add_option('-v', "--verbose", default
=False, action
='store_true',
151 set_group("Output binary types")
152 bool_option("debug", default
=False, help="compile debug binaries")
153 bool_option("opt", default
=False, help="compile opt binaries")
154 bool_option("fast", default
=False, help="compile fast binaries")
155 bool_option("prof", default
=False, help="compile profile binaries")
156 add_option('-a', "--all-bin", default
=False, action
='store_true',
157 help="compile debug, opt, and fast binaries")
159 set_group("ISA options")
160 bool_option("alpha", default
=False, help="compile Alpha")
161 bool_option("mips", default
=False, help="compile MIPS")
162 bool_option("sparc", default
=False, help="compile SPARC")
163 add_option('-i', "--all-isa", default
=False, action
='store_true',
164 help="compile all ISAs")
166 set_group("Emulation options")
167 bool_option("syscall", default
=True,
168 help="Do not compile System Call Emulation mode")
169 bool_option("fullsys", default
=True,
170 help="Do not compile Full System mode")
172 def usage(exitcode
=None):
174 if exitcode
is not None:
177 (options
, args
) = parser
.parse_args()
179 if options
.everything
:
180 options
.all_bin
= True
182 options
.all_isa
= True
191 binaries
.append('m5.debug')
193 binaries
.append('m5.opt')
195 binaries
.append('m5.fast')
197 binaries
.append('m5.prof')
200 binaries
.append('m5.debug')
220 modes
.append('syscall')
222 modes
.append('fullsys')
225 sys
.exit("must specify at least one mode")
228 # Convert options into SCons command line arguments
231 # valid combinations of ISA and emulation mode
232 valid
= { ('alpha', 'syscall') : 'ALPHA_SE',
233 ('alpha', 'fullsys') : 'ALPHA_FS',
234 ('mips', 'syscall') : 'MIPS_SE',
235 ('sparc', 'syscall') : 'SPARC_SE' }
237 # experimental combinations of ISA and emulation mode
238 experiment
= { ('mips', 'fullsys') : 'MIPS_FS',
239 ('sparc', 'fullsys') : 'SPARC_FS' }
241 if options
.experimental
:
242 valid
.update(experiment
)
248 build
= valid
[(isa
, mode
)]
254 sys
.exit("must specify at least one valid combination of ISA and mode")
264 args
.append('%s/%s' % (build
, bin
))
269 build_base
= joinpath(homedir
, 'build')
270 m5_base
= joinpath(homedir
, 'm5')
272 if not isdir(build_base
):
273 sys
.exit('build directory %s not found' % build_base
)
275 if not isdir(m5_base
):
276 sys
.exit('m5 base directory %s not found' % m5_base
)
278 m5_dir
= joinpath(m5_base
, version
)
279 if not isdir(m5_dir
):
280 sys
.exit('source directory %s not found' % m5_dir
)
283 oldstyle
= isfile(joinpath(m5_dir
, 'SConscript'))
285 ext_dir
= joinpath(m5_base
, 'ext')
286 test_dir
= joinpath(m5_base
, 'test.' + version
)
288 if not isdir(ext_dir
):
289 sys
.exit('ext directory not found at %s' % ext_dir
)
291 if not isdir(test_dir
):
292 sys
.exit('test directory not found at %s' % test_dir
)
294 build_dir
= joinpath(build_base
, version
)
295 if not isdir(build_dir
):
297 # need some symlinks for m5 1.x
299 os
.symlink(m5_dir
, joinpath(build_dir
, 'm5'))
300 os
.symlink(ext_dir
, joinpath(build_dir
, 'ext'))
301 os
.symlink(test_dir
, joinpath(build_dir
, 'test'))
302 os
.symlink(joinpath(m5_dir
, 'build', 'SConstruct'),
303 joinpath(build_dir
, 'SConstruct'))
304 os
.symlink(joinpath(m5_dir
, 'build', 'default_options'),
305 joinpath(build_dir
, 'default_options'))
307 sys
.argv
= [ progname
]
310 sys
.argv
.extend(args
)
314 if not arg
.startswith('-') and '=' not in arg
:
315 arg
= joinpath(build_dir
, 'build', arg
)
318 if options
.no_compile
or options
.verbose
:
319 for arg
in sys
.argv
[1:]:
322 if not options
.no_compile
: