SConstruct revision 8897:1021e1f313d0
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc. 4955SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 5955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 6955SN/A# All rights reserved. 7955SN/A# 8955SN/A# Redistribution and use in source and binary forms, with or without 9955SN/A# modification, are permitted provided that the following conditions are 10955SN/A# met: redistributions of source code must retain the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer; 12955SN/A# redistributions in binary form must reproduce the above copyright 13955SN/A# notice, this list of conditions and the following disclaimer in the 14955SN/A# documentation and/or other materials provided with the distribution; 15955SN/A# neither the name of the copyright holders nor the names of its 16955SN/A# contributors may be used to endorse or promote products derived from 17955SN/A# this software without specific prior written permission. 18955SN/A# 19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 282665Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 294762Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30955SN/A# 315522Snate@binkert.org# Authors: Steve Reinhardt 326143Snate@binkert.org# Nathan Binkert 334762Snate@binkert.org 345522Snate@binkert.org################################################### 35955SN/A# 365522Snate@binkert.org# SCons top-level build description (SConstruct) file. 37955SN/A# 385522Snate@binkert.org# While in this directory ('gem5'), just type 'scons' to build the default 394202Sbinkertn@umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 405742Snate@binkert.org# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 41955SN/A# the optimized full-system version). 424381Sbinkertn@umich.edu# 434381Sbinkertn@umich.edu# You can build gem5 in a different directory as long as there is a 44955SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 45955SN/A# expects that all configs under the same build directory are being 46955SN/A# built for the same host system. 474202Sbinkertn@umich.edu# 48955SN/A# Examples: 494382Sbinkertn@umich.edu# 504382Sbinkertn@umich.edu# The following two commands are equivalent. The '-u' option tells 514382Sbinkertn@umich.edu# scons to search up the directory tree for this SConstruct file. 526654Snate@binkert.org# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 535517Snate@binkert.org# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 547674Snate@binkert.org# 557674Snate@binkert.org# The following two commands are equivalent and demonstrate building 566143Snate@binkert.org# in a directory outside of the source tree. The '-C' option tells 576143Snate@binkert.org# scons to chdir to the specified directory to find this SConstruct 586143Snate@binkert.org# file. 596143Snate@binkert.org# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 606143Snate@binkert.org# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 616143Snate@binkert.org# 626143Snate@binkert.org# You can use 'scons -H' to print scons options. If you're in this 636143Snate@binkert.org# 'gem5' directory (or use -u or -C to tell scons where to find this 646143Snate@binkert.org# file), you can use 'scons -h' to print all the gem5-specific build 656143Snate@binkert.org# options as well. 666143Snate@binkert.org# 676143Snate@binkert.org################################################### 686143Snate@binkert.org 696143Snate@binkert.org# Check for recent-enough Python and SCons versions. 706143Snate@binkert.orgtry: 714762Snate@binkert.org # Really old versions of scons only take two options for the 726143Snate@binkert.org # function, so check once without the revision and once with the 736143Snate@binkert.org # revision, the first instance will fail for stuff other than 746143Snate@binkert.org # 0.98, and the second will fail for 0.98.0 756143Snate@binkert.org EnsureSConsVersion(0, 98) 766143Snate@binkert.org EnsureSConsVersion(0, 98, 1) 776143Snate@binkert.orgexcept SystemExit, e: 786143Snate@binkert.org print """ 796143Snate@binkert.orgFor more details, see: 806143Snate@binkert.org http://gem5.org/Dependencies 816143Snate@binkert.org""" 826143Snate@binkert.org raise 836143Snate@binkert.org 846143Snate@binkert.org# We ensure the python version early because we have stuff that 856143Snate@binkert.org# requires python 2.4 866143Snate@binkert.orgtry: 876143Snate@binkert.org EnsurePythonVersion(2, 4) 886143Snate@binkert.orgexcept SystemExit, e: 896143Snate@binkert.org print """ 906143Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 916143Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 926143Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 937065Snate@binkert.orgon the scons script. 946143Snate@binkert.org 956143Snate@binkert.orgFor more details, see: 966143Snate@binkert.org http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 976143Snate@binkert.org""" 986143Snate@binkert.org raise 996143Snate@binkert.org 1006143Snate@binkert.org# Global Python includes 1016143Snate@binkert.orgimport os 1026143Snate@binkert.orgimport re 1036143Snate@binkert.orgimport subprocess 1046143Snate@binkert.orgimport sys 1056143Snate@binkert.org 1066143Snate@binkert.orgfrom os import mkdir, environ 1076143Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1086143Snate@binkert.orgfrom os.path import exists, isdir, isfile 1096143Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1106143Snate@binkert.org 1116143Snate@binkert.org# SCons includes 1126143Snate@binkert.orgimport SCons 1136143Snate@binkert.orgimport SCons.Node 1146143Snate@binkert.org 1155522Snate@binkert.orgextra_python_paths = [ 1166143Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1176143Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1186143Snate@binkert.org ] 1196143Snate@binkert.org 1206143Snate@binkert.orgsys.path[1:1] = extra_python_paths 1216143Snate@binkert.org 1226143Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1236143Snate@binkert.org 1246143Snate@binkert.orghelp_texts = { 1256143Snate@binkert.org "options" : "", 1265522Snate@binkert.org "global_vars" : "", 1275522Snate@binkert.org "local_vars" : "" 1285522Snate@binkert.org} 1295522Snate@binkert.org 1305604Snate@binkert.orgExport("help_texts") 1315604Snate@binkert.org 1326143Snate@binkert.org 1336143Snate@binkert.org# There's a bug in scons in that (1) by default, the help texts from 1344762Snate@binkert.org# AddOption() are supposed to be displayed when you type 'scons -h' 1354762Snate@binkert.org# and (2) you can override the help displayed by 'scons -h' using the 1366143Snate@binkert.org# Help() function, but these two features are incompatible: once 1376727Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1386727Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1396727Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1404762Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1416143Snate@binkert.org# This hack lets us extract the help text from AddOptions and 1426143Snate@binkert.org# re-inject it via Help(). Ideally someday this bug will be fixed and 1436143Snate@binkert.org# we can just use AddOption directly. 1446143Snate@binkert.orgdef AddLocalOption(*args, **kwargs): 1456727Ssteve.reinhardt@amd.com col_width = 30 1466143Snate@binkert.org 1477674Snate@binkert.org help = " " + ", ".join(args) 1487674Snate@binkert.org if "help" in kwargs: 1495604Snate@binkert.org length = len(help) 1506143Snate@binkert.org if length >= col_width: 1516143Snate@binkert.org help += "\n" + " " * col_width 1526143Snate@binkert.org else: 1534762Snate@binkert.org help += " " * (col_width - length) 1546143Snate@binkert.org help += kwargs["help"] 1554762Snate@binkert.org help_texts["options"] += help + "\n" 1564762Snate@binkert.org 1574762Snate@binkert.org AddOption(*args, **kwargs) 1586143Snate@binkert.org 1596143Snate@binkert.orgAddLocalOption('--colors', dest='use_colors', action='store_true', 1604762Snate@binkert.org help="Add color to abbreviated scons output") 1616143Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1626143Snate@binkert.org help="Don't add color to abbreviated scons output") 1636143Snate@binkert.orgAddLocalOption('--default', dest='default', type='string', action='store', 1646143Snate@binkert.org help='Override which build_opts file to use for defaults') 1654762Snate@binkert.orgAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1666143Snate@binkert.org help='Disable style checking hooks') 1674762Snate@binkert.orgAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1686143Snate@binkert.org help='Update test reference outputs') 1694762Snate@binkert.orgAddLocalOption('--verbose', dest='verbose', action='store_true', 1706143Snate@binkert.org help='Print full tool command lines') 1716143Snate@binkert.org 1726143Snate@binkert.orguse_colors = GetOption('use_colors') 1736143Snate@binkert.orgif use_colors: 1746143Snate@binkert.org from m5.util.terminal import termcap 1756143Snate@binkert.orgelif use_colors is None: 1766143Snate@binkert.org # option unspecified; default behavior is to use colors iff isatty 1776143Snate@binkert.org from m5.util.terminal import tty_termcap as termcap 1786143Snate@binkert.orgelse: 1796143Snate@binkert.org from m5.util.terminal import no_termcap as termcap 1806143Snate@binkert.org 1816143Snate@binkert.org######################################################################## 1826143Snate@binkert.org# 183955SN/A# Set up the main build environment. 1845584Snate@binkert.org# 1855584Snate@binkert.org######################################################################## 1865584Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1875584Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1886143Snate@binkert.org 1896143Snate@binkert.orguse_env = {} 1906143Snate@binkert.orgfor key,val in os.environ.iteritems(): 1915584Snate@binkert.org if key in use_vars or key.startswith("M5"): 1924382Sbinkertn@umich.edu use_env[key] = val 1934202Sbinkertn@umich.edu 1944382Sbinkertn@umich.edumain = Environment(ENV=use_env) 1954382Sbinkertn@umich.edumain.Decider('MD5-timestamp') 1964382Sbinkertn@umich.edumain.root = Dir(".") # The current directory (where this file lives). 1975584Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1984382Sbinkertn@umich.edu 1994382Sbinkertn@umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 2004382Sbinkertn@umich.edu# as well 2015192Ssaidi@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 2025192Ssaidi@eecs.umich.edu 2035799Snate@binkert.org######################################################################## 2045799Snate@binkert.org# 2055799Snate@binkert.org# Mercurial Stuff. 2065192Ssaidi@eecs.umich.edu# 2075799Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2085192Ssaidi@eecs.umich.edu# extra things. 2095799Snate@binkert.org# 2105799Snate@binkert.org######################################################################## 2115192Ssaidi@eecs.umich.edu 2125192Ssaidi@eecs.umich.eduhgdir = main.root.Dir(".hg") 2135192Ssaidi@eecs.umich.edu 2145799Snate@binkert.orgmercurial_style_message = """ 2155192Ssaidi@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2165192Ssaidi@eecs.umich.eduagainst the gem5 style rules on hg commit and qrefresh commands. This 2175192Ssaidi@eecs.umich.eduscript will now install the hook in your .hg/hgrc file. 2185192Ssaidi@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 2195192Ssaidi@eecs.umich.edu 2205192Ssaidi@eecs.umich.edumercurial_style_hook = """ 2214382Sbinkertn@umich.edu# The following lines were automatically added by gem5/SConstruct 2224382Sbinkertn@umich.edu# to provide the gem5 style-checking hooks 2234382Sbinkertn@umich.edu[extensions] 2242667Sstever@eecs.umich.edustyle = %s/util/style.py 2252667Sstever@eecs.umich.edu 2262667Sstever@eecs.umich.edu[hooks] 2272667Sstever@eecs.umich.edupretxncommit.style = python:style.check_style 2282667Sstever@eecs.umich.edupre-qrefresh.style = python:style.check_style 2292667Sstever@eecs.umich.edu# End of SConstruct additions 2305742Snate@binkert.org 2315742Snate@binkert.org""" % (main.root.abspath) 2325742Snate@binkert.org 2335793Snate@binkert.orgmercurial_lib_not_found = """ 2345793Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2355793Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2365793Snate@binkert.orghook. It is important. 2375793Snate@binkert.org""" 2384382Sbinkertn@umich.edu 2394762Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2405344Sstever@gmail.com# Skip this if --ignore-style was specified, there's no .hg dir to 2414382Sbinkertn@umich.edu# install a hook in, or there's no interactive terminal to prompt. 2425341Sstever@gmail.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2435742Snate@binkert.org style_hook = True 2445742Snate@binkert.org try: 2455742Snate@binkert.org from mercurial import ui 2465742Snate@binkert.org ui = ui.ui() 2475742Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2484762Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2495742Snate@binkert.org ui.config('hooks', 'pre-qrefresh.style', None) 2505742Snate@binkert.org except ImportError: 2517722Sgblack@eecs.umich.edu print mercurial_lib_not_found 2525742Snate@binkert.org 2535742Snate@binkert.org if not style_hook: 2545742Snate@binkert.org print mercurial_style_message, 2555742Snate@binkert.org # continue unless user does ctrl-c/ctrl-d etc. 2565341Sstever@gmail.com try: 2575742Snate@binkert.org raw_input() 2587722Sgblack@eecs.umich.edu except: 2594773Snate@binkert.org print "Input exception, exiting scons.\n" 2606108Snate@binkert.org sys.exit(1) 2611858SN/A hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2621085SN/A print "Adding style hook to", hgrc_path, "\n" 2636658Snate@binkert.org try: 2646658Snate@binkert.org hgrc = open(hgrc_path, 'a') 2657673Snate@binkert.org hgrc.write(mercurial_style_hook) 2666658Snate@binkert.org hgrc.close() 2676658Snate@binkert.org except: 2686658Snate@binkert.org print "Error updating", hgrc_path 2696658Snate@binkert.org sys.exit(1) 2706658Snate@binkert.org 2716658Snate@binkert.org 2726658Snate@binkert.org################################################### 2737673Snate@binkert.org# 2747673Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 2757673Snate@binkert.org# the target(s). 2767673Snate@binkert.org# 2777673Snate@binkert.org################################################### 2787673Snate@binkert.org 2797673Snate@binkert.org# Find default configuration & binary. 2806658Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2817673Snate@binkert.org 2827673Snate@binkert.org# helper function: find last occurrence of element in list 2837673Snate@binkert.orgdef rfind(l, elt, offs = -1): 2847673Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2857673Snate@binkert.org if l[i] == elt: 2867673Snate@binkert.org return i 2877673Snate@binkert.org raise ValueError, "element not found" 2887673Snate@binkert.org 2897673Snate@binkert.org# Take a list of paths (or SCons Nodes) and return a list with all 2907673Snate@binkert.org# paths made absolute and ~-expanded. Paths will be interpreted 2916658Snate@binkert.org# relative to the launch directory unless a different root is provided 2927756SAli.Saidi@ARM.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2937756SAli.Saidi@ARM.com return [abspath(joinpath(root, expanduser(str(p)))) 2946658Snate@binkert.org for p in path_list] 2954382Sbinkertn@umich.edu 2964382Sbinkertn@umich.edu# Each target must have 'build' in the interior of the path; the 2974762Snate@binkert.org# directory below this will determine the build parameters. For 2984762Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2994762Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 3006654Snate@binkert.org# follow 'build' in the build path. 3016654Snate@binkert.org 3025517Snate@binkert.org# The funky assignment to "[:]" is needed to replace the list contents 3035517Snate@binkert.org# in place rather than reassign the symbol to a new list, which 3045517Snate@binkert.org# doesn't work (obviously!). 3055517Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3065517Snate@binkert.org 3075517Snate@binkert.org# Generate a list of the unique build roots and configs that the 3085517Snate@binkert.org# collected targets reference. 3095517Snate@binkert.orgvariant_paths = [] 3105517Snate@binkert.orgbuild_root = None 3115517Snate@binkert.orgfor t in BUILD_TARGETS: 3125517Snate@binkert.org path_dirs = t.split('/') 3135517Snate@binkert.org try: 3145517Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 3155517Snate@binkert.org except: 3165517Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 3175517Snate@binkert.org Exit(1) 3185517Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3196654Snate@binkert.org if not build_root: 3205517Snate@binkert.org build_root = this_build_root 3215517Snate@binkert.org else: 3225517Snate@binkert.org if this_build_root != build_root: 3235517Snate@binkert.org print "Error: build targets not under same build root\n"\ 3245517Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 3255517Snate@binkert.org Exit(1) 3265517Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 3275517Snate@binkert.org if variant_path not in variant_paths: 3286143Snate@binkert.org variant_paths.append(variant_path) 3296654Snate@binkert.org 3305517Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 3315517Snate@binkert.orgif not isdir(build_root): 3325517Snate@binkert.org mkdir(build_root) 3335517Snate@binkert.orgmain['BUILDROOT'] = build_root 3345517Snate@binkert.org 3355517Snate@binkert.orgExport('main') 3365517Snate@binkert.org 3375517Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 3385517Snate@binkert.org 3395517Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 3405517Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 3415517Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 3425517Snate@binkert.org# (soft) links work better. 3435517Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3446654Snate@binkert.org 3456654Snate@binkert.org# 3465517Snate@binkert.org# Set up global sticky variables... these are common to an entire build 3475517Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 3486143Snate@binkert.org# 3496143Snate@binkert.org 3506143Snate@binkert.orgglobal_vars_file = joinpath(build_root, 'variables.global') 3516727Ssteve.reinhardt@amd.com 3525517Snate@binkert.orgglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3536727Ssteve.reinhardt@amd.com 3545517Snate@binkert.orgglobal_vars.AddVariables( 3555517Snate@binkert.org ('CC', 'C compiler', environ.get('CC', main['CC'])), 3565517Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3576654Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 3586654Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3597673Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3606654Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3616654Snate@binkert.org ) 3626654Snate@binkert.org 3636654Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 3645517Snate@binkert.orgglobal_vars.Update(main) 3655517Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3665517Snate@binkert.org 3676143Snate@binkert.org# Save sticky variable settings back to current variables file 3685517Snate@binkert.orgglobal_vars.Save(global_vars_file, main) 3694762Snate@binkert.org 3705517Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 3715517Snate@binkert.org# look for sources etc. This list is exported as extras_dir_list. 3726143Snate@binkert.orgbase_dir = main.srcdir.abspath 3736143Snate@binkert.orgif main['EXTRAS']: 3745517Snate@binkert.org extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3755517Snate@binkert.orgelse: 3765517Snate@binkert.org extras_dir_list = [] 3775517Snate@binkert.org 3785517Snate@binkert.orgExport('base_dir') 3795517Snate@binkert.orgExport('extras_dir_list') 3805517Snate@binkert.org 3815517Snate@binkert.org# the ext directory should be on the #includes path 3825517Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3835517Snate@binkert.org 3846143Snate@binkert.orgdef strip_build_path(path, env): 3855517Snate@binkert.org path = str(path) 3866654Snate@binkert.org variant_base = env['BUILDROOT'] + os.path.sep 3876654Snate@binkert.org if path.startswith(variant_base): 3886654Snate@binkert.org path = path[len(variant_base):] 3896654Snate@binkert.org elif path.startswith('build/'): 3906654Snate@binkert.org path = path[6:] 3916654Snate@binkert.org return path 3925517Snate@binkert.org 3935517Snate@binkert.org# Generate a string of the form: 3945517Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 3955517Snate@binkert.org# to print while building. 3965517Snate@binkert.orgclass Transform(object): 3974762Snate@binkert.org # all specific color settings should be here and nowhere else 3984762Snate@binkert.org tool_color = termcap.Normal 3994762Snate@binkert.org pfx_color = termcap.Yellow 4004762Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 4014762Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 4024762Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 4037675Snate@binkert.org 4044762Snate@binkert.org def __init__(self, tool, max_sources=99): 4054762Snate@binkert.org self.format = self.tool_color + (" [%8s] " % tool) \ 4064762Snate@binkert.org + self.pfx_color + "%s" \ 4074762Snate@binkert.org + self.srcs_color + "%s" \ 4084382Sbinkertn@umich.edu + self.arrow_color + " -> " \ 4094382Sbinkertn@umich.edu + self.tgts_color + "%s" \ 4105517Snate@binkert.org + termcap.Normal 4116654Snate@binkert.org self.max_sources = max_sources 4125517Snate@binkert.org 4135798Snate@binkert.org def __call__(self, target, source, env, for_signature=None): 4146654Snate@binkert.org # truncate source list according to max_sources param 4157673Snate@binkert.org source = source[0:self.max_sources] 4166654Snate@binkert.org def strip(f): 4176654Snate@binkert.org return strip_build_path(str(f), env) 4186654Snate@binkert.org if len(source) > 0: 4196654Snate@binkert.org srcs = map(strip, source) 4206654Snate@binkert.org else: 4216654Snate@binkert.org srcs = [''] 4226654Snate@binkert.org tgts = map(strip, target) 4236654Snate@binkert.org # surprisingly, os.path.commonprefix is a dumb char-by-char string 4246669Snate@binkert.org # operation that has nothing to do with paths. 4256669Snate@binkert.org com_pfx = os.path.commonprefix(srcs + tgts) 4266669Snate@binkert.org com_pfx_len = len(com_pfx) 4276669Snate@binkert.org if com_pfx: 4286669Snate@binkert.org # do some cleanup and sanity checking on common prefix 4296669Snate@binkert.org if com_pfx[-1] == ".": 4306654Snate@binkert.org # prefix matches all but file extension: ok 4317673Snate@binkert.org # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4325517Snate@binkert.org com_pfx = com_pfx[0:-1] 4335863Snate@binkert.org elif com_pfx[-1] == "/": 4345798Snate@binkert.org # common prefix is directory path: OK 4357756SAli.Saidi@ARM.com pass 4367756SAli.Saidi@ARM.com else: 4375798Snate@binkert.org src0_len = len(srcs[0]) 4385798Snate@binkert.org tgt0_len = len(tgts[0]) 4395517Snate@binkert.org if src0_len == com_pfx_len: 4405517Snate@binkert.org # source is a substring of target, OK 4417673Snate@binkert.org pass 4425517Snate@binkert.org elif tgt0_len == com_pfx_len: 4435517Snate@binkert.org # target is a substring of source, need to back up to 4447673Snate@binkert.org # avoid empty string on RHS of arrow 4457673Snate@binkert.org sep_idx = com_pfx.rfind(".") 4465517Snate@binkert.org if sep_idx != -1: 4475798Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4485798Snate@binkert.org else: 4495798Snate@binkert.org com_pfx = '' 4507756SAli.Saidi@ARM.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4515798Snate@binkert.org # still splitting at file extension: ok 4525798Snate@binkert.org pass 4534762Snate@binkert.org else: 4544762Snate@binkert.org # probably a fluke; ignore it 4554762Snate@binkert.org com_pfx = '' 4564762Snate@binkert.org # recalculate length in case com_pfx was modified 4574762Snate@binkert.org com_pfx_len = len(com_pfx) 4585517Snate@binkert.org def fmt(files): 4595517Snate@binkert.org f = map(lambda s: s[com_pfx_len:], files) 4605517Snate@binkert.org return ', '.join(f) 4615517Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4625517Snate@binkert.org 4635517Snate@binkert.orgExport('Transform') 4647673Snate@binkert.org 4657673Snate@binkert.org 4667673Snate@binkert.orgif GetOption('verbose'): 4675517Snate@binkert.org def MakeAction(action, string, *args, **kwargs): 4685517Snate@binkert.org return Action(action, *args, **kwargs) 4695517Snate@binkert.orgelse: 4705517Snate@binkert.org MakeAction = Action 4715517Snate@binkert.org main['CCCOMSTR'] = Transform("CC") 4725517Snate@binkert.org main['CXXCOMSTR'] = Transform("CXX") 4735517Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 4747673Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4757677Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 4767673Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4777673Snate@binkert.org main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4785517Snate@binkert.org main['M4COMSTR'] = Transform("M4") 4795517Snate@binkert.org main['SHCCCOMSTR'] = Transform("SHCC") 4805517Snate@binkert.org main['SHCXXCOMSTR'] = Transform("SHCXX") 4815517Snate@binkert.orgExport('MakeAction') 4825517Snate@binkert.org 4835517Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4845517Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4857673Snate@binkert.org 4867673Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4877673Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4885517Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4895517Snate@binkert.orgmain['CLANG'] = CXX_V and CXX_V.find('clang') >= 0 4905517Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4915517Snate@binkert.org print 'Error: How can we have two at the same time?' 4925517Snate@binkert.org Exit(1) 4935517Snate@binkert.org 4945517Snate@binkert.org# Set up default C++ compiler flags 4957673Snate@binkert.orgif main['GCC']: 4967673Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 4977673Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4985517Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4997675Snate@binkert.org main.Append(CXXFLAGS=['-Wno-deprecated']) 5007675Snate@binkert.org # Read the GCC version to check for versions with bugs 5017675Snate@binkert.org # Note CCVERSION doesn't work here because it is run with the CC 5027675Snate@binkert.org # before we override it from the command line 5037675Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5047675Snate@binkert.org main['GCC_VERSION'] = gcc_version 5057675Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 5067675Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 5077677Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5087675Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 5097675Snate@binkert.orgelif main['ICC']: 5107675Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 5117675Snate@binkert.orgelif main['SUNCC']: 5127675Snate@binkert.org main.Append(CCFLAGS=['-Qoption ccfe']) 5137675Snate@binkert.org main.Append(CCFLAGS=['-features=gcc']) 5147675Snate@binkert.org main.Append(CCFLAGS=['-features=extensions']) 5157675Snate@binkert.org main.Append(CCFLAGS=['-library=stlport4']) 5167675Snate@binkert.org main.Append(CCFLAGS=['-xar']) 5174762Snate@binkert.org #main.Append(CCFLAGS=['-instances=semiexplicit']) 5184762Snate@binkert.orgelif main['CLANG']: 5196143Snate@binkert.org clang_version_re = re.compile(".* version (\d+\.\d+)") 5206143Snate@binkert.org clang_version_match = clang_version_re.match(CXX_version) 5216143Snate@binkert.org if (clang_version_match): 5224762Snate@binkert.org clang_version = clang_version_match.groups()[0] 5234762Snate@binkert.org if compareVersions(clang_version, "2.9") < 0: 5244762Snate@binkert.org print 'Error: clang version 2.9 or newer required.' 5257756SAli.Saidi@ARM.com print ' Installed version:', clang_version 5267756SAli.Saidi@ARM.com Exit(1) 5274762Snate@binkert.org else: 5284762Snate@binkert.org print 'Error: Unable to determine clang version.' 5294762Snate@binkert.org Exit(1) 5305463Snate@binkert.org 5315517Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 5327677Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 5335463Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5347756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-Wno-tautological-compare']) 5357756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-Wno-self-assign']) 5364762Snate@binkert.orgelse: 5377677Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 5384762Snate@binkert.org print ' Please fix SConstruct and src/SConscript and try again.' 5394762Snate@binkert.org Exit(1) 5406143Snate@binkert.org 5416143Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 5426143Snate@binkert.orgmain['YACCFLAGS'] = '-d' 5434762Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 5444762Snate@binkert.org 5457756SAli.Saidi@ARM.com# Do this after we save setting back, or else we'll tack on an 5467756SAli.Saidi@ARM.com# extra 'qdo' every time we run scons. 5474762Snate@binkert.orgif main['BATCH']: 5484762Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5494762Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5504762Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5517756SAli.Saidi@ARM.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5527756SAli.Saidi@ARM.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5534762Snate@binkert.org 5544762Snate@binkert.orgif sys.platform == 'cygwin': 5557677Snate@binkert.org # cygwin has some header file issues... 5567756SAli.Saidi@ARM.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 5577756SAli.Saidi@ARM.com 5587675Snate@binkert.org# Check for SWIG 5597677Snate@binkert.orgif not main.has_key('SWIG'): 5605517Snate@binkert.org print 'Error: SWIG utility not found.' 5617675Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 5627675Snate@binkert.org Exit(1) 5637675Snate@binkert.org 5647675Snate@binkert.org# Check for appropriate SWIG version 5657675Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split() 5667675Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 5677675Snate@binkert.orgif len(swig_version) < 3 or \ 5685517Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5697673Snate@binkert.org print 'Error determining SWIG version.' 5705517Snate@binkert.org Exit(1) 5717677Snate@binkert.org 5727675Snate@binkert.orgmin_swig_version = '1.3.28' 5737673Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 5747675Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 5757675Snate@binkert.org print ' Installed version:', swig_version[2] 5767675Snate@binkert.org Exit(1) 5777673Snate@binkert.org 5787675Snate@binkert.org# Set up SWIG flags & scanner 5795517Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5807675Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags) 5817675Snate@binkert.org 5827673Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 5837675Snate@binkert.org# stuff for some reason 5847675Snate@binkert.orgscanners = [] 5857677Snate@binkert.orgfor scanner in main['SCANNERS']: 5867675Snate@binkert.org skeys = scanner.skeys 5877675Snate@binkert.org if skeys == '.i': 5887675Snate@binkert.org continue 5895517Snate@binkert.org 5907675Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5915517Snate@binkert.org continue 5927673Snate@binkert.org 5935517Snate@binkert.org scanners.append(scanner) 5947675Snate@binkert.org 5957677Snate@binkert.org# add the new swig scanner that we like better 5967756SAli.Saidi@ARM.comfrom SCons.Scanner import ClassicCPP as CPPScanner 5977756SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5987675Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5997677Snate@binkert.org 6004762Snate@binkert.org# replace the scanners list that has what we want 6017674Snate@binkert.orgmain['SCANNERS'] = scanners 6027674Snate@binkert.org 6037674Snate@binkert.org# Add a custom Check function to the Configure context so that we can 6047674Snate@binkert.org# figure out if the compiler adds leading underscores to global 6057674Snate@binkert.org# variables. This is needed for the autogenerated asm files that we 6067674Snate@binkert.org# use for embedding the python code. 6077674Snate@binkert.orgdef CheckLeading(context): 6087674Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 6097674Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 6107674Snate@binkert.org # won't change the symbol at all. 6117674Snate@binkert.org # 2) Declare that variable. 6127674Snate@binkert.org # 3) Use the variable 6137674Snate@binkert.org # 6147674Snate@binkert.org # If the compiler prepends an underscore, this will successfully 6157674Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 6164762Snate@binkert.org # was defined by the asm statement. If the compiler does not 6176143Snate@binkert.org # prepend an underscore, this will not successfully link because 6186143Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 6197756SAli.Saidi@ARM.com # the code will be trying to use 'x' 6207756SAli.Saidi@ARM.com ret = context.TryLink(''' 6217674Snate@binkert.org asm(".globl _x; _x: .byte 0"); 6227756SAli.Saidi@ARM.com extern int x; 6237756SAli.Saidi@ARM.com int main() { return x; } 6247674Snate@binkert.org ''', extension=".c") 6254382Sbinkertn@umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6266229Snate@binkert.org context.Result(ret) 6276229Snate@binkert.org return ret 6286229Snate@binkert.org 6296229Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 6306229Snate@binkert.org# builds under a given build root run on the same host platform. 6316229Snate@binkert.orgconf = Configure(main, 6326229Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 6336229Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 6346229Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 6356229Snate@binkert.org 6366229Snate@binkert.org# Check for leading underscores. Don't really need to worry either 6376229Snate@binkert.org# way so don't need to check the return code. 6386229Snate@binkert.orgconf.CheckLeading() 6396229Snate@binkert.org 6406229Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6416229Snate@binkert.orgtry: 6426229Snate@binkert.org import platform 6436229Snate@binkert.org uname = platform.uname() 6446229Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6456229Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6466229Snate@binkert.org main.Append(CCFLAGS=['-arch', 'x86_64']) 6475192Ssaidi@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 6485517Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 6495517Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 6507673Snate@binkert.orgexcept: 6515517Snate@binkert.org pass 6526229Snate@binkert.org 6535799Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6547673Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 6557673Snate@binkert.org# present. Unfortuantely this Null object always returns false, 6565517Snate@binkert.org# breaking all our configuration checks. We replace it with our own 6575517Snate@binkert.org# more optimistic null object that returns True instead. 6587673Snate@binkert.orgif not conf: 6597673Snate@binkert.org def NullCheck(*args, **kwargs): 6607673Snate@binkert.org return True 6617673Snate@binkert.org 6625517Snate@binkert.org class NullConf: 6637673Snate@binkert.org def __init__(self, env): 6647673Snate@binkert.org self.env = env 6657673Snate@binkert.org def Finish(self): 6665517Snate@binkert.org return self.env 6675517Snate@binkert.org def __getattr__(self, mname): 6687673Snate@binkert.org return NullCheck 6697673Snate@binkert.org 6707673Snate@binkert.org conf = NullConf(main) 6717673Snate@binkert.org 6725517Snate@binkert.org# Find Python include and library directories for embedding the 6737673Snate@binkert.org# interpreter. For consistency, we will use the same Python 6747673Snate@binkert.org# installation used to run scons (and thus this script). If you want 6755517Snate@binkert.org# to link in an alternate version, see above for instructions on how 6767673Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 6777673Snate@binkert.orgfrom distutils import sysconfig 6785517Snate@binkert.org 6797673Snate@binkert.orgpy_getvar = sysconfig.get_config_var 6805517Snate@binkert.org 6815517Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False) 6827673Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6837673Snate@binkert.org 6847673Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 6857673Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6865517Snate@binkert.orgpy_includes = [ py_general_include ] 6877673Snate@binkert.orgif py_platform_include != py_general_include: 6887673Snate@binkert.org py_includes.append(py_platform_include) 6897673Snate@binkert.org 6905517Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 6917673Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6927673Snate@binkert.org# shared library in prefix/lib/. 6937673Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'): 6945517Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 6957673Snate@binkert.org 6965517Snate@binkert.orgpy_libs = [] 6975517Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6985517Snate@binkert.org if not lib.startswith('-l'): 6995517Snate@binkert.org # Python requires some special flags to link (e.g. -framework 7006229Snate@binkert.org # common on OS X systems), assume appending preserves order 7017673Snate@binkert.org main.Append(LINKFLAGS=[lib]) 7025517Snate@binkert.org else: 7035517Snate@binkert.org lib = lib[2:] 7047673Snate@binkert.org if lib not in py_libs: 7055517Snate@binkert.org py_libs.append(lib) 7065517Snate@binkert.orgpy_libs.append(py_version) 7075517Snate@binkert.org 7085517Snate@binkert.orgmain.Append(CPPPATH=py_includes) 7095517Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 7105517Snate@binkert.org 7115517Snate@binkert.org# Cache build files in the supplied directory. 7125517Snate@binkert.orgif main['M5_BUILD_CACHE']: 7135517Snate@binkert.org print 'Using build cache located at', main['M5_BUILD_CACHE'] 7147673Snate@binkert.org CacheDir(main['M5_BUILD_CACHE']) 7155517Snate@binkert.org 7167673Snate@binkert.org 7175517Snate@binkert.org# verify that this stuff works 7185517Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'): 7195517Snate@binkert.org print "Error: can't find Python.h header in", py_includes 7205517Snate@binkert.org Exit(1) 7217673Snate@binkert.org 7225517Snate@binkert.orgfor lib in py_libs: 7237673Snate@binkert.org if not conf.CheckLib(lib): 7245517Snate@binkert.org print "Error: can't find library %s required by python" % lib 7255517Snate@binkert.org Exit(1) 7267673Snate@binkert.org 7277673Snate@binkert.org# On Solaris you need to use libsocket for socket ops 7285517Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7297673Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7307673Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 7315517Snate@binkert.org Exit(1) 7327673Snate@binkert.org 7337673Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7347673Snate@binkert.org# added to the LIBS environment variable. 7357673Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7365517Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 7375517Snate@binkert.org 'and/or zlib.h header file.' 7385517Snate@binkert.org print ' Please install zlib and try again.' 7397673Snate@binkert.org Exit(1) 7407673Snate@binkert.org 7415517Snate@binkert.org# Check for librt. 7425517Snate@binkert.orghave_posix_clock = \ 7437673Snate@binkert.org conf.CheckLibWithHeader(None, 'time.h', 'C', 7447673Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') or \ 7457673Snate@binkert.org conf.CheckLibWithHeader('rt', 'time.h', 'C', 7467673Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') 7475517Snate@binkert.org 7485517Snate@binkert.orgif not have_posix_clock: 7495517Snate@binkert.org print "Can't find library for POSIX clocks." 7505517Snate@binkert.org 7517673Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 7527673Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>') 7535517Snate@binkert.orgif not have_fenv: 7547673Snate@binkert.org print "Warning: Header file <fenv.h> not found." 7557673Snate@binkert.org print " This host has no IEEE FP rounding mode control." 7567673Snate@binkert.org 7577673Snate@binkert.org###################################################################### 7587673Snate@binkert.org# 7595517Snate@binkert.org# Finish the configuration 7605517Snate@binkert.org# 7615517Snate@binkert.orgmain = conf.Finish() 7627673Snate@binkert.org 7637673Snate@binkert.org###################################################################### 7647673Snate@binkert.org# 7655517Snate@binkert.org# Collect all non-global variables 7665517Snate@binkert.org# 7677673Snate@binkert.org 7685517Snate@binkert.org# Define the universe of supported ISAs 7697673Snate@binkert.orgall_isa_list = [ ] 7707673Snate@binkert.orgExport('all_isa_list') 7715517Snate@binkert.org 7727673Snate@binkert.orgclass CpuModel(object): 7735517Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 7745517Snate@binkert.org know about a particular CPU model.''' 7755517Snate@binkert.org 7765517Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 7776229Snate@binkert.org dict = {} 7787673Snate@binkert.org list = [] 7795517Snate@binkert.org defaults = [] 7805517Snate@binkert.org 7817673Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 7825517Snate@binkert.org def __init__(self, name, filename, includes, strings, default=False): 7835517Snate@binkert.org self.name = name # name of model 7845517Snate@binkert.org self.filename = filename # filename for output exec code 7855517Snate@binkert.org self.includes = includes # include files needed in exec file 7865517Snate@binkert.org # The 'strings' dict holds all the per-CPU symbols we can 7875517Snate@binkert.org # substitute into templates etc. 7885517Snate@binkert.org self.strings = strings 7895517Snate@binkert.org 7905517Snate@binkert.org # This cpu is enabled by default 7915517Snate@binkert.org self.default = default 7925517Snate@binkert.org 7937673Snate@binkert.org # Add self to dict 7945517Snate@binkert.org if name in CpuModel.dict: 7955517Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 7965517Snate@binkert.org CpuModel.dict[name] = self 7977673Snate@binkert.org CpuModel.list.append(name) 7985517Snate@binkert.org 7995517Snate@binkert.orgExport('CpuModel') 8007673Snate@binkert.org 8015517Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 8025517Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 8035517Snate@binkert.org# value becomes sticky). 8047673Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS) 8057673Snate@binkert.orgExport('sticky_vars') 8067673Snate@binkert.org 8075517Snate@binkert.org# Sticky variables that should be exported 8085517Snate@binkert.orgexport_vars = [] 8097673Snate@binkert.orgExport('export_vars') 8105517Snate@binkert.org 8115517Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 8127673Snate@binkert.org# above variables 8135517Snate@binkert.orgif not GetOption('verbose'): 8147673Snate@binkert.org print "Reading SConsopts" 8157673Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 8165517Snate@binkert.org if not isdir(bdir): 8175517Snate@binkert.org print "Error: directory '%s' does not exist" % bdir 8185517Snate@binkert.org Exit(1) 8197673Snate@binkert.org for root, dirs, files in os.walk(bdir): 8205517Snate@binkert.org if 'SConsopts' in files: 8215517Snate@binkert.org if GetOption('verbose'): 8225517Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 8237673Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 8247673Snate@binkert.org 8255517Snate@binkert.orgall_isa_list.sort() 8265517Snate@binkert.org 8277673Snate@binkert.orgsticky_vars.AddVariables( 8285517Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8295517Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 8305517Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8315517Snate@binkert.org sorted(CpuModel.list)), 8325517Snate@binkert.org BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 8335517Snate@binkert.org BoolVariable('FORCE_FAST_ALLOC', 8345517Snate@binkert.org 'Enable fast object allocator, even for gem5.debug', False), 8355517Snate@binkert.org BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8365517Snate@binkert.org False), 8375517Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8387811Ssteve.reinhardt@amd.com False), 8395517Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 8405517Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 8417673Snate@binkert.org False), 8425517Snate@binkert.org BoolVariable('USE_SSE2', 8437673Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8445517Snate@binkert.org False), 8456143Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8467756SAli.Saidi@ARM.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8477756SAli.Saidi@ARM.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8485192Ssaidi@eecs.umich.edu ) 8495192Ssaidi@eecs.umich.edu 8507756SAli.Saidi@ARM.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 8517756SAli.Saidi@ARM.comexport_vars += ['USE_FENV', 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 8527756SAli.Saidi@ARM.com 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', 8537756SAli.Saidi@ARM.com 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ] 8545192Ssaidi@eecs.umich.edu 8555192Ssaidi@eecs.umich.edu################################################### 8567674Snate@binkert.org# 8575522Snate@binkert.org# Define a SCons builder for configuration flag headers. 8585522Snate@binkert.org# 8597674Snate@binkert.org################################################### 8607674Snate@binkert.org 8617674Snate@binkert.org# This function generates a config header file that #defines the 8627674Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 8637674Snate@binkert.org# operands are the name of the variable and a Value node containing the 8647674Snate@binkert.org# value of the variable. 8657674Snate@binkert.orgdef build_config_file(target, source, env): 8667674Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 8675522Snate@binkert.org f = file(str(target[0]), 'w') 8685522Snate@binkert.org print >> f, '#define', variable, value 8695522Snate@binkert.org f.close() 8705517Snate@binkert.org return None 8715522Snate@binkert.org 8725517Snate@binkert.org# Combine the two functions into a scons Action object. 8736143Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 8746727Ssteve.reinhardt@amd.com 8755522Snate@binkert.org# The emitter munges the source & target node lists to reflect what 8765522Snate@binkert.org# we're really doing. 8775522Snate@binkert.orgdef config_emitter(target, source, env): 8787674Snate@binkert.org # extract variable name from Builder arg 8795517Snate@binkert.org variable = str(target[0]) 8807673Snate@binkert.org # True target is config header file 8817673Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 8827674Snate@binkert.org val = env[variable] 8837673Snate@binkert.org if isinstance(val, bool): 8847674Snate@binkert.org # Force value to 0/1 8857674Snate@binkert.org val = int(val) 8867674Snate@binkert.org elif isinstance(val, str): 8877674Snate@binkert.org val = '"' + val + '"' 8887674Snate@binkert.org 8897674Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 8905522Snate@binkert.org return ([target], [Value(variable), Value(val)]) 8915522Snate@binkert.org 8927674Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 8937674Snate@binkert.org 8947674Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8957674Snate@binkert.org 8967673Snate@binkert.org# libelf build is shared across all configs in the build root. 8977674Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 8987674Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 8997674Snate@binkert.org 9007674Snate@binkert.org# gzstream build is shared across all configs in the build root. 9017674Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript', 9027674Snate@binkert.org variant_dir = joinpath(build_root, 'gzstream')) 9037674Snate@binkert.org 9047674Snate@binkert.org################################################### 9057811Ssteve.reinhardt@amd.com# 9067674Snate@binkert.org# This function is used to set up a directory with switching headers 9077673Snate@binkert.org# 9085522Snate@binkert.org################################################### 9096143Snate@binkert.org 9107756SAli.Saidi@ARM.commain['ALL_ISA_LIST'] = all_isa_list 9117756SAli.Saidi@ARM.comdef make_switching_dir(dname, switch_headers, env): 9127674Snate@binkert.org # Generate the header. target[0] is the full path of the output 9134382Sbinkertn@umich.edu # header to generate. 'source' is a dummy variable, since we get the 9144382Sbinkertn@umich.edu # list of ISAs from env['ALL_ISA_LIST']. 9154382Sbinkertn@umich.edu def gen_switch_hdr(target, source, env): 9164382Sbinkertn@umich.edu fname = str(target[0]) 9174382Sbinkertn@umich.edu f = open(fname, 'w') 9184382Sbinkertn@umich.edu isa = env['TARGET_ISA'].lower() 9194382Sbinkertn@umich.edu print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 9204382Sbinkertn@umich.edu f.close() 9214382Sbinkertn@umich.edu 9224382Sbinkertn@umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 9236143Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 924955SN/A # should get re-executed. 9252655Sstever@eecs.umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 9262655Sstever@eecs.umich.edu Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 9272655Sstever@eecs.umich.edu 9282655Sstever@eecs.umich.edu # Instantiate actions for each header 9292655Sstever@eecs.umich.edu for hdr in switch_headers: 9305601Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 9315601Snate@binkert.orgExport('make_switching_dir') 9325601Snate@binkert.org 9335601Snate@binkert.org################################################### 9345522Snate@binkert.org# 9355863Snate@binkert.org# Define build environments for selected configurations. 9365601Snate@binkert.org# 9375601Snate@binkert.org################################################### 9385601Snate@binkert.org 9395863Snate@binkert.orgfor variant_path in variant_paths: 9406143Snate@binkert.org print "Building in", variant_path 9415559Snate@binkert.org 9425559Snate@binkert.org # Make a copy of the build-root environment to use for this config. 9435559Snate@binkert.org env = main.Clone() 9445559Snate@binkert.org env['BUILDDIR'] = variant_path 9455601Snate@binkert.org 9466143Snate@binkert.org # variant_dir is the tail component of build path, and is used to 9476143Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 9486143Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 9496143Snate@binkert.org 9506143Snate@binkert.org # Set env variables according to the build directory config. 9516143Snate@binkert.org sticky_vars.files = [] 9526143Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 9536143Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 9546143Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 9556143Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 9566143Snate@binkert.org if isfile(current_vars_file): 9576143Snate@binkert.org sticky_vars.files.append(current_vars_file) 9586143Snate@binkert.org print "Using saved variables file %s" % current_vars_file 9596143Snate@binkert.org else: 9606143Snate@binkert.org # Build dir-specific variables file doesn't exist. 9616143Snate@binkert.org 9626143Snate@binkert.org # Make sure the directory is there so we can create it later 9636143Snate@binkert.org opt_dir = dirname(current_vars_file) 9646143Snate@binkert.org if not isdir(opt_dir): 9656143Snate@binkert.org mkdir(opt_dir) 9666143Snate@binkert.org 9676143Snate@binkert.org # Get default build variables from source tree. Variables are 9686143Snate@binkert.org # normally determined by name of $VARIANT_DIR, but can be 9696143Snate@binkert.org # overridden by '--default=' arg on command line. 9706143Snate@binkert.org default = GetOption('default') 9716143Snate@binkert.org opts_dir = joinpath(main.root.abspath, 'build_opts') 9726143Snate@binkert.org if default: 9736143Snate@binkert.org default_vars_files = [joinpath(build_root, 'variables', default), 9746143Snate@binkert.org joinpath(opts_dir, default)] 9756143Snate@binkert.org else: 9766143Snate@binkert.org default_vars_files = [joinpath(opts_dir, variant_dir)] 9776143Snate@binkert.org existing_files = filter(isfile, default_vars_files) 9786240Snate@binkert.org if existing_files: 9795554Snate@binkert.org default_vars_file = existing_files[0] 9805522Snate@binkert.org sticky_vars.files.append(default_vars_file) 9815522Snate@binkert.org print "Variables file %s not found,\n using defaults in %s" \ 9825797Snate@binkert.org % (current_vars_file, default_vars_file) 9835797Snate@binkert.org else: 9845522Snate@binkert.org print "Error: cannot find variables file %s or " \ 9855584Snate@binkert.org "default file(s) %s" \ 9866143Snate@binkert.org % (current_vars_file, ' or '.join(default_vars_files)) 9875862Snate@binkert.org Exit(1) 9885584Snate@binkert.org 9895601Snate@binkert.org # Apply current variable settings to env 9906143Snate@binkert.org sticky_vars.Update(env) 9916143Snate@binkert.org 9922655Sstever@eecs.umich.edu help_texts["local_vars"] += \ 9936143Snate@binkert.org "Build variables for %s:\n" % variant_dir \ 9946143Snate@binkert.org + sticky_vars.GenerateHelpText(env) 9956143Snate@binkert.org 9966143Snate@binkert.org # Process variable settings. 9976143Snate@binkert.org 9984007Ssaidi@eecs.umich.edu if not have_fenv and env['USE_FENV']: 9994596Sbinkertn@umich.edu print "Warning: <fenv.h> not available; " \ 10004007Ssaidi@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + "." 10014596Sbinkertn@umich.edu env['USE_FENV'] = False 10027756SAli.Saidi@ARM.com 10037756SAli.Saidi@ARM.com if not env['USE_FENV']: 10045522Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 10055601Snate@binkert.org print " FP results may deviate slightly from other platforms." 10065601Snate@binkert.org 10072655Sstever@eecs.umich.edu if env['EFENCE']: 1008955SN/A env.Append(LIBS=['efence']) 10093918Ssaidi@eecs.umich.edu 10103918Ssaidi@eecs.umich.edu # Save sticky variable settings back to current variables file 10113918Ssaidi@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 10123918Ssaidi@eecs.umich.edu 10133918Ssaidi@eecs.umich.edu if env['USE_SSE2']: 10143918Ssaidi@eecs.umich.edu env.Append(CCFLAGS=['-msse2']) 10153918Ssaidi@eecs.umich.edu 10163918Ssaidi@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 10173918Ssaidi@eecs.umich.edu # to the configured variables. It returns a list of environments, 10183918Ssaidi@eecs.umich.edu # one for each variant build (debug, opt, etc.) 10193918Ssaidi@eecs.umich.edu envList = SConscript('src/SConscript', variant_dir = variant_path, 10203918Ssaidi@eecs.umich.edu exports = 'env') 10213918Ssaidi@eecs.umich.edu 10223918Ssaidi@eecs.umich.edu # Set up the regression tests for each build. 10233940Ssaidi@eecs.umich.edu for e in envList: 10243940Ssaidi@eecs.umich.edu SConscript('tests/SConscript', 10253940Ssaidi@eecs.umich.edu variant_dir = joinpath(variant_path, 'tests', e.Label), 10263942Ssaidi@eecs.umich.edu exports = { 'env' : e }, duplicate = False) 10273940Ssaidi@eecs.umich.edu 10283515Ssaidi@eecs.umich.edu# base help text 10293918Ssaidi@eecs.umich.eduHelp(''' 10304762Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)] 10313515Ssaidi@eecs.umich.edu 10322655Sstever@eecs.umich.eduExtra scons options: 10333918Ssaidi@eecs.umich.edu%(options)s 10343619Sbinkertn@umich.edu 1035955SN/AGlobal build variables: 1036955SN/A%(global_vars)s 10372655Sstever@eecs.umich.edu 10383918Ssaidi@eecs.umich.edu%(local_vars)s 10393619Sbinkertn@umich.edu''' % help_texts) 1040955SN/A