compile revision 13540:da30e62884ee
1955SN/A#!/usr/bin/env python2.7 2955SN/A# Copyright (c) 2006 The Regents of The University of Michigan 31762SN/A# All rights reserved. 4955SN/A# 5955SN/A# Redistribution and use in source and binary forms, with or without 6955SN/A# modification, are permitted provided that the following conditions are 7955SN/A# met: redistributions of source code must retain the above copyright 8955SN/A# notice, this list of conditions and the following disclaimer; 9955SN/A# redistributions in binary form must reproduce the above copyright 10955SN/A# notice, this list of conditions and the following disclaimer in the 11955SN/A# documentation and/or other materials provided with the distribution; 12955SN/A# neither the name of the copyright holders nor the names of its 13955SN/A# contributors may be used to endorse or promote products derived from 14955SN/A# this software without specific prior written permission. 15955SN/A# 16955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27955SN/A# 282665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu 30955SN/Aimport os, re, sys 31955SN/Afrom os.path import isdir, isfile, join as joinpath 32955SN/A 33955SN/Ahomedir = os.environ['HOME'] 34955SN/A 352632Sstever@eecs.umich.edudef do_compile(): 362632Sstever@eecs.umich.edu # 372632Sstever@eecs.umich.edu # Find SCons 382632Sstever@eecs.umich.edu # 39955SN/A search_dirs = [ joinpath(homedir, 'local/lib'), '/opt/local/lib', 402632Sstever@eecs.umich.edu '/usr/local/lib', '/usr/lib' ] 412632Sstever@eecs.umich.edu 422761Sstever@eecs.umich.edu if os.environ.has_key("SCONS_LIB_DIR"): 432632Sstever@eecs.umich.edu search_dirs.append(os.environ["SCONS_LIB_DIR"]) 442632Sstever@eecs.umich.edu 452632Sstever@eecs.umich.edu local = re.compile(r'^scons-local-([0-9]*)\.([0-9]*)\.([0-9]*)$') 462761Sstever@eecs.umich.edu standard = re.compile(r'^scons-([0-9]*)\.([0-9]*)\.([0-9]*)$') 472761Sstever@eecs.umich.edu 482761Sstever@eecs.umich.edu scons_dirs = [] 492632Sstever@eecs.umich.edu for dir in search_dirs: 502632Sstever@eecs.umich.edu if not isdir(dir): 512761Sstever@eecs.umich.edu continue 522761Sstever@eecs.umich.edu 532761Sstever@eecs.umich.edu entries = os.listdir(dir) 542761Sstever@eecs.umich.edu for entry in entries: 552761Sstever@eecs.umich.edu if not entry.startswith('scons'): 562632Sstever@eecs.umich.edu continue 572632Sstever@eecs.umich.edu 582632Sstever@eecs.umich.edu version = (0,0,0) 592632Sstever@eecs.umich.edu path = joinpath(dir, entry) 602632Sstever@eecs.umich.edu 612632Sstever@eecs.umich.edu match = local.search(entry) 622632Sstever@eecs.umich.edu if not match: 63955SN/A match = standard.search(entry) 64955SN/A 65955SN/A if match: 66955SN/A version = match.group(1), match.group(2), match.group(3) 67955SN/A 684202Sbinkertn@umich.edu scons_dirs.append((version, path)) 694678Snate@binkert.org 70955SN/A scons_dirs.sort() 712656Sstever@eecs.umich.edu scons_dirs.reverse() 722656Sstever@eecs.umich.edu 732656Sstever@eecs.umich.edu if not scons_dirs: 742656Sstever@eecs.umich.edu print >>sys.stderr, \ 752656Sstever@eecs.umich.edu "could not find scons in the following dirs: %s" % search_dirs 762656Sstever@eecs.umich.edu sys.exit(1) 772656Sstever@eecs.umich.edu 782653Sstever@eecs.umich.edu sys.path = [ scons_dirs[0][1] ] + sys.path 795227Ssaidi@eecs.umich.edu 805227Ssaidi@eecs.umich.edu # invoke SCons 815227Ssaidi@eecs.umich.edu import SCons.Script 825227Ssaidi@eecs.umich.edu SCons.Script.main() 832653Sstever@eecs.umich.edu 842653Sstever@eecs.umich.edu# 852653Sstever@eecs.umich.edu# do argument parsing 862653Sstever@eecs.umich.edu# 872653Sstever@eecs.umich.eduprogname = sys.argv[0] 882653Sstever@eecs.umich.edu 892653Sstever@eecs.umich.eduimport optparse 902653Sstever@eecs.umich.edu 912653Sstever@eecs.umich.eduusage = '''%prog [compile options] <version> [SCons options] 924781Snate@binkert.org 931852SN/A%prog assumes that the user has a directory called ~/m5/<version> where 94955SN/Athe source tree resides, and a directory called ~/build, where %prog 95955SN/Awill create ~/build/<version> if it does not exist and build the resulting 96955SN/Asimulators there. 973717Sstever@eecs.umich.edu 983716Sstever@eecs.umich.eduIf ~/build is set up in such a way that it points to a local disk on 99955SN/Aeach host, compiles will be very efficient. For example: 1001533SN/A~/build -> /z/<username>/.build (Assuming that /z is a local disk and 1013716Sstever@eecs.umich.edunot NFS mounted, whereas your home directory is NFS mounted). 1021533SN/A''' 1034678Snate@binkert.orgversion = '%prog 0.1' 1044678Snate@binkert.orgparser = optparse.OptionParser(usage=usage, version=version, 1054678Snate@binkert.org formatter=optparse.TitledHelpFormatter()) 1064678Snate@binkert.orgparser.disable_interspersed_args() 1074678Snate@binkert.org 1084678Snate@binkert.org# current option group 1094678Snate@binkert.orggroup = None 1104678Snate@binkert.org 1114678Snate@binkert.orgdef set_group(*args, **kwargs): 1124678Snate@binkert.org '''set the current option group''' 1134678Snate@binkert.org global group 1144678Snate@binkert.org if not args and not kwargs: 1154678Snate@binkert.org group = None 1164678Snate@binkert.org else: 1174678Snate@binkert.org group = parser.add_option_group(*args, **kwargs) 1184678Snate@binkert.org 1194678Snate@binkert.orgdef add_option(*args, **kwargs): 1204678Snate@binkert.org if group: 1214678Snate@binkert.org return group.add_option(*args, **kwargs) 1224678Snate@binkert.org else: 1234678Snate@binkert.org return parser.add_option(*args, **kwargs) 1244973Ssaidi@eecs.umich.edu 1254678Snate@binkert.orgdef bool_option(name, default, help): 1264678Snate@binkert.org '''add a boolean option called --name and --no-name. 1274678Snate@binkert.org Display help depending on which is the default''' 1284678Snate@binkert.org 1294678Snate@binkert.org tname = '--%s' % name 1304678Snate@binkert.org fname = '--no-%s' % name 131955SN/A dest = name.replace('-', '_') 132955SN/A if default: 1332632Sstever@eecs.umich.edu thelp = optparse.SUPPRESS_HELP 1342632Sstever@eecs.umich.edu fhelp = help 135955SN/A else: 136955SN/A thelp = help 137955SN/A fhelp = optparse.SUPPRESS_HELP 138955SN/A 1392632Sstever@eecs.umich.edu add_option(tname, action="store_true", default=default, help=thelp) 140955SN/A add_option(fname, action="store_false", dest=dest, help=fhelp) 1412632Sstever@eecs.umich.edu 1422632Sstever@eecs.umich.eduadd_option('-n', '--no-compile', default=False, action='store_true', 1432632Sstever@eecs.umich.edu help="don't actually compile, just echo SCons command line") 1442632Sstever@eecs.umich.eduadd_option('--everything', default=False, action='store_true', 1452632Sstever@eecs.umich.edu help="compile everything that can be compiled") 1462632Sstever@eecs.umich.eduadd_option('-E', "--experimental", action='store_true', default=False, 1472632Sstever@eecs.umich.edu help="enable experimental builds") 1483053Sstever@eecs.umich.eduadd_option('-v', "--verbose", default=False, action='store_true', 1493053Sstever@eecs.umich.edu help="be verbose") 1503053Sstever@eecs.umich.edu 1513053Sstever@eecs.umich.eduset_group("Output binary types") 1523053Sstever@eecs.umich.edubool_option("debug", default=False, help="compile debug binaries") 1533053Sstever@eecs.umich.edubool_option("opt", default=False, help="compile opt binaries") 1543053Sstever@eecs.umich.edubool_option("fast", default=False, help="compile fast binaries") 1553053Sstever@eecs.umich.edubool_option("prof", default=False, help="compile profile binaries") 1563053Sstever@eecs.umich.eduadd_option('-a', "--all-bin", default=False, action='store_true', 1573053Sstever@eecs.umich.edu help="compile debug, opt, and fast binaries") 1583053Sstever@eecs.umich.edu 1593053Sstever@eecs.umich.eduset_group("ISA options") 1603053Sstever@eecs.umich.edubool_option("alpha", default=False, help="compile Alpha") 1613053Sstever@eecs.umich.edubool_option("mips", default=False, help="compile MIPS") 1623053Sstever@eecs.umich.edubool_option("sparc", default=False, help="compile SPARC") 1633053Sstever@eecs.umich.eduadd_option('-i', "--all-isa", default=False, action='store_true', 1642632Sstever@eecs.umich.edu help="compile all ISAs") 1652632Sstever@eecs.umich.edu 1662632Sstever@eecs.umich.eduset_group("Emulation options") 1672632Sstever@eecs.umich.edubool_option("syscall", default=True, 1682632Sstever@eecs.umich.edu help="Do not compile System Call Emulation mode") 1692632Sstever@eecs.umich.edubool_option("fullsys", default=True, 1703718Sstever@eecs.umich.edu help="Do not compile Full System mode") 1713718Sstever@eecs.umich.edu 1723718Sstever@eecs.umich.edudef usage(exitcode=None): 1733718Sstever@eecs.umich.edu parser.print_help() 1743718Sstever@eecs.umich.edu if exitcode is not None: 1753718Sstever@eecs.umich.edu sys.exit(exitcode) 1763718Sstever@eecs.umich.edu 1773718Sstever@eecs.umich.edu(options, args) = parser.parse_args() 1783718Sstever@eecs.umich.edu 1793718Sstever@eecs.umich.eduif options.everything: 1803718Sstever@eecs.umich.edu options.all_bin = True 1813718Sstever@eecs.umich.edu options.prof = True 1823718Sstever@eecs.umich.edu options.all_isa = True 1832634Sstever@eecs.umich.edu 1842634Sstever@eecs.umich.eduif options.all_bin: 1852632Sstever@eecs.umich.edu options.debug = True 1862638Sstever@eecs.umich.edu options.opt = True 1872632Sstever@eecs.umich.edu options.fast = True 1882632Sstever@eecs.umich.edu 1892632Sstever@eecs.umich.edubinaries = [] 1902632Sstever@eecs.umich.eduif options.debug: 1912632Sstever@eecs.umich.edu binaries.append('m5.debug') 1922632Sstever@eecs.umich.eduif options.opt: 1931858SN/A binaries.append('m5.opt') 1943716Sstever@eecs.umich.eduif options.fast: 1952638Sstever@eecs.umich.edu binaries.append('m5.fast') 1962638Sstever@eecs.umich.eduif options.prof: 1972638Sstever@eecs.umich.edu binaries.append('m5.prof') 1982638Sstever@eecs.umich.edu 1992638Sstever@eecs.umich.eduif not binaries: 2002638Sstever@eecs.umich.edu binaries.append('m5.debug') 2012638Sstever@eecs.umich.edu 2023716Sstever@eecs.umich.eduif options.all_isa: 2032634Sstever@eecs.umich.edu options.alpha = True 2042634Sstever@eecs.umich.edu options.mips = True 205955SN/A options.sparc = True 206955SN/A 207955SN/Aisas = [] 208955SN/Aif options.alpha: 209955SN/A isas.append('alpha') 210955SN/Aif options.mips: 211955SN/A isas.append('mips') 212955SN/Aif options.sparc: 2131858SN/A isas.append('sparc') 2141858SN/A 2152632Sstever@eecs.umich.eduif not isas: 216955SN/A isas.append('alpha') 2174781Snate@binkert.org 2183643Ssaidi@eecs.umich.edumodes = [] 2193643Ssaidi@eecs.umich.eduif options.syscall: 2203643Ssaidi@eecs.umich.edu modes.append('syscall') 2213643Ssaidi@eecs.umich.eduif options.fullsys: 2223643Ssaidi@eecs.umich.edu modes.append('fullsys') 2233643Ssaidi@eecs.umich.edu 2243643Ssaidi@eecs.umich.eduif not modes: 2254494Ssaidi@eecs.umich.edu sys.exit("must specify at least one mode") 2264494Ssaidi@eecs.umich.edu 2273716Sstever@eecs.umich.edu# 2281105SN/A# Convert options into SCons command line arguments 2292667Sstever@eecs.umich.edu# 2302667Sstever@eecs.umich.edu 2312667Sstever@eecs.umich.edu# valid combinations of ISA and emulation mode 2322667Sstever@eecs.umich.eduvalid = { ('alpha', 'syscall') : 'ALPHA_SE', 2332667Sstever@eecs.umich.edu ('alpha', 'fullsys') : 'ALPHA_FS', 2342667Sstever@eecs.umich.edu ('mips', 'syscall') : 'MIPS_SE', 2351869SN/A ('sparc', 'syscall') : 'SPARC_SE' } 2361869SN/A 2371869SN/A# experimental combinations of ISA and emulation mode 2381869SN/Aexperiment = { ('mips', 'fullsys') : 'MIPS_FS', 2391869SN/A ('sparc', 'fullsys') : 'SPARC_FS' } 2401065SN/A 2412632Sstever@eecs.umich.eduif options.experimental: 2425199Sstever@gmail.com valid.update(experiment) 2433918Ssaidi@eecs.umich.edu 2443918Ssaidi@eecs.umich.edubuilds = [] 2453940Ssaidi@eecs.umich.edufor isa in isas: 2464781Snate@binkert.org for mode in modes: 2474781Snate@binkert.org try: 2483918Ssaidi@eecs.umich.edu build = valid[(isa, mode)] 2494781Snate@binkert.org builds.append(build) 2504781Snate@binkert.org except KeyError: 2513918Ssaidi@eecs.umich.edu pass 2524781Snate@binkert.org 2534781Snate@binkert.orgif not builds: 2543940Ssaidi@eecs.umich.edu sys.exit("must specify at least one valid combination of ISA and mode") 2553942Ssaidi@eecs.umich.edu 2563940Ssaidi@eecs.umich.eduif not args: 2573918Ssaidi@eecs.umich.edu usage(2) 2583918Ssaidi@eecs.umich.edu 259955SN/Aversion = args[0] 2601858SN/Adel args[0] 2613918Ssaidi@eecs.umich.edu 2623918Ssaidi@eecs.umich.edufor bin in binaries: 2633918Ssaidi@eecs.umich.edu for build in builds: 2643918Ssaidi@eecs.umich.edu args.append('%s/%s' % (build, bin)) 2653940Ssaidi@eecs.umich.edu 2663940Ssaidi@eecs.umich.edu# 2673918Ssaidi@eecs.umich.edu# set up compile 2683918Ssaidi@eecs.umich.edu# 2693918Ssaidi@eecs.umich.edubuild_base = joinpath(homedir, 'build') 2703918Ssaidi@eecs.umich.edum5_base = joinpath(homedir, 'm5') 2713918Ssaidi@eecs.umich.edu 2723918Ssaidi@eecs.umich.eduif not isdir(build_base): 2733918Ssaidi@eecs.umich.edu sys.exit('build directory %s not found' % build_base) 2743918Ssaidi@eecs.umich.edu 2753918Ssaidi@eecs.umich.eduif not isdir(m5_base): 2763940Ssaidi@eecs.umich.edu sys.exit('m5 base directory %s not found' % m5_base) 2773918Ssaidi@eecs.umich.edu 2783918Ssaidi@eecs.umich.edum5_dir = joinpath(m5_base, version) 2791851SN/Aif not isdir(m5_dir): 2801851SN/A sys.exit('source directory %s not found' % m5_dir) 2811858SN/A 2825200Sstever@gmail.com# support M5 1.x 283955SN/Aoldstyle = isfile(joinpath(m5_dir, 'SConscript')) 2843053Sstever@eecs.umich.eduif oldstyle: 2853053Sstever@eecs.umich.edu ext_dir = joinpath(m5_base, 'ext') 2863053Sstever@eecs.umich.edu test_dir = joinpath(m5_base, 'test.' + version) 2873053Sstever@eecs.umich.edu 2883053Sstever@eecs.umich.edu if not isdir(ext_dir): 2893053Sstever@eecs.umich.edu sys.exit('ext directory not found at %s' % ext_dir) 2903053Sstever@eecs.umich.edu 2913053Sstever@eecs.umich.edu if not isdir(test_dir): 2923053Sstever@eecs.umich.edu sys.exit('test directory not found at %s' % test_dir) 2934742Sstever@eecs.umich.edu 2944742Sstever@eecs.umich.edubuild_dir = joinpath(build_base, version) 2953053Sstever@eecs.umich.eduif not isdir(build_dir): 2963053Sstever@eecs.umich.edu os.mkdir(build_dir) 2973053Sstever@eecs.umich.edu # need some symlinks for m5 1.x 2983053Sstever@eecs.umich.edu if oldstyle: 2993053Sstever@eecs.umich.edu os.symlink(m5_dir, joinpath(build_dir, 'm5')) 3003053Sstever@eecs.umich.edu os.symlink(ext_dir, joinpath(build_dir, 'ext')) 3013053Sstever@eecs.umich.edu os.symlink(test_dir, joinpath(build_dir, 'test')) 3023053Sstever@eecs.umich.edu os.symlink(joinpath(m5_dir, 'build', 'SConstruct'), 3033053Sstever@eecs.umich.edu joinpath(build_dir, 'SConstruct')) 3042667Sstever@eecs.umich.edu os.symlink(joinpath(m5_dir, 'build', 'default_options'), 3054554Sbinkertn@umich.edu joinpath(build_dir, 'default_options')) 3064554Sbinkertn@umich.edu 3072667Sstever@eecs.umich.edusys.argv = [ progname ] 3084554Sbinkertn@umich.eduif oldstyle: 3094554Sbinkertn@umich.edu os.chdir(build_dir) 3104554Sbinkertn@umich.edu sys.argv.extend(args) 3114554Sbinkertn@umich.eduelse: 3124554Sbinkertn@umich.edu os.chdir(m5_dir) 3134554Sbinkertn@umich.edu for arg in args: 3144554Sbinkertn@umich.edu if not arg.startswith('-') and '=' not in arg: 3154781Snate@binkert.org arg = joinpath(build_dir, 'build', arg) 3164554Sbinkertn@umich.edu sys.argv.append(arg) 3174554Sbinkertn@umich.edu 3182667Sstever@eecs.umich.eduif options.no_compile or options.verbose: 3194554Sbinkertn@umich.edu for arg in sys.argv[1:]: 3204554Sbinkertn@umich.edu print arg 3214554Sbinkertn@umich.edu 3224554Sbinkertn@umich.eduif not options.no_compile: 3232667Sstever@eecs.umich.edu do_compile() 3244554Sbinkertn@umich.edu