SConstruct (7807:15553b536bd6) SConstruct (7816:b5003ac75977)
1# -*- mode:python -*-
2
1# -*- mode:python -*-
2
3# Copyright (c) 2011 Advanced Micro Devices, Inc.
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
9# met: redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer;

--- 104 unchanged lines hidden (view full) ---

115 Dir('src/python').srcnode().abspath, # M5 includes
116 Dir('ext/ply').srcnode().abspath, # ply is used by several files
117 ]
118
119sys.path[1:1] = extra_python_paths
120
121from m5.util import compareVersions, readCommand
122
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
123########################################################################
124#
125# Set up the main build environment.
126#
127########################################################################
128use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
129 'PYTHONPATH', 'RANLIB' ])
130

--- 221 unchanged lines hidden (view full) ---

352 extras_dir_list = []
353
354Export('base_dir')
355Export('extras_dir_list')
356
357# the ext directory should be on the #includes path
358main.Append(CPPPATH=[Dir('ext')])
359
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
360def _STRIP(path, env):
373def strip_build_path(path, env):
361 path = str(path)
362 variant_base = env['BUILDROOT'] + os.path.sep
363 if path.startswith(variant_base):
364 path = path[len(variant_base):]
365 elif path.startswith('build/'):
366 path = path[6:]
367 return path
368
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
369def _STRIP_SOURCE(target, source, env, for_signature):
370 return _STRIP(source[0], env)
371main['STRIP_SOURCE'] = _STRIP_SOURCE
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
372
392
373def _STRIP_TARGET(target, source, env, for_signature):
374 return _STRIP(target[0], env)
375main['STRIP_TARGET'] = _STRIP_TARGET
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
376
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
377if main['VERBOSE']:
378 def MakeAction(action, string, *args, **kwargs):
379 return Action(action, *args, **kwargs)
380else:
381 MakeAction = Action
455if main['VERBOSE']:
456 def MakeAction(action, string, *args, **kwargs):
457 return Action(action, *args, **kwargs)
458else:
459 MakeAction = Action
382 main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE'
383 main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE'
384 main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE'
385 main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE'
386 main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET'
387 main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET'
388 main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET'
389 main['M4COMSTR'] = ' [ M4] $STRIP_TARGET'
390 main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET'
391 main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET'
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")
392Export('MakeAction')
393
394CXX_version = readCommand([main['CXX'],'--version'], exception=False)
395CXX_V = readCommand([main['CXX'],'-V'], exception=False)
396
397main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
398main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
399main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0

--- 423 unchanged lines hidden (view full) ---

823 isa = env['TARGET_ISA'].lower()
824 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
825 f.close()
826
827 # Build SCons Action object. 'varlist' specifies env vars that this
828 # action depends on; when env['ALL_ISA_LIST'] changes these actions
829 # should get re-executed.
830 switch_hdr_action = MakeAction(gen_switch_hdr,
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,
831 " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST'])
909 Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
832
833 # Instantiate actions for each header
834 for hdr in switch_headers:
835 env.Command(hdr, [], switch_hdr_action)
836Export('make_switching_dir')
837
838###################################################
839#

--- 95 unchanged lines hidden ---
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 ---