SConstruct revision 3716
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/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# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu###################################################
325863Snate@binkert.org#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
388878Ssteve.reinhardt@amd.com# the optimized full-system version).
392632Sstever@eecs.umich.edu#
408878Ssteve.reinhardt@amd.com# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
42955SN/A# expects that all configs under the same build directory are being
438878Ssteve.reinhardt@amd.com# built for the same host system.
442632Sstever@eecs.umich.edu#
452761Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482632Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512761Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
538878Ssteve.reinhardt@amd.com#   in a directory outside of the source tree.  The '-C' option tells
542761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
552761Sstever@eecs.umich.edu#   file.
562761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582761Sstever@eecs.umich.edu#
598878Ssteve.reinhardt@amd.com# You can use 'scons -H' to print scons options.  If you're in this
608878Ssteve.reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this
612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622632Sstever@eecs.umich.edu# options as well.
638878Ssteve.reinhardt@amd.com#
648878Ssteve.reinhardt@amd.com###################################################
652632Sstever@eecs.umich.edu
66955SN/A# Python library imports
67955SN/Aimport sys
68955SN/Aimport os
695863Snate@binkert.orgfrom os.path import join as joinpath
705863Snate@binkert.org
715863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
725863Snate@binkert.org# default installation of Python is not recent enough, you can use a
735863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
745863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
755863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
765863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
775863Snate@binkert.orgEnsurePythonVersion(2,4)
785863Snate@binkert.org
795863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
808878Ssteve.reinhardt@amd.com# 3-element version number.
815863Snate@binkert.orgmin_scons_version = (0,96,91)
825863Snate@binkert.orgtry:
835863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
845863Snate@binkert.orgexcept:
855863Snate@binkert.org    print "Error checking current SCons version."
865863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
875863Snate@binkert.org    Exit(2)
885863Snate@binkert.org    
895863Snate@binkert.org
905863Snate@binkert.org# The absolute path to the current directory (where this file lives).
915863Snate@binkert.orgROOT = Dir('.').abspath
925863Snate@binkert.org
935863Snate@binkert.org# Paths to the M5 and external source trees.
945863Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src')
955863Snate@binkert.org
968878Ssteve.reinhardt@amd.com# tell python where to find m5 python code
975863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python'))
985863Snate@binkert.org
995863Snate@binkert.org###################################################
1006654Snate@binkert.org#
101955SN/A# Figure out which configurations to set up based on the path(s) of
1025396Ssaidi@eecs.umich.edu# the target(s).
1035863Snate@binkert.org#
1045863Snate@binkert.org###################################################
1054202Sbinkertn@umich.edu
1065863Snate@binkert.org# Find default configuration & binary.
1075863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1085863Snate@binkert.org
1095863Snate@binkert.org# Ask SCons which directory it was invoked from.
110955SN/Alaunch_dir = GetLaunchDir()
1116654Snate@binkert.org
1125273Sstever@gmail.com# Make targets relative to invocation directory
1135871Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1145273Sstever@gmail.com                  BUILD_TARGETS)
1156655Snate@binkert.org
1168878Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list
1176655Snate@binkert.orgdef rfind(l, elt, offs = -1):
1186655Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
1199219Spower.jg@gmail.com        if l[i] == elt:
1206655Snate@binkert.org            return i
1215871Snate@binkert.org    raise ValueError, "element not found"
1226654Snate@binkert.org
1238947Sandreas.hansson@arm.com# helper function: compare dotted version numbers.
1245396Ssaidi@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1258120Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1268120Sgblack@eecs.umich.edudef compare_versions(v1, v2):
1278120Sgblack@eecs.umich.edu    # Convert dotted strings to lists
1288120Sgblack@eecs.umich.edu    v1 = map(int, v1.split('.'))
1298120Sgblack@eecs.umich.edu    v2 = map(int, v2.split('.'))
1308120Sgblack@eecs.umich.edu    # Compare corresponding elements of lists
1318120Sgblack@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1328120Sgblack@eecs.umich.edu        if n1 < n2: return -1
1338879Ssteve.reinhardt@amd.com        if n1 > n2: return  1
1348879Ssteve.reinhardt@amd.com    # all corresponding values are equal... see if one has extra values
1358879Ssteve.reinhardt@amd.com    if len(v1) < len(v2): return -1
1368879Ssteve.reinhardt@amd.com    if len(v1) > len(v2): return  1
1378879Ssteve.reinhardt@amd.com    return 0
1388879Ssteve.reinhardt@amd.com
1398879Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the
1408879Ssteve.reinhardt@amd.com# directory below this will determine the build parameters.  For
1418879Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1428879Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it
1438879Ssteve.reinhardt@amd.com# follow 'build' in the bulid path.
1448879Ssteve.reinhardt@amd.com
1458879Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
1468120Sgblack@eecs.umich.edu# collected targets reference.
1478120Sgblack@eecs.umich.edubuild_paths = []
1488120Sgblack@eecs.umich.edubuild_root = None
1498120Sgblack@eecs.umich.edufor t in abs_targets:
1508120Sgblack@eecs.umich.edu    path_dirs = t.split('/')
1518120Sgblack@eecs.umich.edu    try:
1528120Sgblack@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1538120Sgblack@eecs.umich.edu    except:
1548120Sgblack@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1558120Sgblack@eecs.umich.edu        Exit(1)
1568120Sgblack@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1578120Sgblack@eecs.umich.edu    if not build_root:
1588120Sgblack@eecs.umich.edu        build_root = this_build_root
1598120Sgblack@eecs.umich.edu    else:
1608879Ssteve.reinhardt@amd.com        if this_build_root != build_root:
1618879Ssteve.reinhardt@amd.com            print "Error: build targets not under same build root\n"\
1628879Ssteve.reinhardt@amd.com                  "  %s\n  %s" % (build_root, this_build_root)
1638879Ssteve.reinhardt@amd.com            Exit(1)
1648879Ssteve.reinhardt@amd.com    build_path = joinpath('/',*path_dirs[:build_top+2])
1658879Ssteve.reinhardt@amd.com    if build_path not in build_paths:
1668879Ssteve.reinhardt@amd.com        build_paths.append(build_path)
1678879Ssteve.reinhardt@amd.com
1689227Sandreas.hansson@arm.com###################################################
1699227Sandreas.hansson@arm.com#
1708879Ssteve.reinhardt@amd.com# Set up the default build environment.  This environment is copied
1718879Ssteve.reinhardt@amd.com# and modified according to each selected configuration.
1728879Ssteve.reinhardt@amd.com#
1738879Ssteve.reinhardt@amd.com###################################################
1748120Sgblack@eecs.umich.edu
1758947Sandreas.hansson@arm.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1767816Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1775871Snate@binkert.org                  SRCDIR = SRCDIR)
1785871Snate@binkert.org
1796121Snate@binkert.org#Parse CC/CXX early so that we use the correct compiler for 
1805871Snate@binkert.org# to test for dependencies/versions/libraries/includes
1815871Snate@binkert.orgif ARGUMENTS.get('CC', None):
1829119Sandreas.hansson@arm.com    env['CC'] = ARGUMENTS.get('CC')
1839396Sandreas.hansson@arm.com
1849396Sandreas.hansson@arm.comif ARGUMENTS.get('CXX', None):
185955SN/A    env['CXX'] = ARGUMENTS.get('CXX')
1869416SAndreas.Sandberg@ARM.com
1879416SAndreas.Sandberg@ARM.comenv.SConsignFile(joinpath(build_root,"sconsign"))
1889416SAndreas.Sandberg@ARM.com
1899416SAndreas.Sandberg@ARM.com# Default duplicate option is to use hard links, but this messes up
1909416SAndreas.Sandberg@ARM.com# when you use emacs to edit a file in the target dir, as emacs moves
1919416SAndreas.Sandberg@ARM.com# file to file~ then copies to file, breaking the link.  Symbolic
1929416SAndreas.Sandberg@ARM.com# (soft) links work better.
1935871Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy')
1945871Snate@binkert.org
1959416SAndreas.Sandberg@ARM.com# I waffle on this setting... it does avoid a few painful but
1969416SAndreas.Sandberg@ARM.com# unnecessary builds, but it also seems to make trivial builds take
1975871Snate@binkert.org# noticeably longer.
198955SN/Aif False:
1996121Snate@binkert.org    env.TargetSignatures('content')
2008881Smarc.orr@gmail.com
2016121Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
2026121Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
2031533SN/A
2049239Sandreas.hansson@arm.com# Set up default C++ compiler flags
2059239Sandreas.hansson@arm.comenv.Append(CCFLAGS='-pipe')
2069239Sandreas.hansson@arm.comenv.Append(CCFLAGS='-fno-strict-aliasing')
2079239Sandreas.hansson@arm.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2089239Sandreas.hansson@arm.comif sys.platform == 'cygwin':
2099239Sandreas.hansson@arm.com    # cygwin has some header file issues...
2109239Sandreas.hansson@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2119239Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')])
2129239Sandreas.hansson@arm.com
2139239Sandreas.hansson@arm.com# Check for SWIG
2149239Sandreas.hansson@arm.comif not env.has_key('SWIG'):
2159239Sandreas.hansson@arm.com    print 'Error: SWIG utility not found.'
2166655Snate@binkert.org    print '       Please install (see http://www.swig.org) and retry.'
2176655Snate@binkert.org    Exit(1)
2186655Snate@binkert.org
2196655Snate@binkert.org# Check for appropriate SWIG version
2205871Snate@binkert.orgswig_version = os.popen('swig -version').read().split()
2215871Snate@binkert.org# First 3 words should be "SWIG Version x.y.z"
2225863Snate@binkert.orgif swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2235871Snate@binkert.org    print 'Error determining SWIG version.'
2248878Ssteve.reinhardt@amd.com    Exit(1)
2255871Snate@binkert.org
2265871Snate@binkert.orgmin_swig_version = '1.3.28'
2275871Snate@binkert.orgif compare_versions(swig_version[2], min_swig_version) < 0:
2285863Snate@binkert.org    print 'Error: SWIG version', min_swig_version, 'or newer required.'
2296121Snate@binkert.org    print '       Installed version:', swig_version[2]
2305863Snate@binkert.org    Exit(1)
2315871Snate@binkert.org
2328336Ssteve.reinhardt@amd.com# Set up SWIG flags & scanner
2338336Ssteve.reinhardt@amd.comenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2348336Ssteve.reinhardt@amd.com
2358336Ssteve.reinhardt@amd.comimport SCons.Scanner
2364678Snate@binkert.org
2378336Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2388336Ssteve.reinhardt@amd.com
2398336Ssteve.reinhardt@amd.comswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2404678Snate@binkert.org                                        swig_inc_re)
2414678Snate@binkert.org
2424678Snate@binkert.orgenv.Append(SCANNERS = swig_scanner)
2434678Snate@binkert.org
2447827Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
2457827Snate@binkert.org# builds under a given build root run on the same host platform.
2468336Ssteve.reinhardt@amd.comconf = Configure(env,
2474678Snate@binkert.org                 conf_dir = joinpath(build_root, '.scons_config'),
2488336Ssteve.reinhardt@amd.com                 log_file = joinpath(build_root, 'scons_config.log'))
2498336Ssteve.reinhardt@amd.com
2508336Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the
2518336Ssteve.reinhardt@amd.com# interpreter.  For consistency, we will use the same Python
2528336Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script).  If you want
2538336Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how
2545871Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
2555871Snate@binkert.org
2568336Ssteve.reinhardt@amd.com# Get brief Python version name (e.g., "python2.4") for locating
2578336Ssteve.reinhardt@amd.com# include & library files
2588336Ssteve.reinhardt@amd.compy_version_name = 'python' + sys.version[:3]
2598336Ssteve.reinhardt@amd.com
2608336Ssteve.reinhardt@amd.com# include path, e.g. /usr/local/include/python2.4
2615871Snate@binkert.orgpy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
2628336Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path)
2638336Ssteve.reinhardt@amd.com# verify that it works
2648336Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'):
2658336Ssteve.reinhardt@amd.com    print "Error: can't find Python.h header in", py_header_path
2668336Ssteve.reinhardt@amd.com    Exit(1)
2674678Snate@binkert.org
2685871Snate@binkert.org# add library path too if it's not in the default place
2694678Snate@binkert.orgpy_lib_path = None
2708336Ssteve.reinhardt@amd.comif sys.exec_prefix != '/usr':
2718336Ssteve.reinhardt@amd.com    py_lib_path = joinpath(sys.exec_prefix, 'lib')
2728336Ssteve.reinhardt@amd.comelif sys.platform == 'cygwin':
2738336Ssteve.reinhardt@amd.com    # cygwin puts the .dll in /bin for some reason
2748336Ssteve.reinhardt@amd.com    py_lib_path = '/bin'
2758336Ssteve.reinhardt@amd.comif py_lib_path:
2768336Ssteve.reinhardt@amd.com    env.Append(LIBPATH = py_lib_path)
2778336Ssteve.reinhardt@amd.com    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
2788336Ssteve.reinhardt@amd.comif not conf.CheckLib(py_version_name):
2798336Ssteve.reinhardt@amd.com    print "Error: can't find Python library", py_version_name
2808336Ssteve.reinhardt@amd.com    Exit(1)
2818336Ssteve.reinhardt@amd.com
2828336Ssteve.reinhardt@amd.com# On Solaris you need to use libsocket for socket ops
2838336Ssteve.reinhardt@amd.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
2848336Ssteve.reinhardt@amd.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
2858336Ssteve.reinhardt@amd.com       print "Can't find library with socket calls (e.g. accept())"
2868336Ssteve.reinhardt@amd.com       Exit(1)
2875871Snate@binkert.org
2886121Snate@binkert.org# Check for zlib.  If the check passes, libz will be automatically
289955SN/A# added to the LIBS environment variable.
290955SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'):
2912632Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
2922632Sstever@eecs.umich.edu          'and/or zlib.h header file.'
293955SN/A    print '       Please install zlib and try again.'
294955SN/A    Exit(1)
295955SN/A
296955SN/A# Check for <fenv.h> (C99 FP environment control)
2978878Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
298955SN/Aif not have_fenv:
2992632Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
3002632Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
3012632Sstever@eecs.umich.edu
3022632Sstever@eecs.umich.edu# Check for mysql.
3032632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
3042632Sstever@eecs.umich.eduhave_mysql = mysql_config != None
3052632Sstever@eecs.umich.edu
3068268Ssteve.reinhardt@amd.com# Check MySQL version.
3078268Ssteve.reinhardt@amd.comif have_mysql:
3088268Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
3098268Ssteve.reinhardt@amd.com    min_mysql_version = '4.1'
3108268Ssteve.reinhardt@amd.com    if compare_versions(mysql_version, min_mysql_version) < 0:
3118268Ssteve.reinhardt@amd.com        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
3128268Ssteve.reinhardt@amd.com        print '         Version', mysql_version, 'detected.'
3132632Sstever@eecs.umich.edu        have_mysql = False
3142632Sstever@eecs.umich.edu
3152632Sstever@eecs.umich.edu# Set up mysql_config commands.
3162632Sstever@eecs.umich.eduif have_mysql:
3178268Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
3182632Sstever@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
3198268Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
3208268Ssteve.reinhardt@amd.com        # --cflags instead
3218268Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
3228268Ssteve.reinhardt@amd.com    # This seems to work in all versions
3233718Sstever@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
3242634Sstever@eecs.umich.edu
3252634Sstever@eecs.umich.eduenv = conf.Finish()
3265863Snate@binkert.org
3272638Sstever@eecs.umich.edu# Define the universe of supported ISAs
3288268Ssteve.reinhardt@amd.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
3292632Sstever@eecs.umich.edu
3302632Sstever@eecs.umich.edu# Define the universe of supported CPU models
3312632Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
3322632Sstever@eecs.umich.edu                       'O3CPU', 'OzoneCPU']
3332632Sstever@eecs.umich.edu
3341858SN/Aif os.path.isdir(joinpath(SRCDIR, 'src/encumbered/cpu/full')):
3353716Sstever@eecs.umich.edu    env['ALL_CPU_LIST'] += ['FullCPU']
3362638Sstever@eecs.umich.edu
3372638Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
3382638Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
3392638Sstever@eecs.umich.edu# value becomes sticky).
3402638Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
3412638Sstever@eecs.umich.edusticky_opts.AddOptions(
3422638Sstever@eecs.umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
3435863Snate@binkert.org    BoolOption('FULL_SYSTEM', 'Full-system support', False),
3445863Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
3455863Snate@binkert.org    # values (more than one value) not to be able to be restored from
346955SN/A    # a saved option file.  If this causes trouble then upgrade to
3475341Sstever@gmail.com    # scons 0.96.90 or later.
3485341Sstever@gmail.com    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU',
3495863Snate@binkert.org               env['ALL_CPU_LIST']),
3507756SAli.Saidi@ARM.com    BoolOption('ALPHA_TLASER',
3515341Sstever@gmail.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
3526121Snate@binkert.org    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
3534494Ssaidi@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
3546121Snate@binkert.org               False),
3551105SN/A    BoolOption('SS_COMPATIBLE_FP',
3562667Sstever@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
3572667Sstever@eecs.umich.edu               False),
3582667Sstever@eecs.umich.edu    BoolOption('USE_SSE2',
3592667Sstever@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
3606121Snate@binkert.org               False),
3612667Sstever@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
3625341Sstever@gmail.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
3635863Snate@binkert.org    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
3645341Sstever@gmail.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
3655341Sstever@gmail.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
3665341Sstever@gmail.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
3678120Sgblack@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3685341Sstever@gmail.com    ('PYTHONHOME',
3698120Sgblack@eecs.umich.edu     'Override the default PYTHONHOME for this system (use with caution)',
3705341Sstever@gmail.com     '%s:%s' % (sys.prefix, sys.exec_prefix))
3718120Sgblack@eecs.umich.edu    )
3726121Snate@binkert.org
3736121Snate@binkert.org# Non-sticky options only apply to the current build.
3748980Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS)
3759396Sandreas.hansson@arm.comnonsticky_opts.AddOptions(
3765397Ssaidi@eecs.umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
3775397Ssaidi@eecs.umich.edu    )
3787727SAli.Saidi@ARM.com
3798268Ssteve.reinhardt@amd.com# These options get exported to #defines in config/*.hh (see src/SConscript).
3806168Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3815341Sstever@gmail.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3828120Sgblack@eecs.umich.edu                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
3838120Sgblack@eecs.umich.edu
3848120Sgblack@eecs.umich.edu# Define a handy 'no-op' action
3856814Sgblack@eecs.umich.edudef no_action(target, source, env):
3865863Snate@binkert.org    return 0
3878120Sgblack@eecs.umich.edu
3885341Sstever@gmail.comenv.NoAction = Action(no_action, None)
3895863Snate@binkert.org
3908268Ssteve.reinhardt@amd.com###################################################
3916121Snate@binkert.org#
3926121Snate@binkert.org# Define a SCons builder for configuration flag headers.
3938268Ssteve.reinhardt@amd.com#
3945742Snate@binkert.org###################################################
3955742Snate@binkert.org
3965341Sstever@gmail.com# This function generates a config header file that #defines the
3975742Snate@binkert.org# option symbol to the current option setting (0 or 1).  The source
3985742Snate@binkert.org# operands are the name of the option and a Value node containing the
3995341Sstever@gmail.com# value of the option.
4006017Snate@binkert.orgdef build_config_file(target, source, env):
4016121Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
4026017Snate@binkert.org    f = file(str(target[0]), 'w')
4037816Ssteve.reinhardt@amd.com    print >> f, '#define', option, value
4047756SAli.Saidi@ARM.com    f.close()
4057756SAli.Saidi@ARM.com    return None
4067756SAli.Saidi@ARM.com
4077756SAli.Saidi@ARM.com# Generate the message to be printed when building the config file.
4087756SAli.Saidi@ARM.comdef build_config_file_string(target, source, env):
4097756SAli.Saidi@ARM.com    (option, value) = [s.get_contents() for s in source]
4107756SAli.Saidi@ARM.com    return "Defining %s as %s in %s." % (option, value, target[0])
4117756SAli.Saidi@ARM.com
4127816Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object.
4137816Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string)
4147816Ssteve.reinhardt@amd.com
4157816Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what
4167816Ssteve.reinhardt@amd.com# we're really doing.
4177816Ssteve.reinhardt@amd.comdef config_emitter(target, source, env):
4187816Ssteve.reinhardt@amd.com    # extract option name from Builder arg
4197816Ssteve.reinhardt@amd.com    option = str(target[0])
4207816Ssteve.reinhardt@amd.com    # True target is config header file
4217816Ssteve.reinhardt@amd.com    target = joinpath('config', option.lower() + '.hh')
4227756SAli.Saidi@ARM.com    val = env[option]
4237816Ssteve.reinhardt@amd.com    if isinstance(val, bool):
4247816Ssteve.reinhardt@amd.com        # Force value to 0/1
4257816Ssteve.reinhardt@amd.com        val = int(val)
4267816Ssteve.reinhardt@amd.com    elif isinstance(val, str):
4277816Ssteve.reinhardt@amd.com        val = '"' + val + '"'
4287816Ssteve.reinhardt@amd.com        
4297816Ssteve.reinhardt@amd.com    # Sources are option name & value (packaged in SCons Value nodes)
4307816Ssteve.reinhardt@amd.com    return ([target], [Value(option), Value(val)])
4317816Ssteve.reinhardt@amd.com
4327816Ssteve.reinhardt@amd.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
4337816Ssteve.reinhardt@amd.com
4347816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
4357816Ssteve.reinhardt@amd.com
4367816Ssteve.reinhardt@amd.com###################################################
4377816Ssteve.reinhardt@amd.com#
4387816Ssteve.reinhardt@amd.com# Define a SCons builder for copying files.  This is used by the
4397816Ssteve.reinhardt@amd.com# Python zipfile code in src/python/SConscript, but is placed up here
4407816Ssteve.reinhardt@amd.com# since it's potentially more generally applicable.
4417816Ssteve.reinhardt@amd.com#
4427816Ssteve.reinhardt@amd.com###################################################
4437816Ssteve.reinhardt@amd.com
4447816Ssteve.reinhardt@amd.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
4457816Ssteve.reinhardt@amd.com
4467816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
4477816Ssteve.reinhardt@amd.com
4487816Ssteve.reinhardt@amd.com###################################################
4497816Ssteve.reinhardt@amd.com#
4507816Ssteve.reinhardt@amd.com# Define a simple SCons builder to concatenate files.
4517816Ssteve.reinhardt@amd.com#
4527816Ssteve.reinhardt@amd.com# Used to append the Python zip archive to the executable.
4537816Ssteve.reinhardt@amd.com#
4547816Ssteve.reinhardt@amd.com###################################################
4557816Ssteve.reinhardt@amd.com
4567816Ssteve.reinhardt@amd.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
4577816Ssteve.reinhardt@amd.com                                          'chmod +x $TARGET']))
4587816Ssteve.reinhardt@amd.com
4597816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
4607816Ssteve.reinhardt@amd.com
4617816Ssteve.reinhardt@amd.com
4627816Ssteve.reinhardt@amd.com# base help text
4637816Ssteve.reinhardt@amd.comhelp_text = '''
4647816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)]
4657816Ssteve.reinhardt@amd.com
4667816Ssteve.reinhardt@amd.com'''
4677816Ssteve.reinhardt@amd.com
4687816Ssteve.reinhardt@amd.com# libelf build is shared across all configs in the build root.
4697816Ssteve.reinhardt@amd.comenv.SConscript('ext/libelf/SConscript',
4707816Ssteve.reinhardt@amd.com               build_dir = joinpath(build_root, 'libelf'),
4717816Ssteve.reinhardt@amd.com               exports = 'env')
4727816Ssteve.reinhardt@amd.com
4737816Ssteve.reinhardt@amd.com###################################################
4747816Ssteve.reinhardt@amd.com#
4757816Ssteve.reinhardt@amd.com# This function is used to set up a directory with switching headers
4767816Ssteve.reinhardt@amd.com#
4777816Ssteve.reinhardt@amd.com###################################################
4787816Ssteve.reinhardt@amd.com
4797816Ssteve.reinhardt@amd.comdef make_switching_dir(dirname, switch_headers, env):
4807816Ssteve.reinhardt@amd.com    # Generate the header.  target[0] is the full path of the output
4817816Ssteve.reinhardt@amd.com    # header to generate.  'source' is a dummy variable, since we get the
4827816Ssteve.reinhardt@amd.com    # list of ISAs from env['ALL_ISA_LIST'].
4837816Ssteve.reinhardt@amd.com    def gen_switch_hdr(target, source, env):
4848947Sandreas.hansson@arm.com	fname = str(target[0])
4858947Sandreas.hansson@arm.com	basename = os.path.basename(fname)
4867756SAli.Saidi@ARM.com	f = open(fname, 'w')
4878120Sgblack@eecs.umich.edu	f.write('#include "arch/isa_specific.hh"\n')
4887756SAli.Saidi@ARM.com	cond = '#if'
4897756SAli.Saidi@ARM.com	for isa in env['ALL_ISA_LIST']:
4907756SAli.Saidi@ARM.com	    f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
4917756SAli.Saidi@ARM.com		    % (cond, isa.upper(), dirname, isa, basename))
4927816Ssteve.reinhardt@amd.com	    cond = '#elif'
4937816Ssteve.reinhardt@amd.com	f.write('#else\n#error "THE_ISA not set"\n#endif\n')
4947816Ssteve.reinhardt@amd.com	f.close()
4957816Ssteve.reinhardt@amd.com	return 0
4967816Ssteve.reinhardt@amd.com
4977816Ssteve.reinhardt@amd.com    # String to print when generating header
4987816Ssteve.reinhardt@amd.com    def gen_switch_hdr_string(target, source, env):
4997816Ssteve.reinhardt@amd.com	return "Generating switch header " + str(target[0])
5007816Ssteve.reinhardt@amd.com
5017816Ssteve.reinhardt@amd.com    # Build SCons Action object. 'varlist' specifies env vars that this
5027756SAli.Saidi@ARM.com    # action depends on; when env['ALL_ISA_LIST'] changes these actions
5037756SAli.Saidi@ARM.com    # should get re-executed.
5049227Sandreas.hansson@arm.com    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
5059227Sandreas.hansson@arm.com                               varlist=['ALL_ISA_LIST'])
5069227Sandreas.hansson@arm.com
5079227Sandreas.hansson@arm.com    # Instantiate actions for each header
5089590Sandreas@sandberg.pp.se    for hdr in switch_headers:
5099590Sandreas@sandberg.pp.se        env.Command(hdr, [], switch_hdr_action)
5109590Sandreas@sandberg.pp.se
5119590Sandreas@sandberg.pp.seenv.make_switching_dir = make_switching_dir
5129590Sandreas@sandberg.pp.se
5139590Sandreas@sandberg.pp.se###################################################
5146654Snate@binkert.org#
5156654Snate@binkert.org# Define build environments for selected configurations.
5165871Snate@binkert.org#
5176121Snate@binkert.org###################################################
5188946Sandreas.hansson@arm.com
5199419Sandreas.hansson@arm.com# rename base env
5203940Ssaidi@eecs.umich.edubase_env = env
5213918Ssaidi@eecs.umich.edu
5223918Ssaidi@eecs.umich.edufor build_path in build_paths:
5231858SN/A    print "Building in", build_path
5249556Sandreas.hansson@arm.com    # build_dir is the tail component of build path, and is used to
5259556Sandreas.hansson@arm.com    # determine the build parameters (e.g., 'ALPHA_SE')
5269556Sandreas.hansson@arm.com    (build_root, build_dir) = os.path.split(build_path)
5279556Sandreas.hansson@arm.com    # Make a copy of the build-root environment to use for this config.
5289556Sandreas.hansson@arm.com    env = base_env.Copy()
5299556Sandreas.hansson@arm.com
5309556Sandreas.hansson@arm.com    # Set env options according to the build directory config.
5319556Sandreas.hansson@arm.com    sticky_opts.files = []
5329556Sandreas.hansson@arm.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
5339556Sandreas.hansson@arm.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
5349556Sandreas.hansson@arm.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
5359556Sandreas.hansson@arm.com    current_opts_file = joinpath(build_root, 'options', build_dir)
5369556Sandreas.hansson@arm.com    if os.path.isfile(current_opts_file):
5379556Sandreas.hansson@arm.com        sticky_opts.files.append(current_opts_file)
5389556Sandreas.hansson@arm.com        print "Using saved options file %s" % current_opts_file
5399556Sandreas.hansson@arm.com    else:
5409556Sandreas.hansson@arm.com        # Build dir-specific options file doesn't exist.
5419556Sandreas.hansson@arm.com
5429556Sandreas.hansson@arm.com        # Make sure the directory is there so we can create it later
5439556Sandreas.hansson@arm.com        opt_dir = os.path.dirname(current_opts_file)
5449556Sandreas.hansson@arm.com        if not os.path.isdir(opt_dir):
5459556Sandreas.hansson@arm.com            os.mkdir(opt_dir)
5469556Sandreas.hansson@arm.com
5479556Sandreas.hansson@arm.com        # Get default build options from source tree.  Options are
5489556Sandreas.hansson@arm.com        # normally determined by name of $BUILD_DIR, but can be
5499556Sandreas.hansson@arm.com        # overriden by 'default=' arg on command line.
5509556Sandreas.hansson@arm.com        default_opts_file = joinpath('build_opts',
5519556Sandreas.hansson@arm.com                                     ARGUMENTS.get('default', build_dir))
5529556Sandreas.hansson@arm.com        if os.path.isfile(default_opts_file):
5539556Sandreas.hansson@arm.com            sticky_opts.files.append(default_opts_file)
5549556Sandreas.hansson@arm.com            print "Options file %s not found,\n  using defaults in %s" \
5559556Sandreas.hansson@arm.com                  % (current_opts_file, default_opts_file)
5566121Snate@binkert.org        else:
5579420Sandreas.hansson@arm.com            print "Error: cannot find options file %s or %s" \
5589420Sandreas.hansson@arm.com                  % (current_opts_file, default_opts_file)
5599420Sandreas.hansson@arm.com            Exit(1)
5609420Sandreas.hansson@arm.com
5619420Sandreas.hansson@arm.com    # Apply current option settings to env
5629420Sandreas.hansson@arm.com    sticky_opts.Update(env)
5639420Sandreas.hansson@arm.com    nonsticky_opts.Update(env)
5649420Sandreas.hansson@arm.com
5659420Sandreas.hansson@arm.com    help_text += "Sticky options for %s:\n" % build_dir \
5669420Sandreas.hansson@arm.com                 + sticky_opts.GenerateHelpText(env) \
5679420Sandreas.hansson@arm.com                 + "\nNon-sticky options for %s:\n" % build_dir \
5687618SAli.Saidi@arm.com                 + nonsticky_opts.GenerateHelpText(env)
5697618SAli.Saidi@arm.com
5707618SAli.Saidi@arm.com    # Process option settings.
5717739Sgblack@eecs.umich.edu
5729227Sandreas.hansson@arm.com    if not have_fenv and env['USE_FENV']:
5739227Sandreas.hansson@arm.com        print "Warning: <fenv.h> not available; " \
5749227Sandreas.hansson@arm.com              "forcing USE_FENV to False in", build_dir + "."
5759227Sandreas.hansson@arm.com        env['USE_FENV'] = False
5769227Sandreas.hansson@arm.com
5779227Sandreas.hansson@arm.com    if not env['USE_FENV']:
5789227Sandreas.hansson@arm.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
5799227Sandreas.hansson@arm.com        print "         FP results may deviate slightly from other platforms."
5809227Sandreas.hansson@arm.com
5819227Sandreas.hansson@arm.com    if env['EFENCE']:
5829227Sandreas.hansson@arm.com        env.Append(LIBS=['efence'])
5839227Sandreas.hansson@arm.com
5849227Sandreas.hansson@arm.com    if env['USE_MYSQL']:
5859227Sandreas.hansson@arm.com        if not have_mysql:
5869227Sandreas.hansson@arm.com            print "Warning: MySQL not available; " \
5879227Sandreas.hansson@arm.com                  "forcing USE_MYSQL to False in", build_dir + "."
5889227Sandreas.hansson@arm.com            env['USE_MYSQL'] = False
5899227Sandreas.hansson@arm.com        else:
5909590Sandreas@sandberg.pp.se            print "Compiling in", build_dir, "with MySQL support."
5919590Sandreas@sandberg.pp.se            env.ParseConfig(mysql_config_libs)
5929590Sandreas@sandberg.pp.se            env.ParseConfig(mysql_config_include)
5938737Skoansin.tan@gmail.com
5949420Sandreas.hansson@arm.com    # Save sticky option settings back to current options file
5959420Sandreas.hansson@arm.com    sticky_opts.Save(current_opts_file, env)
5969420Sandreas.hansson@arm.com
5978737Skoansin.tan@gmail.com    # Do this after we save setting back, or else we'll tack on an
5988737Skoansin.tan@gmail.com    # extra 'qdo' every time we run scons.
5998737Skoansin.tan@gmail.com    if env['BATCH']:
6008737Skoansin.tan@gmail.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
6018737Skoansin.tan@gmail.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
6028737Skoansin.tan@gmail.com
6038737Skoansin.tan@gmail.com    if env['USE_SSE2']:
6048737Skoansin.tan@gmail.com        env.Append(CCFLAGS='-msse2')
6058737Skoansin.tan@gmail.com
6068737Skoansin.tan@gmail.com    # The src/SConscript file sets up the build rules in 'env' according
6078737Skoansin.tan@gmail.com    # to the configured options.  It returns a list of environments,
6088737Skoansin.tan@gmail.com    # one for each variant build (debug, opt, etc.)
6099556Sandreas.hansson@arm.com    envList = SConscript('src/SConscript', build_dir = build_path,
6109556Sandreas.hansson@arm.com                         exports = 'env')
6119556Sandreas.hansson@arm.com
6129556Sandreas.hansson@arm.com    # Set up the regression tests for each build.
6139556Sandreas.hansson@arm.com    for e in envList:
6149556Sandreas.hansson@arm.com        SConscript('tests/SConscript',
6159556Sandreas.hansson@arm.com                   build_dir = joinpath(build_path, 'tests', e.Label),
6169556Sandreas.hansson@arm.com                   exports = { 'env' : e }, duplicate = False)
6179556Sandreas.hansson@arm.com
6189556Sandreas.hansson@arm.comHelp(help_text)
6199590Sandreas@sandberg.pp.se
6209590Sandreas@sandberg.pp.se
6219420Sandreas.hansson@arm.com###################################################
6229420Sandreas.hansson@arm.com#
6239420Sandreas.hansson@arm.com# Let SCons do its thing.  At this point SCons will use the defined
6249420Sandreas.hansson@arm.com# build environments to build the requested targets.
6259420Sandreas.hansson@arm.com#
6269420Sandreas.hansson@arm.com###################################################
6279420Sandreas.hansson@arm.com
6289420Sandreas.hansson@arm.com