1# -*- mode:python -*- 2 3# Copyright (c) 2009 The Hewlett-Packard Development Company 4# Copyright (c) 2004-2005 The Regents of The University of Michigan 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are --- 144 unchanged lines hidden (view full) --- 153 if n1 > n2: return 1 154 # all corresponding values are equal... see if one has extra values 155 if len(v1) < len(v2): return -1 156 if len(v1) > len(v2): return 1 157 return 0 158 159######################################################################## 160# |
161# Set up the main build environment. |
162# 163######################################################################## 164use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 165 'RANLIB' ]) 166 167use_env = {} 168for key,val in os.environ.iteritems(): 169 if key in use_vars or key.startswith("M5"): 170 use_env[key] = val 171 |
172main = Environment(ENV=use_env) 173main.root = Dir(".") # The current directory (where this file lives). 174main.srcdir = Dir("src") # The source directory |
175 176######################################################################## 177# 178# Mercurial Stuff. 179# 180# If the M5 directory is a mercurial repository, we should do some 181# extra things. 182# 183######################################################################## 184 |
185hgdir = main.root.Dir(".hg") |
186 187mercurial_style_message = """ 188You're missing the M5 style hook. 189Please install the hook so we can ensure that all code fits a common style. 190 191All you'd need to do is add the following lines to your repository .hg/hgrc 192or your personal .hgrc 193---------------- 194 195[extensions] 196style = %s/util/style.py 197 198[hooks] 199pretxncommit.style = python:style.check_whitespace |
200""" % (main.root) |
201 202mercurial_bin_not_found = """ 203Mercurial binary cannot be found, unfortunately this means that we 204cannot easily determine the version of M5 that you are running and 205this makes error messages more difficult to collect. Please consider 206installing mercurial if you choose to post an error message 207""" 208 209mercurial_lib_not_found = """ 210Mercurial libraries cannot be found, ignoring style hook 211If you are actually a M5 developer, please fix this and 212run the style hook. It is important. 213""" 214 215hg_info = "Unknown" 216if hgdir.exists(): 217 # 1) Grab repository revision if we know it. 218 cmd = "hg id -n -i -t -b" 219 try: |
220 hg_info = read_command(cmd, cwd=main.root.abspath).strip() |
221 except OSError: 222 print mercurial_bin_not_found 223 224 # 2) Ensure that the style hook is in place. 225 try: 226 ui = None 227 if ARGUMENTS.get('IGNORE_STYLE') != 'True': 228 from mercurial import ui --- 5 unchanged lines hidden (view full) --- 234 ui.readconfig(hgdir.File('hgrc').abspath) 235 style_hook = ui.config('hooks', 'pretxncommit.style', None) 236 237 if not style_hook: 238 print mercurial_style_message 239 sys.exit(1) 240else: 241 print ".hg directory not found" |
242 |
243main['HG_INFO'] = hg_info 244 |
245################################################### 246# 247# Figure out which configurations to set up based on the path(s) of 248# the target(s). 249# 250################################################### 251 252# Find default configuration & binary. --- 16 unchanged lines hidden (view full) --- 269if COMMAND_LINE_TARGETS: 270 # Ask SCons which directory it was invoked from 271 launch_dir = GetLaunchDir() 272 # Make targets relative to invocation directory 273 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 274 COMMAND_LINE_TARGETS] 275else: 276 # Default targets are relative to root of tree |
277 abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ |
278 DEFAULT_TARGETS] 279 280 281# Generate a list of the unique build roots and configs that the 282# collected targets reference. 283variant_paths = [] 284build_root = None 285for t in abs_targets: --- 14 unchanged lines hidden (view full) --- 300 variant_path = joinpath('/',*path_dirs[:build_top+2]) 301 if variant_path not in variant_paths: 302 variant_paths.append(variant_path) 303 304# Make sure build_root exists (might not if this is the first build there) 305if not isdir(build_root): 306 mkdir(build_root) 307 |
308Export('main') |
309 |
310main.SConsignFile(joinpath(build_root, "sconsign")) |
311 312# Default duplicate option is to use hard links, but this messes up 313# when you use emacs to edit a file in the target dir, as emacs moves 314# file to file~ then copies to file, breaking the link. Symbolic 315# (soft) links work better. |
316main.SetOption('duplicate', 'soft-copy') |
317 318# 319# Set up global sticky variables... these are common to an entire build 320# tree (not specific to a particular build like ALPHA_SE) 321# 322 323# Variable validators & converters for global sticky variables 324def PathListMakeAbsolute(val): --- 10 unchanged lines hidden (view full) --- 335 if not isdir(path): 336 raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 337 338global_sticky_vars_file = joinpath(build_root, 'variables.global') 339 340global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 341 342global_sticky_vars.AddVariables( |
343 ('CC', 'C compiler', environ.get('CC', main['CC'])), 344 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), |
345 ('BATCH', 'Use batch pool for build and tests', False), 346 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 347 ('EXTRAS', 'Add Extra directories to the compilation', '', 348 PathListAllExist, PathListMakeAbsolute) 349 ) 350 351# base help text 352help_text = ''' 353Usage: scons [scons options] [build options] [target(s)] 354 355Global sticky options: 356''' 357 |
358help_text += global_sticky_vars.GenerateHelpText(main) |
359 |
360# Update main environment with values from ARGUMENTS & global_sticky_vars_file 361global_sticky_vars.Update(main) |
362 363# Save sticky variable settings back to current variables file |
364global_sticky_vars.Save(global_sticky_vars_file, main) |
365 366# Parse EXTRAS variable to build list of all directories where we're 367# look for sources etc. This list is exported as base_dir_list. |
368base_dir = main.srcdir.abspath 369if main['EXTRAS']: 370 extras_dir_list = main['EXTRAS'].split(':') |
371else: 372 extras_dir_list = [] 373 374Export('base_dir') 375Export('extras_dir_list') 376 377# the ext directory should be on the #includes path |
378main.Append(CPPPATH=[Dir('ext')]) |
379 380# M5_PLY is used by isa_parser.py to find the PLY package. |
381main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) |
382 |
383CXX_version = read_command([main['CXX'],'--version'], exception=False) 384CXX_V = read_command([main['CXX'],'-V'], exception=False) |
385 |
386main['GCC'] = CXX_version and CXX_version.find('g++') >= 0 387main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 388main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 389if main['GCC'] + main['SUNCC'] + main['ICC'] > 1: |
390 print 'Error: How can we have two at the same time?' 391 Exit(1) 392 393# Set up default C++ compiler flags |
394if main['GCC']: 395 main.Append(CCFLAGS='-pipe') 396 main.Append(CCFLAGS='-fno-strict-aliasing') 397 main.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 398 main.Append(CXXFLAGS='-Wno-deprecated') 399elif main['ICC']: |
400 pass #Fix me... add warning flags once we clean up icc warnings |
401elif main['SUNCC']: 402 main.Append(CCFLAGS='-Qoption ccfe') 403 main.Append(CCFLAGS='-features=gcc') 404 main.Append(CCFLAGS='-features=extensions') 405 main.Append(CCFLAGS='-library=stlport4') 406 main.Append(CCFLAGS='-xar') 407 #main.Append(CCFLAGS='-instances=semiexplicit') |
408else: 409 print 'Error: Don\'t know what compiler options to use for your compiler.' 410 print ' Please fix SConstruct and src/SConscript and try again.' 411 Exit(1) 412 413# Do this after we save setting back, or else we'll tack on an 414# extra 'qdo' every time we run scons. |
415if main['BATCH']: 416 main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 417 main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 418 main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 419 main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 420 main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] |
421 422if sys.platform == 'cygwin': 423 # cygwin has some header file issues... |
424 main.Append(CCFLAGS=Split("-Wno-uninitialized")) |
425 426# Check for SWIG |
427if not main.has_key('SWIG'): |
428 print 'Error: SWIG utility not found.' 429 print ' Please install (see http://www.swig.org) and retry.' 430 Exit(1) 431 432# Check for appropriate SWIG version 433swig_version = read_command(('swig', '-version'), exception='').split() 434# First 3 words should be "SWIG Version x.y.z" 435if len(swig_version) < 3 or \ --- 4 unchanged lines hidden (view full) --- 440min_swig_version = '1.3.28' 441if compare_versions(swig_version[2], min_swig_version) < 0: 442 print 'Error: SWIG version', min_swig_version, 'or newer required.' 443 print ' Installed version:', swig_version[2] 444 Exit(1) 445 446# Set up SWIG flags & scanner 447swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') |
448main.Append(SWIGFLAGS=swig_flags) |
449 450# filter out all existing swig scanners, they mess up the dependency 451# stuff for some reason 452scanners = [] |
453for scanner in main['SCANNERS']: |
454 skeys = scanner.skeys 455 if skeys == '.i': 456 continue 457 458 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 459 continue 460 461 scanners.append(scanner) 462 463# add the new swig scanner that we like better 464from SCons.Scanner import ClassicCPP as CPPScanner 465swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 466scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 467 468# replace the scanners list that has what we want |
469main['SCANNERS'] = scanners |
470 471# Add a custom Check function to the Configure context so that we can 472# figure out if the compiler adds leading underscores to global 473# variables. This is needed for the autogenerated asm files that we 474# use for embedding the python code. 475def CheckLeading(context): 476 context.Message("Checking for leading underscore in global variables...") 477 # 1) Define a global variable called x from asm so the C compiler --- 13 unchanged lines hidden (view full) --- 491 int main() { return x; } 492 ''', extension=".c") 493 context.env.Append(LEADING_UNDERSCORE=ret) 494 context.Result(ret) 495 return ret 496 497# Platform-specific configuration. Note again that we assume that all 498# builds under a given build root run on the same host platform. |
499conf = Configure(main, |
500 conf_dir = joinpath(build_root, '.scons_config'), 501 log_file = joinpath(build_root, 'scons_config.log'), 502 custom_tests = { 'CheckLeading' : CheckLeading }) 503 504# Check for leading underscores. Don't really need to worry either 505# way so don't need to check the return code. 506conf.CheckLeading() 507 508# Check if we should compile a 64 bit binary on Mac OS X/Darwin 509try: 510 import platform 511 uname = platform.uname() 512 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 513 if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): |
514 main.Append(CCFLAGS='-arch x86_64') 515 main.Append(CFLAGS='-arch x86_64') 516 main.Append(LINKFLAGS='-arch x86_64') 517 main.Append(ASFLAGS='-arch x86_64') |
518except: 519 pass 520 521# Recent versions of scons substitute a "Null" object for Configure() 522# when configuration isn't necessary, e.g., if the "--help" option is 523# present. Unfortuantely this Null object always returns false, 524# breaking all our configuration checks. We replace it with our own 525# more optimistic null object that returns True instead. --- 4 unchanged lines hidden (view full) --- 530 class NullConf: 531 def __init__(self, env): 532 self.env = env 533 def Finish(self): 534 return self.env 535 def __getattr__(self, mname): 536 return NullCheck 537 |
538 conf = NullConf(main) |
539 540# Find Python include and library directories for embedding the 541# interpreter. For consistency, we will use the same Python 542# installation used to run scons (and thus this script). If you want 543# to link in an alternate version, see above for instructions on how 544# to invoke scons with a different copy of the Python interpreter. 545from distutils import sysconfig 546 --- 16 unchanged lines hidden (view full) --- 563py_libs = [] 564for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 565 assert lib.startswith('-l') 566 lib = lib[2:] 567 if lib not in py_libs: 568 py_libs.append(lib) 569py_libs.append(py_version) 570 |
571main.Append(CPPPATH=py_includes) 572main.Append(LIBPATH=py_lib_path) |
573 574# verify that this stuff works 575if not conf.CheckHeader('Python.h', '<>'): 576 print "Error: can't find Python.h header in", py_includes 577 Exit(1) 578 579for lib in py_libs: 580 if not conf.CheckLib(lib): --- 45 unchanged lines hidden (view full) --- 626 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 627 # This seems to work in all versions 628 mysql_config_libs = mysql_config + ' --libs' 629 630###################################################################### 631# 632# Finish the configuration 633# |
634main = conf.Finish() |
635 636###################################################################### 637# 638# Collect all non-global variables 639# 640 |
641# Define the universe of supported ISAs 642all_isa_list = [ ] 643Export('all_isa_list') 644 645# Define the universe of supported CPU models 646all_cpu_list = [ ] 647default_cpus = [ ] 648Export('all_cpu_list', 'default_cpus') --- 95 unchanged lines hidden (view full) --- 744 elif isinstance(val, str): 745 val = '"' + val + '"' 746 747 # Sources are variable name & value (packaged in SCons Value nodes) 748 return ([target], [Value(variable), Value(val)]) 749 750config_builder = Builder(emitter = config_emitter, action = config_action) 751 |
752main.Append(BUILDERS = { 'ConfigFile' : config_builder }) |
753 754# libelf build is shared across all configs in the build root. |
755main.SConscript('ext/libelf/SConscript', 756 variant_dir = joinpath(build_root, 'libelf')) |
757 758# gzstream build is shared across all configs in the build root. |
759main.SConscript('ext/gzstream/SConscript', 760 variant_dir = joinpath(build_root, 'gzstream')) |
761 762################################################### 763# 764# This function is used to set up a directory with switching headers 765# 766################################################### 767 |
768main['ALL_ISA_LIST'] = all_isa_list |
769def make_switching_dir(dname, switch_headers, env): 770 # Generate the header. target[0] is the full path of the output 771 # header to generate. 'source' is a dummy variable, since we get the 772 # list of ISAs from env['ALL_ISA_LIST']. 773 def gen_switch_hdr(target, source, env): 774 fname = str(target[0]) 775 bname = basename(fname) 776 f = open(fname, 'w') --- 23 unchanged lines hidden (view full) --- 800Export('make_switching_dir') 801 802################################################### 803# 804# Define build environments for selected configurations. 805# 806################################################### 807 |
808for variant_path in variant_paths: 809 print "Building in", variant_path 810 811 # Make a copy of the build-root environment to use for this config. |
812 env = main.Clone() |
813 env['BUILDDIR'] = variant_path 814 815 # variant_dir is the tail component of build path, and is used to 816 # determine the build parameters (e.g., 'ALPHA_SE') 817 (build_root, variant_dir) = splitpath(variant_path) 818 819 # Set env variables according to the build directory config. 820 sticky_vars.files = [] --- 81 unchanged lines hidden --- |