1# -*- mode:python -*- 2 |
3# Copyright (c) 2011 Advanced Micro Devices, Inc. |
4# Copyright (c) 2009 The Hewlett-Packard Development Company 5# Copyright (c) 2004-2005 The Regents of The University of Michigan 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions are 10# met: redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer; --- 104 unchanged lines hidden (view full) --- 116 Dir('src/python').srcnode().abspath, # M5 includes 117 Dir('ext/ply').srcnode().abspath, # ply is used by several files 118 ] 119 120sys.path[1:1] = extra_python_paths 121 122from m5.util import compareVersions, readCommand 123 |
124AddOption('--colors', dest='use_colors', action='store_true') 125AddOption('--no-colors', dest='use_colors', action='store_false') 126use_colors = GetOption('use_colors') 127 128if use_colors: 129 from m5.util.terminal import termcap 130elif use_colors is None: 131 # option unspecified; default behavior is to use colors iff isatty 132 from m5.util.terminal import tty_termcap as termcap 133else: 134 from m5.util.terminal import no_termcap as termcap 135 |
136######################################################################## 137# 138# Set up the main build environment. 139# 140######################################################################## 141use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 142 'PYTHONPATH', 'RANLIB' ]) 143 --- 221 unchanged lines hidden (view full) --- 365 extras_dir_list = [] 366 367Export('base_dir') 368Export('extras_dir_list') 369 370# the ext directory should be on the #includes path 371main.Append(CPPPATH=[Dir('ext')]) 372 |
373def strip_build_path(path, env): |
374 path = str(path) 375 variant_base = env['BUILDROOT'] + os.path.sep 376 if path.startswith(variant_base): 377 path = path[len(variant_base):] 378 elif path.startswith('build/'): 379 path = path[6:] 380 return path 381 |
382# Generate a string of the form: 383# common/path/prefix/src1, src2 -> tgt1, tgt2 384# to print while building. 385class Transform(object): 386 # all specific color settings should be here and nowhere else 387 tool_color = termcap.Normal 388 pfx_color = termcap.Yellow 389 srcs_color = termcap.Yellow + termcap.Bold 390 arrow_color = termcap.Blue + termcap.Bold 391 tgts_color = termcap.Yellow + termcap.Bold |
392 |
393 def __init__(self, tool, max_sources=99): 394 self.format = self.tool_color + (" [%8s] " % tool) \ 395 + self.pfx_color + "%s" \ 396 + self.srcs_color + "%s" \ 397 + self.arrow_color + " -> " \ 398 + self.tgts_color + "%s" \ 399 + termcap.Normal 400 self.max_sources = max_sources |
401 |
402 def __call__(self, target, source, env, for_signature=None): 403 # truncate source list according to max_sources param 404 source = source[0:self.max_sources] 405 def strip(f): 406 return strip_build_path(str(f), env) 407 if len(source) > 0: 408 srcs = map(strip, source) 409 else: 410 srcs = [''] 411 tgts = map(strip, target) 412 # surprisingly, os.path.commonprefix is a dumb char-by-char string 413 # operation that has nothing to do with paths. 414 com_pfx = os.path.commonprefix(srcs + tgts) 415 com_pfx_len = len(com_pfx) 416 if com_pfx: 417 # do some cleanup and sanity checking on common prefix 418 if com_pfx[-1] == ".": 419 # prefix matches all but file extension: ok 420 # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 421 com_pfx = com_pfx[0:-1] 422 elif com_pfx[-1] == "/": 423 # common prefix is directory path: OK 424 pass 425 else: 426 src0_len = len(srcs[0]) 427 tgt0_len = len(tgts[0]) 428 if src0_len == com_pfx_len: 429 # source is a substring of target, OK 430 pass 431 elif tgt0_len == com_pfx_len: 432 # target is a substring of source, need to back up to 433 # avoid empty string on RHS of arrow 434 sep_idx = com_pfx.rfind(".") 435 if sep_idx != -1: 436 com_pfx = com_pfx[0:sep_idx] 437 else: 438 com_pfx = '' 439 elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 440 # still splitting at file extension: ok 441 pass 442 else: 443 # probably a fluke; ignore it 444 com_pfx = '' 445 # recalculate length in case com_pfx was modified 446 com_pfx_len = len(com_pfx) 447 def fmt(files): 448 f = map(lambda s: s[com_pfx_len:], files) 449 return ', '.join(f) 450 return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 451 452Export('Transform') 453 454 |
455if main['VERBOSE']: 456 def MakeAction(action, string, *args, **kwargs): 457 return Action(action, *args, **kwargs) 458else: 459 MakeAction = Action |
460 main['CCCOMSTR'] = Transform("CC") 461 main['CXXCOMSTR'] = Transform("CXX") 462 main['ASCOMSTR'] = Transform("AS") 463 main['SWIGCOMSTR'] = Transform("SWIG") 464 main['ARCOMSTR'] = Transform("AR", 0) 465 main['LINKCOMSTR'] = Transform("LINK", 0) 466 main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 467 main['M4COMSTR'] = Transform("M4") 468 main['SHCCCOMSTR'] = Transform("SHCC") 469 main['SHCXXCOMSTR'] = Transform("SHCXX") |
470Export('MakeAction') 471 472CXX_version = readCommand([main['CXX'],'--version'], exception=False) 473CXX_V = readCommand([main['CXX'],'-V'], exception=False) 474 475main['GCC'] = CXX_version and CXX_version.find('g++') >= 0 476main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 477main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 --- 423 unchanged lines hidden (view full) --- 901 isa = env['TARGET_ISA'].lower() 902 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 903 f.close() 904 905 # Build SCons Action object. 'varlist' specifies env vars that this 906 # action depends on; when env['ALL_ISA_LIST'] changes these actions 907 # should get re-executed. 908 switch_hdr_action = MakeAction(gen_switch_hdr, |
909 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) |
910 911 # Instantiate actions for each header 912 for hdr in switch_headers: 913 env.Command(hdr, [], switch_hdr_action) 914Export('make_switching_dir') 915 916################################################### 917# --- 95 unchanged lines hidden --- |