SConstruct revision 8483
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 ('m5'), 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_FS/m5.opt' for 41955SN/A# the optimized full-system version). 424381Sbinkertn@umich.edu# 434381Sbinkertn@umich.edu# You can build M5 in a different directory as long as there is a 448334Snate@binkert.org# '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>/m5 ; scons build/ALPHA_FS/m5.debug 535517Snate@binkert.org# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 548614Sgblack@eecs.umich.edu# 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. 598233Snate@binkert.org# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 608233Snate@binkert.org# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 618233Snate@binkert.org# 628233Snate@binkert.org# You can use 'scons -H' to print scons options. If you're in this 638233Snate@binkert.org# 'm5' directory (or use -u or -C to tell scons where to find this 648334Snate@binkert.org# file), you can use 'scons -h' to print all the M5-specific build 658334Snate@binkert.org# options as well. 6610453SAndrew.Bardsley@arm.com# 6710453SAndrew.Bardsley@arm.com################################################### 688233Snate@binkert.org 698233Snate@binkert.org# Check for recent-enough Python and SCons versions. 708233Snate@binkert.orgtry: 718233Snate@binkert.org # Really old versions of scons only take two options for the 728233Snate@binkert.org # function, so check once without the revision and once with the 738233Snate@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 758233Snate@binkert.org EnsureSConsVersion(0, 98) 768233Snate@binkert.org EnsureSConsVersion(0, 98, 1) 778233Snate@binkert.orgexcept SystemExit, e: 786143Snate@binkert.org print """ 796143Snate@binkert.orgFor more details, see: 806143Snate@binkert.org http://m5sim.org/wiki/index.php/Compiling_M5 816143Snate@binkert.org""" 828233Snate@binkert.org raise 838233Snate@binkert.org 848233Snate@binkert.org# We ensure the python version early because we have stuff that 856143Snate@binkert.org# requires python 2.4 868233Snate@binkert.orgtry: 878233Snate@binkert.org EnsurePythonVersion(2, 4) 888233Snate@binkert.orgexcept SystemExit, e: 898233Snate@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 934762Snate@binkert.orgon the scons script. 946143Snate@binkert.org 958233Snate@binkert.orgFor more details, see: 968233Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 978233Snate@binkert.org""" 988233Snate@binkert.org raise 998233Snate@binkert.org 1006143Snate@binkert.org# Global Python includes 1018233Snate@binkert.orgimport os 1028233Snate@binkert.orgimport re 1038233Snate@binkert.orgimport subprocess 1048233Snate@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 1147065Snate@binkert.org 1156143Snate@binkert.orgextra_python_paths = [ 1168233Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1178233Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1188233Snate@binkert.org ] 1198233Snate@binkert.org 1208233Snate@binkert.orgsys.path[1:1] = extra_python_paths 1218233Snate@binkert.org 1228233Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1238233Snate@binkert.org 1248233Snate@binkert.orghelp_texts = { 1258233Snate@binkert.org "options" : "", 1268233Snate@binkert.org "global_vars" : "", 1278233Snate@binkert.org "local_vars" : "" 1288233Snate@binkert.org} 1298233Snate@binkert.org 1308233Snate@binkert.orgExport("help_texts") 1318233Snate@binkert.org 1328233Snate@binkert.orgdef AddM5Option(*args, **kwargs): 1338233Snate@binkert.org col_width = 30 1348233Snate@binkert.org 1358233Snate@binkert.org help = " " + ", ".join(args) 1368233Snate@binkert.org if "help" in kwargs: 1378233Snate@binkert.org length = len(help) 1388233Snate@binkert.org if length >= col_width: 1398233Snate@binkert.org help += "\n" + " " * col_width 1408233Snate@binkert.org else: 1418233Snate@binkert.org help += " " * (col_width - length) 1428233Snate@binkert.org help += kwargs["help"] 1438233Snate@binkert.org help_texts["options"] += help + "\n" 1448233Snate@binkert.org 1458233Snate@binkert.org AddOption(*args, **kwargs) 1468233Snate@binkert.org 1476143Snate@binkert.orgAddM5Option('--colors', dest='use_colors', action='store_true', 1486143Snate@binkert.org help="Add color to abbreviated scons output") 1496143Snate@binkert.orgAddM5Option('--no-colors', dest='use_colors', action='store_false', 1506143Snate@binkert.org help="Don't add color to abbreviated scons output") 1516143Snate@binkert.orgAddM5Option('--default', dest='default', type='string', action='store', 1526143Snate@binkert.org help='Override which build_opts file to use for defaults') 1539982Satgutier@umich.eduAddM5Option('--ignore-style', dest='ignore_style', action='store_true', 15410196SCurtis.Dunham@arm.com help='Disable style checking hooks') 15510196SCurtis.Dunham@arm.comAddM5Option('--update-ref', dest='update_ref', action='store_true', 15610196SCurtis.Dunham@arm.com help='Update test reference outputs') 15710196SCurtis.Dunham@arm.comAddM5Option('--verbose', dest='verbose', action='store_true', 15810196SCurtis.Dunham@arm.com help='Print full tool command lines') 15910196SCurtis.Dunham@arm.com 16010196SCurtis.Dunham@arm.comuse_colors = GetOption('use_colors') 16110196SCurtis.Dunham@arm.comif use_colors: 1626143Snate@binkert.org from m5.util.terminal import termcap 1636143Snate@binkert.orgelif use_colors is None: 1648945Ssteve.reinhardt@amd.com # option unspecified; default behavior is to use colors iff isatty 1658233Snate@binkert.org from m5.util.terminal import tty_termcap as termcap 1668233Snate@binkert.orgelse: 1676143Snate@binkert.org from m5.util.terminal import no_termcap as termcap 1688945Ssteve.reinhardt@amd.com 1696143Snate@binkert.org######################################################################## 1706143Snate@binkert.org# 1716143Snate@binkert.org# Set up the main build environment. 1726143Snate@binkert.org# 1735522Snate@binkert.org######################################################################## 1746143Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1756143Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1766143Snate@binkert.org 1779982Satgutier@umich.eduuse_env = {} 1788233Snate@binkert.orgfor key,val in os.environ.iteritems(): 1798233Snate@binkert.org if key in use_vars or key.startswith("M5"): 1808233Snate@binkert.org use_env[key] = val 1816143Snate@binkert.org 1826143Snate@binkert.orgmain = Environment(ENV=use_env) 1836143Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1846143Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1855522Snate@binkert.org 1865522Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 1875522Snate@binkert.org# as well 1885522Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 1895604Snate@binkert.org 1905604Snate@binkert.org######################################################################## 1916143Snate@binkert.org# 1926143Snate@binkert.org# Mercurial Stuff. 1934762Snate@binkert.org# 1944762Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some 1956143Snate@binkert.org# extra things. 1966727Ssteve.reinhardt@amd.com# 1976727Ssteve.reinhardt@amd.com######################################################################## 1986727Ssteve.reinhardt@amd.com 1994762Snate@binkert.orghgdir = main.root.Dir(".hg") 2006143Snate@binkert.org 2016143Snate@binkert.orgmercurial_style_message = """ 2026143Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2036143Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2046727Ssteve.reinhardt@amd.comscript will now install the hook in your .hg/hgrc file. 2056143Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2067674Snate@binkert.org 2077674Snate@binkert.orgmercurial_style_hook = """ 2085604Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2096143Snate@binkert.org# to provide the gem5 style-checking hooks 2106143Snate@binkert.org[extensions] 2116143Snate@binkert.orgstyle = %s/util/style.py 2124762Snate@binkert.org 2136143Snate@binkert.org[hooks] 2144762Snate@binkert.orgpretxncommit.style = python:style.check_style 2154762Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2164762Snate@binkert.org# End of SConstruct additions 2176143Snate@binkert.org 2186143Snate@binkert.org""" % (main.root.abspath) 2194762Snate@binkert.org 2208233Snate@binkert.orgmercurial_lib_not_found = """ 2218233Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2228233Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2238233Snate@binkert.orghook. It is important. 2246143Snate@binkert.org""" 2256143Snate@binkert.org 2264762Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2276143Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to 2284762Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2296143Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2304762Snate@binkert.org style_hook = True 2316143Snate@binkert.org try: 2328233Snate@binkert.org from mercurial import ui 2338233Snate@binkert.org ui = ui.ui() 23410453SAndrew.Bardsley@arm.com ui.readconfig(hgdir.File('hgrc').abspath) 2356143Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2366143Snate@binkert.org ui.config('hooks', 'pre-qrefresh.style', None) 2376143Snate@binkert.org except ImportError: 2386143Snate@binkert.org print mercurial_lib_not_found 2396143Snate@binkert.org 2406143Snate@binkert.org if not style_hook: 2416143Snate@binkert.org print mercurial_style_message, 2426143Snate@binkert.org # continue unless user does ctrl-c/ctrl-d etc. 24310453SAndrew.Bardsley@arm.com try: 24410453SAndrew.Bardsley@arm.com raw_input() 245955SN/A except: 2469396Sandreas.hansson@arm.com print "Input exception, exiting scons.\n" 2479396Sandreas.hansson@arm.com sys.exit(1) 2489396Sandreas.hansson@arm.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2499396Sandreas.hansson@arm.com print "Adding style hook to", hgrc_path, "\n" 2509396Sandreas.hansson@arm.com try: 2519396Sandreas.hansson@arm.com hgrc = open(hgrc_path, 'a') 2529396Sandreas.hansson@arm.com hgrc.write(mercurial_style_hook) 2539396Sandreas.hansson@arm.com hgrc.close() 2549396Sandreas.hansson@arm.com except: 2559396Sandreas.hansson@arm.com print "Error updating", hgrc_path 2569396Sandreas.hansson@arm.com sys.exit(1) 2579396Sandreas.hansson@arm.com 2589396Sandreas.hansson@arm.com 2599930Sandreas.hansson@arm.com################################################### 2609930Sandreas.hansson@arm.com# 2619396Sandreas.hansson@arm.com# Figure out which configurations to set up based on the path(s) of 2628235Snate@binkert.org# the target(s). 2638235Snate@binkert.org# 2646143Snate@binkert.org################################################### 2658235Snate@binkert.org 2669003SAli.Saidi@ARM.com# Find default configuration & binary. 2678235Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2688235Snate@binkert.org 2698235Snate@binkert.org# helper function: find last occurrence of element in list 2708235Snate@binkert.orgdef rfind(l, elt, offs = -1): 2718235Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2728235Snate@binkert.org if l[i] == elt: 2738235Snate@binkert.org return i 2748235Snate@binkert.org raise ValueError, "element not found" 2758235Snate@binkert.org 2768235Snate@binkert.org# Take a list of paths (or SCons Nodes) and return a list with all 2778235Snate@binkert.org# paths made absolute and ~-expanded. Paths will be interpreted 2788235Snate@binkert.org# relative to the launch directory unless a different root is provided 2798235Snate@binkert.orgdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2808235Snate@binkert.org return [abspath(joinpath(root, expanduser(str(p)))) 2819003SAli.Saidi@ARM.com for p in path_list] 2828235Snate@binkert.org 2835584Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2844382Sbinkertn@umich.edu# directory below this will determine the build parameters. For 2854202Sbinkertn@umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2864382Sbinkertn@umich.edu# recognize that ALPHA_SE specifies the configuration because it 2874382Sbinkertn@umich.edu# follow 'build' in the build path. 2884382Sbinkertn@umich.edu 2899396Sandreas.hansson@arm.com# The funky assignment to "[:]" is needed to replace the list contents 2905584Snate@binkert.org# in place rather than reassign the symbol to a new list, which 2914382Sbinkertn@umich.edu# doesn't work (obviously!). 2924382Sbinkertn@umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2934382Sbinkertn@umich.edu 2948232Snate@binkert.org# Generate a list of the unique build roots and configs that the 2955192Ssaidi@eecs.umich.edu# collected targets reference. 2968232Snate@binkert.orgvariant_paths = [] 2978232Snate@binkert.orgbuild_root = None 2988232Snate@binkert.orgfor t in BUILD_TARGETS: 2995192Ssaidi@eecs.umich.edu path_dirs = t.split('/') 3008232Snate@binkert.org try: 3015192Ssaidi@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 3025799Snate@binkert.org except: 3038232Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 3045192Ssaidi@eecs.umich.edu Exit(1) 3055192Ssaidi@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3065192Ssaidi@eecs.umich.edu if not build_root: 3078232Snate@binkert.org build_root = this_build_root 3085192Ssaidi@eecs.umich.edu else: 3098232Snate@binkert.org if this_build_root != build_root: 3105192Ssaidi@eecs.umich.edu print "Error: build targets not under same build root\n"\ 3115192Ssaidi@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 3125192Ssaidi@eecs.umich.edu Exit(1) 3135192Ssaidi@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3144382Sbinkertn@umich.edu if variant_path not in variant_paths: 3154382Sbinkertn@umich.edu variant_paths.append(variant_path) 3164382Sbinkertn@umich.edu 3172667Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3182667Sstever@eecs.umich.eduif not isdir(build_root): 3192667Sstever@eecs.umich.edu mkdir(build_root) 3202667Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 3212667Sstever@eecs.umich.edu 3222667Sstever@eecs.umich.eduExport('main') 3235742Snate@binkert.org 3245742Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 3255742Snate@binkert.org 3265793Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 3278334Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 3285793Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 3295793Snate@binkert.org# (soft) links work better. 3305793Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3314382Sbinkertn@umich.edu 3324762Snate@binkert.org# 3335344Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3344382Sbinkertn@umich.edu# tree (not specific to a particular build like ALPHA_SE) 3355341Sstever@gmail.com# 3365742Snate@binkert.org 3375742Snate@binkert.orgglobal_vars_file = joinpath(build_root, 'variables.global') 3385742Snate@binkert.org 3395742Snate@binkert.orgglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3405742Snate@binkert.org 3414762Snate@binkert.orgglobal_vars.AddVariables( 3425742Snate@binkert.org ('CC', 'C compiler', environ.get('CC', main['CC'])), 3435742Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3447722Sgblack@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3455742Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3465742Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3475742Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3489930Sandreas.hansson@arm.com ) 3499930Sandreas.hansson@arm.com 3509930Sandreas.hansson@arm.com# Update main environment with values from ARGUMENTS & global_vars_file 3519930Sandreas.hansson@arm.comglobal_vars.Update(main) 3529930Sandreas.hansson@arm.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3535742Snate@binkert.org 3548242Sbradley.danofsky@amd.com# Save sticky variable settings back to current variables file 3558242Sbradley.danofsky@amd.comglobal_vars.Save(global_vars_file, main) 3568242Sbradley.danofsky@amd.com 3578242Sbradley.danofsky@amd.com# Parse EXTRAS variable to build list of all directories where we're 3585341Sstever@gmail.com# look for sources etc. This list is exported as extras_dir_list. 3595742Snate@binkert.orgbase_dir = main.srcdir.abspath 3607722Sgblack@eecs.umich.eduif main['EXTRAS']: 3614773Snate@binkert.org extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3626108Snate@binkert.orgelse: 3631858SN/A extras_dir_list = [] 3641085SN/A 3656658Snate@binkert.orgExport('base_dir') 3666658Snate@binkert.orgExport('extras_dir_list') 3677673Snate@binkert.org 3686658Snate@binkert.org# the ext directory should be on the #includes path 3696658Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3706658Snate@binkert.org 3716658Snate@binkert.orgdef strip_build_path(path, env): 3726658Snate@binkert.org path = str(path) 3736658Snate@binkert.org variant_base = env['BUILDROOT'] + os.path.sep 3746658Snate@binkert.org if path.startswith(variant_base): 3757673Snate@binkert.org path = path[len(variant_base):] 3767673Snate@binkert.org elif path.startswith('build/'): 3777673Snate@binkert.org path = path[6:] 3787673Snate@binkert.org return path 3797673Snate@binkert.org 3807673Snate@binkert.org# Generate a string of the form: 3817673Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 3826658Snate@binkert.org# to print while building. 3837673Snate@binkert.orgclass Transform(object): 3847673Snate@binkert.org # all specific color settings should be here and nowhere else 3857673Snate@binkert.org tool_color = termcap.Normal 3867673Snate@binkert.org pfx_color = termcap.Yellow 3877673Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 3887673Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 3899048SAli.Saidi@ARM.com tgts_color = termcap.Yellow + termcap.Bold 3907673Snate@binkert.org 3917673Snate@binkert.org def __init__(self, tool, max_sources=99): 3927673Snate@binkert.org self.format = self.tool_color + (" [%8s] " % tool) \ 3937673Snate@binkert.org + self.pfx_color + "%s" \ 3946658Snate@binkert.org + self.srcs_color + "%s" \ 3957756SAli.Saidi@ARM.com + self.arrow_color + " -> " \ 3967816Ssteve.reinhardt@amd.com + self.tgts_color + "%s" \ 3976658Snate@binkert.org + termcap.Normal 3984382Sbinkertn@umich.edu self.max_sources = max_sources 3994382Sbinkertn@umich.edu 4004762Snate@binkert.org def __call__(self, target, source, env, for_signature=None): 4014762Snate@binkert.org # truncate source list according to max_sources param 4024762Snate@binkert.org source = source[0:self.max_sources] 4036654Snate@binkert.org def strip(f): 4046654Snate@binkert.org return strip_build_path(str(f), env) 4055517Snate@binkert.org if len(source) > 0: 4065517Snate@binkert.org srcs = map(strip, source) 4075517Snate@binkert.org else: 4085517Snate@binkert.org srcs = [''] 4095517Snate@binkert.org tgts = map(strip, target) 4105517Snate@binkert.org # surprisingly, os.path.commonprefix is a dumb char-by-char string 4115517Snate@binkert.org # operation that has nothing to do with paths. 4125517Snate@binkert.org com_pfx = os.path.commonprefix(srcs + tgts) 4135517Snate@binkert.org com_pfx_len = len(com_pfx) 4145517Snate@binkert.org if com_pfx: 4155517Snate@binkert.org # do some cleanup and sanity checking on common prefix 4165517Snate@binkert.org if com_pfx[-1] == ".": 4175517Snate@binkert.org # prefix matches all but file extension: ok 4185517Snate@binkert.org # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4195517Snate@binkert.org com_pfx = com_pfx[0:-1] 4205517Snate@binkert.org elif com_pfx[-1] == "/": 4215517Snate@binkert.org # common prefix is directory path: OK 4226654Snate@binkert.org pass 4235517Snate@binkert.org else: 4245517Snate@binkert.org src0_len = len(srcs[0]) 4255517Snate@binkert.org tgt0_len = len(tgts[0]) 4265517Snate@binkert.org if src0_len == com_pfx_len: 4275517Snate@binkert.org # source is a substring of target, OK 4285517Snate@binkert.org pass 4295517Snate@binkert.org elif tgt0_len == com_pfx_len: 4305517Snate@binkert.org # target is a substring of source, need to back up to 4316143Snate@binkert.org # avoid empty string on RHS of arrow 4326654Snate@binkert.org sep_idx = com_pfx.rfind(".") 4335517Snate@binkert.org if sep_idx != -1: 4345517Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4355517Snate@binkert.org else: 4365517Snate@binkert.org com_pfx = '' 4375517Snate@binkert.org elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4385517Snate@binkert.org # still splitting at file extension: ok 4395517Snate@binkert.org pass 4405517Snate@binkert.org else: 4415517Snate@binkert.org # probably a fluke; ignore it 4425517Snate@binkert.org com_pfx = '' 4435517Snate@binkert.org # recalculate length in case com_pfx was modified 4445517Snate@binkert.org com_pfx_len = len(com_pfx) 4455517Snate@binkert.org def fmt(files): 4465517Snate@binkert.org f = map(lambda s: s[com_pfx_len:], files) 4476654Snate@binkert.org return ', '.join(f) 4486654Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4495517Snate@binkert.org 4505517Snate@binkert.orgExport('Transform') 4516143Snate@binkert.org 4526143Snate@binkert.org 4536143Snate@binkert.orgif GetOption('verbose'): 4546727Ssteve.reinhardt@amd.com def MakeAction(action, string, *args, **kwargs): 4555517Snate@binkert.org return Action(action, *args, **kwargs) 4566727Ssteve.reinhardt@amd.comelse: 4575517Snate@binkert.org MakeAction = Action 4585517Snate@binkert.org main['CCCOMSTR'] = Transform("CC") 4595517Snate@binkert.org main['CXXCOMSTR'] = Transform("CXX") 4606654Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 4616654Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4627673Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 4636654Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4646654Snate@binkert.org main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4656654Snate@binkert.org main['M4COMSTR'] = Transform("M4") 4666654Snate@binkert.org main['SHCCCOMSTR'] = Transform("SHCC") 4675517Snate@binkert.org main['SHCXXCOMSTR'] = Transform("SHCXX") 4685517Snate@binkert.orgExport('MakeAction') 4695517Snate@binkert.org 4706143Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4715517Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4724762Snate@binkert.org 4735517Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4745517Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4756143Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4766143Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4775517Snate@binkert.org print 'Error: How can we have two at the same time?' 4785517Snate@binkert.org Exit(1) 4795517Snate@binkert.org 4805517Snate@binkert.org# Set up default C++ compiler flags 4815517Snate@binkert.orgif main['GCC']: 4825517Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 4835517Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4845517Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4855517Snate@binkert.org main.Append(CXXFLAGS=['-Wno-deprecated']) 4869338SAndreas.Sandberg@arm.com # Read the GCC version to check for versions with bugs 4879338SAndreas.Sandberg@arm.com # Note CCVERSION doesn't work here because it is run with the CC 4889338SAndreas.Sandberg@arm.com # before we override it from the command line 4899338SAndreas.Sandberg@arm.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4909338SAndreas.Sandberg@arm.com if not compareVersions(gcc_version, '4.4.1') or \ 4919338SAndreas.Sandberg@arm.com not compareVersions(gcc_version, '4.4.2'): 4928596Ssteve.reinhardt@amd.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4938596Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 4948596Ssteve.reinhardt@amd.comelif main['ICC']: 4958596Ssteve.reinhardt@amd.com pass #Fix me... add warning flags once we clean up icc warnings 4968596Ssteve.reinhardt@amd.comelif main['SUNCC']: 4978596Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Qoption ccfe']) 4988596Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-features=gcc']) 4996143Snate@binkert.org main.Append(CCFLAGS=['-features=extensions']) 5005517Snate@binkert.org main.Append(CCFLAGS=['-library=stlport4']) 5016654Snate@binkert.org main.Append(CCFLAGS=['-xar']) 5026654Snate@binkert.org #main.Append(CCFLAGS=['-instances=semiexplicit']) 5036654Snate@binkert.orgelse: 5046654Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 5056654Snate@binkert.org print ' Please fix SConstruct and src/SConscript and try again.' 5066654Snate@binkert.org Exit(1) 5075517Snate@binkert.org 5085517Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 5095517Snate@binkert.orgmain['YACCFLAGS'] = '-d' 5108596Ssteve.reinhardt@amd.commain['YACCHXXFILESUFFIX'] = '.hh' 5118596Ssteve.reinhardt@amd.com 5124762Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 5134762Snate@binkert.org# extra 'qdo' every time we run scons. 5144762Snate@binkert.orgif main['BATCH']: 5154762Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5164762Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5174762Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5187675Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5194762Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5204762Snate@binkert.org 5214762Snate@binkert.orgif sys.platform == 'cygwin': 5224762Snate@binkert.org # cygwin has some header file issues... 5234382Sbinkertn@umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5244382Sbinkertn@umich.edu 5255517Snate@binkert.org# Check for SWIG 5266654Snate@binkert.orgif not main.has_key('SWIG'): 5275517Snate@binkert.org print 'Error: SWIG utility not found.' 5288126Sgblack@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 5296654Snate@binkert.org Exit(1) 5307673Snate@binkert.org 5316654Snate@binkert.org# Check for appropriate SWIG version 5326654Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split() 5336654Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 5346654Snate@binkert.orgif len(swig_version) < 3 or \ 5356654Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5366654Snate@binkert.org print 'Error determining SWIG version.' 5376654Snate@binkert.org Exit(1) 5386669Snate@binkert.org 5396669Snate@binkert.orgmin_swig_version = '1.3.28' 5406669Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 5416669Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 5426669Snate@binkert.org print ' Installed version:', swig_version[2] 5436669Snate@binkert.org Exit(1) 5446654Snate@binkert.org 5457673Snate@binkert.org# Set up SWIG flags & scanner 5465517Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5478126Sgblack@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5485798Snate@binkert.org 5497756SAli.Saidi@ARM.com# filter out all existing swig scanners, they mess up the dependency 5507816Ssteve.reinhardt@amd.com# stuff for some reason 5515798Snate@binkert.orgscanners = [] 5525798Snate@binkert.orgfor scanner in main['SCANNERS']: 5535517Snate@binkert.org skeys = scanner.skeys 5545517Snate@binkert.org if skeys == '.i': 5557673Snate@binkert.org continue 5565517Snate@binkert.org 5575517Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5587673Snate@binkert.org continue 5597673Snate@binkert.org 5605517Snate@binkert.org scanners.append(scanner) 5615798Snate@binkert.org 5625798Snate@binkert.org# add the new swig scanner that we like better 5638333Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 5647816Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5655798Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5665798Snate@binkert.org 5674762Snate@binkert.org# replace the scanners list that has what we want 5684762Snate@binkert.orgmain['SCANNERS'] = scanners 5694762Snate@binkert.org 5704762Snate@binkert.org# Add a custom Check function to the Configure context so that we can 5714762Snate@binkert.org# figure out if the compiler adds leading underscores to global 5728596Ssteve.reinhardt@amd.com# variables. This is needed for the autogenerated asm files that we 5735517Snate@binkert.org# use for embedding the python code. 5745517Snate@binkert.orgdef CheckLeading(context): 5755517Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 5765517Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 5775517Snate@binkert.org # won't change the symbol at all. 5787673Snate@binkert.org # 2) Declare that variable. 5798596Ssteve.reinhardt@amd.com # 3) Use the variable 5807673Snate@binkert.org # 5815517Snate@binkert.org # If the compiler prepends an underscore, this will successfully 5828596Ssteve.reinhardt@amd.com # link because the external symbol 'x' will be called '_x' which 5835517Snate@binkert.org # was defined by the asm statement. If the compiler does not 5845517Snate@binkert.org # prepend an underscore, this will not successfully link because 5855517Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 5868596Ssteve.reinhardt@amd.com # the code will be trying to use 'x' 5875517Snate@binkert.org ret = context.TryLink(''' 5887673Snate@binkert.org asm(".globl _x; _x: .byte 0"); 5897673Snate@binkert.org extern int x; 5907673Snate@binkert.org int main() { return x; } 5915517Snate@binkert.org ''', extension=".c") 5925517Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 5935517Snate@binkert.org context.Result(ret) 5945517Snate@binkert.org return ret 5955517Snate@binkert.org 5965517Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 5975517Snate@binkert.org# builds under a given build root run on the same host platform. 5987673Snate@binkert.orgconf = Configure(main, 5997673Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 6007673Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 6015517Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 6028596Ssteve.reinhardt@amd.com 6035517Snate@binkert.org# Check for leading underscores. Don't really need to worry either 6045517Snate@binkert.org# way so don't need to check the return code. 6055517Snate@binkert.orgconf.CheckLeading() 6065517Snate@binkert.org 6075517Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6087673Snate@binkert.orgtry: 6097673Snate@binkert.org import platform 6107673Snate@binkert.org uname = platform.uname() 6115517Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6128596Ssteve.reinhardt@amd.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6137675Snate@binkert.org main.Append(CCFLAGS=['-arch', 'x86_64']) 6147675Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 6157675Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 6167675Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 6177675Snate@binkert.orgexcept: 6187675Snate@binkert.org pass 6198596Ssteve.reinhardt@amd.com 6207675Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6217675Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 6228596Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 6238596Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 6248596Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 6258596Ssteve.reinhardt@amd.comif not conf: 6268596Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 6278596Ssteve.reinhardt@amd.com return True 6288596Ssteve.reinhardt@amd.com 6298596Ssteve.reinhardt@amd.com class NullConf: 6308596Ssteve.reinhardt@amd.com def __init__(self, env): 6314762Snate@binkert.org self.env = env 6326143Snate@binkert.org def Finish(self): 6336143Snate@binkert.org return self.env 6346143Snate@binkert.org def __getattr__(self, mname): 6354762Snate@binkert.org return NullCheck 6364762Snate@binkert.org 6374762Snate@binkert.org conf = NullConf(main) 6387756SAli.Saidi@ARM.com 6398596Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 6404762Snate@binkert.org# interpreter. For consistency, we will use the same Python 6414762Snate@binkert.org# installation used to run scons (and thus this script). If you want 6428596Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 6435463Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 6448596Ssteve.reinhardt@amd.comfrom distutils import sysconfig 6458596Ssteve.reinhardt@amd.com 6465463Snate@binkert.orgpy_getvar = sysconfig.get_config_var 6477756SAli.Saidi@ARM.com 6488596Ssteve.reinhardt@amd.compy_debug = getattr(sys, 'pydebug', False) 6494762Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6507677Snate@binkert.org 6514762Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 6524762Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6536143Snate@binkert.orgpy_includes = [ py_general_include ] 6546143Snate@binkert.orgif py_platform_include != py_general_include: 6556143Snate@binkert.org py_includes.append(py_platform_include) 6564762Snate@binkert.org 6574762Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 6587756SAli.Saidi@ARM.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6597816Ssteve.reinhardt@amd.com# shared library in prefix/lib/. 6604762Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'): 6614762Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 6624762Snate@binkert.org 6634762Snate@binkert.orgpy_libs = [] 6647756SAli.Saidi@ARM.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6658596Ssteve.reinhardt@amd.com assert lib.startswith('-l') 6664762Snate@binkert.org lib = lib[2:] 6674762Snate@binkert.org if lib not in py_libs: 6687677Snate@binkert.org py_libs.append(lib) 6697756SAli.Saidi@ARM.compy_libs.append(py_version) 6708596Ssteve.reinhardt@amd.com 6717675Snate@binkert.orgmain.Append(CPPPATH=py_includes) 6727677Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 6735517Snate@binkert.org 6748596Ssteve.reinhardt@amd.com# Cache build files in the supplied directory. 6759248SAndreas.Sandberg@arm.comif main['M5_BUILD_CACHE']: 6769248SAndreas.Sandberg@arm.com print 'Using build cache located at', main['M5_BUILD_CACHE'] 6779248SAndreas.Sandberg@arm.com CacheDir(main['M5_BUILD_CACHE']) 6789248SAndreas.Sandberg@arm.com 6798596Ssteve.reinhardt@amd.com 6808596Ssteve.reinhardt@amd.com# verify that this stuff works 6818596Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'): 6829248SAndreas.Sandberg@arm.com print "Error: can't find Python.h header in", py_includes 6838596Ssteve.reinhardt@amd.com Exit(1) 6844762Snate@binkert.org 6857674Snate@binkert.orgfor lib in py_libs: 6867674Snate@binkert.org if not conf.CheckLib(lib): 6877674Snate@binkert.org print "Error: can't find library %s required by python" % lib 6887674Snate@binkert.org Exit(1) 6897674Snate@binkert.org 6907674Snate@binkert.org# On Solaris you need to use libsocket for socket ops 6917674Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6927674Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6937674Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 6947674Snate@binkert.org Exit(1) 6957674Snate@binkert.org 6967674Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 6977674Snate@binkert.org# added to the LIBS environment variable. 6987674Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 6997674Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 7004762Snate@binkert.org 'and/or zlib.h header file.' 7016143Snate@binkert.org print ' Please install zlib and try again.' 7026143Snate@binkert.org Exit(1) 7037756SAli.Saidi@ARM.com 7047816Ssteve.reinhardt@amd.com# Check for librt. 7058235Snate@binkert.orghave_posix_clock = \ 7068596Ssteve.reinhardt@amd.com conf.CheckLibWithHeader(None, 'time.h', 'C', 7077756SAli.Saidi@ARM.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 7087816Ssteve.reinhardt@amd.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 7098235Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') 7104382Sbinkertn@umich.edu 7119396Sandreas.hansson@arm.comif not have_posix_clock: 7129396Sandreas.hansson@arm.com print "Can't find library for POSIX clocks." 7139396Sandreas.hansson@arm.com 7149396Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 7159396Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 7169396Sandreas.hansson@arm.comif not have_fenv: 7179396Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 7189396Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 7199396Sandreas.hansson@arm.com 7209396Sandreas.hansson@arm.com###################################################################### 7219396Sandreas.hansson@arm.com# 7229396Sandreas.hansson@arm.com# Finish the configuration 7239396Sandreas.hansson@arm.com# 7249396Sandreas.hansson@arm.commain = conf.Finish() 7259396Sandreas.hansson@arm.com 7269396Sandreas.hansson@arm.com###################################################################### 7279396Sandreas.hansson@arm.com# 7289396Sandreas.hansson@arm.com# Collect all non-global variables 7298232Snate@binkert.org# 7308232Snate@binkert.org 7318232Snate@binkert.org# Define the universe of supported ISAs 7328232Snate@binkert.orgall_isa_list = [ ] 7338232Snate@binkert.orgExport('all_isa_list') 7346229Snate@binkert.org 7358232Snate@binkert.orgclass CpuModel(object): 7368232Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 7378232Snate@binkert.org know about a particular CPU model.''' 7386229Snate@binkert.org 7397673Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 7405517Snate@binkert.org dict = {} 7415517Snate@binkert.org list = [] 7427673Snate@binkert.org defaults = [] 7435517Snate@binkert.org 7445517Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 7455517Snate@binkert.org def __init__(self, name, filename, includes, strings, default=False): 7465517Snate@binkert.org self.name = name # name of model 7478232Snate@binkert.org self.filename = filename # filename for output exec code 7487673Snate@binkert.org self.includes = includes # include files needed in exec file 7497673Snate@binkert.org # The 'strings' dict holds all the per-CPU symbols we can 7508232Snate@binkert.org # substitute into templates etc. 7518232Snate@binkert.org self.strings = strings 7528232Snate@binkert.org 7538232Snate@binkert.org # This cpu is enabled by default 7547673Snate@binkert.org self.default = default 7555517Snate@binkert.org 7568232Snate@binkert.org # Add self to dict 7578232Snate@binkert.org if name in CpuModel.dict: 7588232Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 7598232Snate@binkert.org CpuModel.dict[name] = self 7607673Snate@binkert.org CpuModel.list.append(name) 7618232Snate@binkert.org 7628232Snate@binkert.orgExport('CpuModel') 7638232Snate@binkert.org 7648232Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 7658232Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 7668232Snate@binkert.org# value becomes sticky). 7677673Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS) 7685517Snate@binkert.orgExport('sticky_vars') 7698232Snate@binkert.org 7708232Snate@binkert.org# Sticky variables that should be exported 7715517Snate@binkert.orgexport_vars = [] 7727673Snate@binkert.orgExport('export_vars') 7735517Snate@binkert.org 7748232Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 7758232Snate@binkert.org# above variables 7765517Snate@binkert.orgif not GetOption('verbose'): 7778232Snate@binkert.org print "Reading SConsopts" 7788232Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 7798232Snate@binkert.org if not isdir(bdir): 7807673Snate@binkert.org print "Error: directory '%s' does not exist" % bdir 7815517Snate@binkert.org Exit(1) 7825517Snate@binkert.org for root, dirs, files in os.walk(bdir): 7837673Snate@binkert.org if 'SConsopts' in files: 7845517Snate@binkert.org if GetOption('verbose'): 7855517Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 7865517Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 7878232Snate@binkert.org 7885517Snate@binkert.orgall_isa_list.sort() 7895517Snate@binkert.org 7908232Snate@binkert.orgsticky_vars.AddVariables( 7918232Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 7925517Snate@binkert.org BoolVariable('FULL_SYSTEM', 'Full-system support', False), 7938232Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 7948232Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 7955517Snate@binkert.org sorted(CpuModel.list)), 7968232Snate@binkert.org BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 7978232Snate@binkert.org BoolVariable('FORCE_FAST_ALLOC', 7988232Snate@binkert.org 'Enable fast object allocator, even for m5.debug', False), 7995517Snate@binkert.org BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8008232Snate@binkert.org False), 8018232Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8028232Snate@binkert.org False), 8038232Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 8048232Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 8058232Snate@binkert.org False), 8065517Snate@binkert.org BoolVariable('USE_SSE2', 8078232Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8088232Snate@binkert.org False), 8095517Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8108232Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8117673Snate@binkert.org BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 8125517Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8137673Snate@binkert.org ) 8145517Snate@binkert.org 8158232Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 8168232Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 8178232Snate@binkert.org 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 'FAST_ALLOC_STATS', 8185192Ssaidi@eecs.umich.edu 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 8198232Snate@binkert.org 'USE_POSIX_CLOCK' ] 8208232Snate@binkert.org 8218232Snate@binkert.org################################################### 8228232Snate@binkert.org# 8238232Snate@binkert.org# Define a SCons builder for configuration flag headers. 8245192Ssaidi@eecs.umich.edu# 8257674Snate@binkert.org################################################### 8265522Snate@binkert.org 8275522Snate@binkert.org# This function generates a config header file that #defines the 8287674Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 8297674Snate@binkert.org# operands are the name of the variable and a Value node containing the 8307674Snate@binkert.org# value of the variable. 8317674Snate@binkert.orgdef build_config_file(target, source, env): 8327674Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 8337674Snate@binkert.org f = file(str(target[0]), 'w') 8347674Snate@binkert.org print >> f, '#define', variable, value 8357674Snate@binkert.org f.close() 8365522Snate@binkert.org return None 8375522Snate@binkert.org 8385522Snate@binkert.org# Combine the two functions into a scons Action object. 8395517Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 8405522Snate@binkert.org 8415517Snate@binkert.org# The emitter munges the source & target node lists to reflect what 8426143Snate@binkert.org# we're really doing. 8436727Ssteve.reinhardt@amd.comdef config_emitter(target, source, env): 8445522Snate@binkert.org # extract variable name from Builder arg 8455522Snate@binkert.org variable = str(target[0]) 8465522Snate@binkert.org # True target is config header file 8477674Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 8485517Snate@binkert.org val = env[variable] 8497673Snate@binkert.org if isinstance(val, bool): 8507673Snate@binkert.org # Force value to 0/1 8517674Snate@binkert.org val = int(val) 8527673Snate@binkert.org elif isinstance(val, str): 8537674Snate@binkert.org val = '"' + val + '"' 8547674Snate@binkert.org 8558946Sandreas.hansson@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 8567674Snate@binkert.org return ([target], [Value(variable), Value(val)]) 8577674Snate@binkert.org 8587674Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 8595522Snate@binkert.org 8605522Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8617674Snate@binkert.org 8627674Snate@binkert.org# libelf build is shared across all configs in the build root. 8637674Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 8647674Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 8657673Snate@binkert.org 8667674Snate@binkert.org# gzstream build is shared across all configs in the build root. 8677674Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript', 8687674Snate@binkert.org variant_dir = joinpath(build_root, 'gzstream')) 8697674Snate@binkert.org 8707674Snate@binkert.org################################################### 8717674Snate@binkert.org# 8727674Snate@binkert.org# This function is used to set up a directory with switching headers 8737674Snate@binkert.org# 8747811Ssteve.reinhardt@amd.com################################################### 8757674Snate@binkert.org 8767673Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list 8775522Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env): 8786143Snate@binkert.org # Generate the header. target[0] is the full path of the output 87910453SAndrew.Bardsley@arm.com # header to generate. 'source' is a dummy variable, since we get the 8807816Ssteve.reinhardt@amd.com # list of ISAs from env['ALL_ISA_LIST']. 88110453SAndrew.Bardsley@arm.com def gen_switch_hdr(target, source, env): 8824382Sbinkertn@umich.edu fname = str(target[0]) 8834382Sbinkertn@umich.edu f = open(fname, 'w') 8844382Sbinkertn@umich.edu isa = env['TARGET_ISA'].lower() 8854382Sbinkertn@umich.edu print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 8864382Sbinkertn@umich.edu f.close() 8874382Sbinkertn@umich.edu 8884382Sbinkertn@umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 8894382Sbinkertn@umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 89010196SCurtis.Dunham@arm.com # should get re-executed. 8914382Sbinkertn@umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 89210196SCurtis.Dunham@arm.com Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 89310196SCurtis.Dunham@arm.com 89410196SCurtis.Dunham@arm.com # Instantiate actions for each header 89510196SCurtis.Dunham@arm.com for hdr in switch_headers: 89610196SCurtis.Dunham@arm.com env.Command(hdr, [], switch_hdr_action) 89710196SCurtis.Dunham@arm.comExport('make_switching_dir') 89810196SCurtis.Dunham@arm.com 899955SN/A################################################### 9002655Sstever@eecs.umich.edu# 9012655Sstever@eecs.umich.edu# Define build environments for selected configurations. 9022655Sstever@eecs.umich.edu# 9032655Sstever@eecs.umich.edu################################################### 90410196SCurtis.Dunham@arm.com 9055601Snate@binkert.orgfor variant_path in variant_paths: 9065601Snate@binkert.org print "Building in", variant_path 90710196SCurtis.Dunham@arm.com 90810196SCurtis.Dunham@arm.com # Make a copy of the build-root environment to use for this config. 90910196SCurtis.Dunham@arm.com env = main.Clone() 9105522Snate@binkert.org env['BUILDDIR'] = variant_path 9115863Snate@binkert.org 9125601Snate@binkert.org # variant_dir is the tail component of build path, and is used to 9135601Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 9145601Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 9155863Snate@binkert.org 9169556Sandreas.hansson@arm.com # Set env variables according to the build directory config. 9179556Sandreas.hansson@arm.com sticky_vars.files = [] 9189556Sandreas.hansson@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 9199556Sandreas.hansson@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 9209556Sandreas.hansson@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 9219556Sandreas.hansson@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 9229556Sandreas.hansson@arm.com if isfile(current_vars_file): 9239556Sandreas.hansson@arm.com sticky_vars.files.append(current_vars_file) 9249556Sandreas.hansson@arm.com print "Using saved variables file %s" % current_vars_file 9255559Snate@binkert.org else: 9269556Sandreas.hansson@arm.com # Build dir-specific variables file doesn't exist. 9279618Ssteve.reinhardt@amd.com 9289618Ssteve.reinhardt@amd.com # Make sure the directory is there so we can create it later 9299618Ssteve.reinhardt@amd.com opt_dir = dirname(current_vars_file) 93010238Sandreas.hansson@arm.com if not isdir(opt_dir): 93110238Sandreas.hansson@arm.com mkdir(opt_dir) 9329554Sandreas.hansson@arm.com 9339556Sandreas.hansson@arm.com # Get default build variables from source tree. Variables are 9349556Sandreas.hansson@arm.com # normally determined by name of $VARIANT_DIR, but can be 9359556Sandreas.hansson@arm.com # overridden by '--default=' arg on command line. 9369556Sandreas.hansson@arm.com default = GetOption('default') 9379555Sandreas.hansson@arm.com opts_dir = joinpath(main.root.abspath, 'build_opts') 9389555Sandreas.hansson@arm.com if default: 9399556Sandreas.hansson@arm.com default_vars_files = [joinpath(build_root, 'variables', default), 9408737Skoansin.tan@gmail.com joinpath(opts_dir, default)] 9419556Sandreas.hansson@arm.com else: 9429556Sandreas.hansson@arm.com default_vars_files = [joinpath(opts_dir, variant_dir)] 9439556Sandreas.hansson@arm.com existing_files = filter(isfile, default_vars_files) 9449554Sandreas.hansson@arm.com if existing_files: 94510278SAndreas.Sandberg@ARM.com default_vars_file = existing_files[0] 94610278SAndreas.Sandberg@ARM.com sticky_vars.files.append(default_vars_file) 94710278SAndreas.Sandberg@ARM.com print "Variables file %s not found,\n using defaults in %s" \ 94810278SAndreas.Sandberg@ARM.com % (current_vars_file, default_vars_file) 94910278SAndreas.Sandberg@ARM.com else: 95010278SAndreas.Sandberg@ARM.com print "Error: cannot find variables file %s or " \ 95110278SAndreas.Sandberg@ARM.com "default file(s) %s" \ 95210278SAndreas.Sandberg@ARM.com % (current_vars_file, ' or '.join(default_vars_files)) 9538945Ssteve.reinhardt@amd.com Exit(1) 9548945Ssteve.reinhardt@amd.com 9558945Ssteve.reinhardt@amd.com # Apply current variable settings to env 9566143Snate@binkert.org sticky_vars.Update(env) 9576143Snate@binkert.org 9586143Snate@binkert.org help_texts["local_vars"] += \ 9596143Snate@binkert.org "Build variables for %s:\n" % variant_dir \ 9606143Snate@binkert.org + sticky_vars.GenerateHelpText(env) 9616143Snate@binkert.org 9626143Snate@binkert.org # Process variable settings. 9638945Ssteve.reinhardt@amd.com 9648945Ssteve.reinhardt@amd.com if not have_fenv and env['USE_FENV']: 9656143Snate@binkert.org print "Warning: <fenv.h> not available; " \ 9666143Snate@binkert.org "forcing USE_FENV to False in", variant_dir + "." 9676143Snate@binkert.org env['USE_FENV'] = False 9686143Snate@binkert.org 9696143Snate@binkert.org if not env['USE_FENV']: 9706143Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 9716143Snate@binkert.org print " FP results may deviate slightly from other platforms." 9726143Snate@binkert.org 9736143Snate@binkert.org if env['EFENCE']: 9746143Snate@binkert.org env.Append(LIBS=['efence']) 9756143Snate@binkert.org 9766143Snate@binkert.org # Save sticky variable settings back to current variables file 9776143Snate@binkert.org sticky_vars.Save(current_vars_file, env) 97810453SAndrew.Bardsley@arm.com 97910453SAndrew.Bardsley@arm.com if env['USE_SSE2']: 98010453SAndrew.Bardsley@arm.com env.Append(CCFLAGS=['-msse2']) 98110453SAndrew.Bardsley@arm.com 98210453SAndrew.Bardsley@arm.com if env['PROTOCOL'] != 'None': 98310453SAndrew.Bardsley@arm.com env['RUBY'] = True 98410453SAndrew.Bardsley@arm.com else: 98510453SAndrew.Bardsley@arm.com env['RUBY'] = False 98610453SAndrew.Bardsley@arm.com 9876143Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 9886143Snate@binkert.org # to the configured variables. It returns a list of environments, 9896143Snate@binkert.org # one for each variant build (debug, opt, etc.) 99010453SAndrew.Bardsley@arm.com envList = SConscript('src/SConscript', variant_dir = variant_path, 9916143Snate@binkert.org exports = 'env') 9926240Snate@binkert.org 9935554Snate@binkert.org # Set up the regression tests for each build. 9945522Snate@binkert.org for e in envList: 9955522Snate@binkert.org SConscript('tests/SConscript', 9965797Snate@binkert.org variant_dir = joinpath(variant_path, 'tests', e.Label), 9975797Snate@binkert.org exports = { 'env' : e }, duplicate = False) 9985522Snate@binkert.org 9995601Snate@binkert.org# base help text 10008233Snate@binkert.orgHelp(''' 10018233Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)] 10028235Snate@binkert.org 10038235Snate@binkert.orgExtra scons options: 10048235Snate@binkert.org%(options)s 10058235Snate@binkert.org 10069003SAli.Saidi@ARM.comGlobal build variables: 10079003SAli.Saidi@ARM.com%(global_vars)s 100810196SCurtis.Dunham@arm.com 100910196SCurtis.Dunham@arm.com%(local_vars)s 10108235Snate@binkert.org''' % help_texts) 10116143Snate@binkert.org