SConstruct revision 1858
1955SN/A# -*- mode:python -*-
2955SN/A
312230Sgiacomo.travaglini@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A
29955SN/A###################################################
30955SN/A#
31955SN/A# SCons top-level build description (SConstruct) file.
32955SN/A#
33955SN/A# To build M5, you need a directory with three things:
34955SN/A# 1. A copy of this file (named SConstruct).
35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
36955SN/A# 3. A link named 'ext' to the top of the M5 external source tree.
37955SN/A#
38955SN/A# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
40955SN/A# 'ALPHA_FS/m5.opt' for the optimized full-system version).
41955SN/A#
422665Ssaidi@eecs.umich.edu###################################################
432665Ssaidi@eecs.umich.edu
445863Snate@binkert.org# Python library imports
45955SN/Aimport sys
46955SN/Aimport os
47955SN/A
48955SN/A# Check for recent-enough Python and SCons versions
49955SN/AEnsurePythonVersion(2,3)
508878Ssteve.reinhardt@amd.comEnsureSConsVersion(0,96)
512632Sstever@eecs.umich.edu
528878Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives).
532632Sstever@eecs.umich.eduROOT = Dir('.').abspath
54955SN/A
558878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees (local symlinks).
562632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
572761Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
582632Sstever@eecs.umich.edu
592632Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist.
602632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
612761Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
622761Sstever@eecs.umich.edu    Exit(1)
632761Sstever@eecs.umich.edu
648878Ssteve.reinhardt@amd.comif not os.path.isdir('ext'):
658878Ssteve.reinhardt@amd.com    print "Error: '%s' must be a link to the M5 external source tree." \
662761Sstever@eecs.umich.edu          % EXT_SRCDIR
672761Sstever@eecs.umich.edu    Exit(1)
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu# tell python where to find m5 python code
702761Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python'))
718878Ssteve.reinhardt@amd.com
728878Ssteve.reinhardt@amd.com###################################################
732632Sstever@eecs.umich.edu#
742632Sstever@eecs.umich.edu# Figure out which configurations to set up.
758878Ssteve.reinhardt@amd.com#
768878Ssteve.reinhardt@amd.com#
772632Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
78955SN/A# and options, so we have to infer which ones the user wants.
79955SN/A#
80955SN/A# 1. If there are command-line targets, the configuration(s) are inferred
8112563Sgabeblack@google.com#    from the directories of those targets.  If scons was invoked from a
8212563Sgabeblack@google.com#    subdirectory (using 'scons -u'), those targets have to be
836654Snate@binkert.org#    interpreted relative to that subdirectory.
8410196SCurtis.Dunham@arm.com#
85955SN/A# 2. If there are no command-line targets, and scons was invoked from a
865396Ssaidi@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
8711401Sandreas.sandberg@arm.com#    the name of the subdirectory.
885863Snate@binkert.org#
895863Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
904202Sbinkertn@umich.edu#    the root build directory, a default configuration is used.  The
915863Snate@binkert.org#    built-in default is ALPHA_SE, but this can be overridden by setting the
925863Snate@binkert.org#    M5_DEFAULT_CONFIG shell environment veriable.
935863Snate@binkert.org#
945863Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
9513541Sandrea.mondelli@ucf.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
96955SN/A# environment veriable.
976654Snate@binkert.org#
985273Sstever@gmail.com###################################################
995871Snate@binkert.org
10013758Sgabeblack@google.com# Find default configuration & binary.
1015273Sstever@gmail.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1026654Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1035396Ssaidi@eecs.umich.edu
1048120Sgblack@eecs.umich.edu# Ask SCons which directory it was invoked from.  If you invoke SCons
1058120Sgblack@eecs.umich.edu# from a subdirectory you must use the '-u' flag.
1068120Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir()
1078120Sgblack@eecs.umich.edu
1088120Sgblack@eecs.umich.edu# Build a list 'my_targets' of all the targets relative to ROOT.
1098120Sgblack@eecs.umich.eduif launch_dir == ROOT:
1108120Sgblack@eecs.umich.edu    # invoked from root build dir
1118120Sgblack@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1128879Ssteve.reinhardt@amd.com        # easy: use specified targets as is
1138879Ssteve.reinhardt@amd.com        my_targets = COMMAND_LINE_TARGETS
1148879Ssteve.reinhardt@amd.com    else:
1158879Ssteve.reinhardt@amd.com        # default target (ALPHA_SE/m5.debug, unless overridden)
1168879Ssteve.reinhardt@amd.com        target = os.path.join(default_config, default_binary)
1178879Ssteve.reinhardt@amd.com        my_targets = [target]
1188879Ssteve.reinhardt@amd.com        Default(target)
1198879Ssteve.reinhardt@amd.comelse:
1208879Ssteve.reinhardt@amd.com    # invoked from subdirectory
1218879Ssteve.reinhardt@amd.com    if not launch_dir.startswith(ROOT):
1228879Ssteve.reinhardt@amd.com        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1238879Ssteve.reinhardt@amd.com              (launch_dir, ROOT)
1248879Ssteve.reinhardt@amd.com        Exit(1)
1258120Sgblack@eecs.umich.edu    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
1268120Sgblack@eecs.umich.edu    launch_dir = launch_dir[len(ROOT)+1:]
1278120Sgblack@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1288120Sgblack@eecs.umich.edu        # make specified targets relative to ROOT
1298120Sgblack@eecs.umich.edu        my_targets = map(lambda x: os.path.join(launch_dir, x),
1308120Sgblack@eecs.umich.edu                         COMMAND_LINE_TARGETS)
1318120Sgblack@eecs.umich.edu    else:
1328120Sgblack@eecs.umich.edu        # build default binary (m5.debug, unless overridden) using the
1338120Sgblack@eecs.umich.edu        # config inferred by the invocation directory (the first
1348120Sgblack@eecs.umich.edu        # subdirectory after ROOT)
1358120Sgblack@eecs.umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
1368120Sgblack@eecs.umich.edu        my_targets = [target]
1378120Sgblack@eecs.umich.edu        Default(target)
1388120Sgblack@eecs.umich.edu
1398879Ssteve.reinhardt@amd.com# Normalize target paths (gets rid of '..' in the middle, etc.)
1408879Ssteve.reinhardt@amd.commy_targets = map(os.path.normpath, my_targets)
1418879Ssteve.reinhardt@amd.com
1428879Ssteve.reinhardt@amd.com# Generate a list of the unique configs that the collected targets reference.
14310458Sandreas.hansson@arm.combuild_dirs = []
14410458Sandreas.hansson@arm.comfor t in my_targets:
14510458Sandreas.hansson@arm.com    dir = t.split('/')[0]
1468879Ssteve.reinhardt@amd.com    if dir not in build_dirs:
1478879Ssteve.reinhardt@amd.com        build_dirs.append(dir)
1488879Ssteve.reinhardt@amd.com
1498879Ssteve.reinhardt@amd.com# Make a first pass to verify that build dirs are valid
15013421Sciro.santilli@arm.comfor build_dir in build_dirs:
15113421Sciro.santilli@arm.com    if not os.path.isdir(build_dir):
1529227Sandreas.hansson@arm.com        print "Error: build directory", build_dir, "does not exist."
1539227Sandreas.hansson@arm.com        Exit(1)
15412063Sgabeblack@google.com
15512063Sgabeblack@google.com###################################################
15612063Sgabeblack@google.com#
1578879Ssteve.reinhardt@amd.com# Set up the default build environment.  This environment is copied
1588879Ssteve.reinhardt@amd.com# and modified according to each selected configuration.
1598879Ssteve.reinhardt@amd.com#
1608879Ssteve.reinhardt@amd.com###################################################
16110453SAndrew.Bardsley@arm.com
16210453SAndrew.Bardsley@arm.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
16310453SAndrew.Bardsley@arm.com                  ROOT = ROOT,
16410456SCurtis.Dunham@arm.com                  SRCDIR = SRCDIR,
16510456SCurtis.Dunham@arm.com                  EXT_SRCDIR = EXT_SRCDIR)
16610456SCurtis.Dunham@arm.com
16710457Sandreas.hansson@arm.comenv.SConsignFile("sconsign")
16810457Sandreas.hansson@arm.com
16911342Sandreas.hansson@arm.comif os.environ.has_key('CC'):
17011342Sandreas.hansson@arm.com    env.Replace(CC=os.environ['CC'])
1718120Sgblack@eecs.umich.edu
17212063Sgabeblack@google.comif os.environ.has_key('CXX'):
17312563Sgabeblack@google.com    env.Replace(CXX=os.environ['CXX'])
17412063Sgabeblack@google.com
17512063Sgabeblack@google.com# M5_EXT is used by isa_parser.py to find the PLY package.
1765871Snate@binkert.orgenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
1775871Snate@binkert.org
1786121Snate@binkert.org# Set up default C++ compiler flags
1795871Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1805871Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing')
1819926Sstan.czerniawski@arm.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
18212243Sgabeblack@google.comif sys.platform == 'cygwin':
1831533SN/A    # cygwin has some header file issues...
18412246Sgabeblack@google.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
18512246Sgabeblack@google.comenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
18612246Sgabeblack@google.com
18712246Sgabeblack@google.com# Default libraries
1889239Sandreas.hansson@arm.comenv.Append(LIBS=['z'])
1899239Sandreas.hansson@arm.com
1909239Sandreas.hansson@arm.com# Platform-specific configuration
1919239Sandreas.hansson@arm.comconf = Configure(env)
19212563Sgabeblack@google.com
1939239Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control)
1949239Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
195955SN/Aif not have_fenv:
196955SN/A    print "Warning: Header file <fenv.h> not found."
1972632Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
1982632Sstever@eecs.umich.edu
199955SN/A# Check for mysql
200955SN/Amysql_config = WhereIs('mysql_config')
201955SN/Ahave_mysql = mysql_config != None
202955SN/A
2038878Ssteve.reinhardt@amd.comenv = conf.Finish()
204955SN/A
2052632Sstever@eecs.umich.edu# The source operand is a Value node containing the value of the option.
2062632Sstever@eecs.umich.edudef build_config_file(target, source, env, option):
2072632Sstever@eecs.umich.edu    f = file(str(target[0]), 'w')
2082632Sstever@eecs.umich.edu    print >> f, '#define', option, source[0]
2092632Sstever@eecs.umich.edu    f.close()
2102632Sstever@eecs.umich.edu    return None
2112632Sstever@eecs.umich.edu
2128268Ssteve.reinhardt@amd.comdef config_builder(env, option):
2138268Ssteve.reinhardt@amd.com    target = os.path.join('config', option.lower() + '.hh')
2148268Ssteve.reinhardt@amd.com    source = Value(env[option])
2158268Ssteve.reinhardt@amd.com    def my_build_config_file(target, source, env):
2168268Ssteve.reinhardt@amd.com        build_config_file(target, source, env, option)
2178268Ssteve.reinhardt@amd.com    env.Command(target, source, my_build_config_file)
2188268Ssteve.reinhardt@amd.com
21913715Sandreas.sandberg@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
22013715Sandreas.sandberg@arm.com
22113715Sandreas.sandberg@arm.com# libelf build is described in its own SConscript file.
22213715Sandreas.sandberg@arm.com# SConscript-global is the build in build/libelf shared among all
22313715Sandreas.sandberg@arm.com# configs.
22413715Sandreas.sandberg@arm.comenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
22513715Sandreas.sandberg@arm.com
22613715Sandreas.sandberg@arm.com###################################################
22713715Sandreas.sandberg@arm.com#
22813715Sandreas.sandberg@arm.com# Define build environments for selected configurations.
22913715Sandreas.sandberg@arm.com#
23013715Sandreas.sandberg@arm.com###################################################
23113715Sandreas.sandberg@arm.com
2322632Sstever@eecs.umich.edu# rename base env
2332632Sstever@eecs.umich.edubase_env = env
2342632Sstever@eecs.umich.edu
2352632Sstever@eecs.umich.edufor build_dir in build_dirs:
2368268Ssteve.reinhardt@amd.com    # Make a copy of the default environment to use for this config.
2372632Sstever@eecs.umich.edu    env = base_env.Copy()
2388268Ssteve.reinhardt@amd.com    # Set env according to the build directory config.
2398268Ssteve.reinhardt@amd.com    options_file = os.path.join(build_dir, 'build_options')
2408268Ssteve.reinhardt@amd.com    opts = Options(options_file, ARGUMENTS)
2418268Ssteve.reinhardt@amd.com    opts.AddOptions(
2423718Sstever@eecs.umich.edu        EnumOption('TARGET_ISA', 'Target ISA', 'alpha', ('alpha')),
2432634Sstever@eecs.umich.edu        BoolOption('FULL_SYSTEM', 'Full-system support', False),
2442634Sstever@eecs.umich.edu        BoolOption('ALPHA_TLASER',
2455863Snate@binkert.org                   'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2462638Sstever@eecs.umich.edu        BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2478268Ssteve.reinhardt@amd.com        BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2482632Sstever@eecs.umich.edu                   False),
2492632Sstever@eecs.umich.edu        BoolOption('SS_COMPATIBLE_FP',
2502632Sstever@eecs.umich.edu                   'Make floating-point results compatible with SimpleScalar',
2512632Sstever@eecs.umich.edu                   False),
25212563Sgabeblack@google.com        BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2531858SN/A        BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2543716Sstever@eecs.umich.edu        BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv)
2552638Sstever@eecs.umich.edu        )
2562638Sstever@eecs.umich.edu
2572638Sstever@eecs.umich.edu    opts.Update(env)
2582638Sstever@eecs.umich.edu    opts.Save(options_file, env)
25912563Sgabeblack@google.com
26012563Sgabeblack@google.com    env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2612638Sstever@eecs.umich.edu                         'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2625863Snate@binkert.org                         'STATS_BINNING']
2635863Snate@binkert.org
2645863Snate@binkert.org    # Process option settings.
265955SN/A
2665341Sstever@gmail.com    if not have_fenv and env['USE_FENV']:
2675341Sstever@gmail.com        print "Warning: <fenv.h> not available; " \
2685863Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
2697756SAli.Saidi@ARM.com        env['USE_FENV'] = False
2705341Sstever@gmail.com
2716121Snate@binkert.org    if not env['USE_FENV']:
2724494Ssaidi@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
2736121Snate@binkert.org        print "         FP results may deviate slightly", \
2741105SN/A              "and some regression tests may fail."
2752667Sstever@eecs.umich.edu
2762667Sstever@eecs.umich.edu    if env['EFENCE']:
2772667Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
2782667Sstever@eecs.umich.edu
2796121Snate@binkert.org    if env['USE_MYSQL']:
2802667Sstever@eecs.umich.edu        if not have_mysql:
2815341Sstever@gmail.com            print "Warning: MySQL not available; " \
2825863Snate@binkert.org                  "forcing USE_MYSQL to False in", build_dir + "."
2835341Sstever@gmail.com            env['USE_MYSQL'] = False
2845341Sstever@gmail.com        else:
2855341Sstever@gmail.com            print "Compiling in", build_dir, "with MySQL support."
2868120Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config + ' --libs')
2875341Sstever@gmail.com            env.ParseConfig(mysql_config + ' --include')
2888120Sgblack@eecs.umich.edu    
2895341Sstever@gmail.com    # The m5/SConscript file sets up the build rules in 'env' according
2908120Sgblack@eecs.umich.edu    # to the configured options.
2916121Snate@binkert.org    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2926121Snate@binkert.org               duplicate=0)
29313715Sandreas.sandberg@arm.com
29413715Sandreas.sandberg@arm.com###################################################
2959396Sandreas.hansson@arm.com#
2965397Ssaidi@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
2975397Ssaidi@eecs.umich.edu# build environments to build the requested targets.
2987727SAli.Saidi@ARM.com#
2998268Ssteve.reinhardt@amd.com###################################################
3006168Snate@binkert.org
3015341Sstever@gmail.com