SConstruct (8267:06f3a4cbd585) SConstruct (8268:3f49ed206f46)
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

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

259
260# helper function: find last occurrence of element in list
261def rfind(l, elt, offs = -1):
262 for i in range(len(l)+offs, 0, -1):
263 if l[i] == elt:
264 return i
265 raise ValueError, "element not found"
266
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

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

259
260# helper function: find last occurrence of element in list
261def rfind(l, elt, offs = -1):
262 for i in range(len(l)+offs, 0, -1):
263 if l[i] == elt:
264 return i
265 raise ValueError, "element not found"
266
267# Take a list of paths (or SCons Nodes) and return a list with all
268# paths made absolute and ~-expanded. Paths will be interpreted
269# relative to the launch directory unless a different root is provided
270def makePathListAbsolute(path_list, root=GetLaunchDir()):
271 return [abspath(joinpath(root, expanduser(str(p))))
272 for p in path_list]
273
267# Each target must have 'build' in the interior of the path; the
268# directory below this will determine the build parameters. For
269# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
270# recognize that ALPHA_SE specifies the configuration because it
274# Each target must have 'build' in the interior of the path; the
275# directory below this will determine the build parameters. For
276# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
277# recognize that ALPHA_SE specifies the configuration because it
271# follow 'build' in the bulid path.
278# follow 'build' in the build path.
272
279
273# Generate absolute paths to targets so we can see where the build dir is
274if COMMAND_LINE_TARGETS:
275 # Ask SCons which directory it was invoked from
276 launch_dir = GetLaunchDir()
277 # Make targets relative to invocation directory
278 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
279 COMMAND_LINE_TARGETS]
280else:
281 # Default targets are relative to root of tree
282 abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
283 DEFAULT_TARGETS]
280# The funky assignment to "[:]" is needed to replace the list contents
281# in place rather than reassign the symbol to a new list, which
282# doesn't work (obviously!).
283BUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
284
284
285
286# Generate a list of the unique build roots and configs that the
287# collected targets reference.
288variant_paths = []
289build_root = None
285# Generate a list of the unique build roots and configs that the
286# collected targets reference.
287variant_paths = []
288build_root = None
290for t in abs_targets:
289for t in BUILD_TARGETS:
291 path_dirs = t.split('/')
292 try:
293 build_top = rfind(path_dirs, 'build', -2)
294 except:
295 print "Error: no non-leaf 'build' dir found on target path", t
296 Exit(1)
297 this_build_root = joinpath('/',*path_dirs[:build_top+1])
298 if not build_root:

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

321# (soft) links work better.
322main.SetOption('duplicate', 'soft-copy')
323
324#
325# Set up global sticky variables... these are common to an entire build
326# tree (not specific to a particular build like ALPHA_SE)
327#
328
290 path_dirs = t.split('/')
291 try:
292 build_top = rfind(path_dirs, 'build', -2)
293 except:
294 print "Error: no non-leaf 'build' dir found on target path", t
295 Exit(1)
296 this_build_root = joinpath('/',*path_dirs[:build_top+1])
297 if not build_root:

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

320# (soft) links work better.
321main.SetOption('duplicate', 'soft-copy')
322
323#
324# Set up global sticky variables... these are common to an entire build
325# tree (not specific to a particular build like ALPHA_SE)
326#
327
329# Variable validators & converters for global sticky variables
330def PathListMakeAbsolute(val):
331 if not val:
332 return val
333 f = lambda p: abspath(expanduser(p))
334 return ':'.join(map(f, val.split(':')))
335
336def PathListAllExist(key, val, env):
337 if not val:
338 return
339 paths = val.split(':')
340 for path in paths:
341 if not isdir(path):
342 raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
343
344global_vars_file = joinpath(build_root, 'variables.global')
345
346global_vars = Variables(global_vars_file, args=ARGUMENTS)
347
348global_vars.AddVariables(
349 ('CC', 'C compiler', environ.get('CC', main['CC'])),
350 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
351 ('BATCH', 'Use batch pool for build and tests', False),
352 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
353 ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
328global_vars_file = joinpath(build_root, 'variables.global')
329
330global_vars = Variables(global_vars_file, args=ARGUMENTS)
331
332global_vars.AddVariables(
333 ('CC', 'C compiler', environ.get('CC', main['CC'])),
334 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
335 ('BATCH', 'Use batch pool for build and tests', False),
336 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
337 ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
354 ('EXTRAS', 'Add extra directories to the compilation', '',
355 PathListAllExist, PathListMakeAbsolute),
338 ('EXTRAS', 'Add extra directories to the compilation', '')
356 )
357
358# Update main environment with values from ARGUMENTS & global_vars_file
359global_vars.Update(main)
360help_texts["global_vars"] += global_vars.GenerateHelpText(main)
361
362# Save sticky variable settings back to current variables file
363global_vars.Save(global_vars_file, main)
364
365# Parse EXTRAS variable to build list of all directories where we're
339 )
340
341# Update main environment with values from ARGUMENTS & global_vars_file
342global_vars.Update(main)
343help_texts["global_vars"] += global_vars.GenerateHelpText(main)
344
345# Save sticky variable settings back to current variables file
346global_vars.Save(global_vars_file, main)
347
348# Parse EXTRAS variable to build list of all directories where we're
366# look for sources etc. This list is exported as base_dir_list.
349# look for sources etc. This list is exported as extras_dir_list.
367base_dir = main.srcdir.abspath
368if main['EXTRAS']:
350base_dir = main.srcdir.abspath
351if main['EXTRAS']:
369 extras_dir_list = main['EXTRAS'].split(':')
352 extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
370else:
371 extras_dir_list = []
372
373Export('base_dir')
374Export('extras_dir_list')
375
376# the ext directory should be on the #includes path
377main.Append(CPPPATH=[Dir('ext')])

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

803
804# Sticky variables that should be exported
805export_vars = []
806Export('export_vars')
807
808# Walk the tree and execute all SConsopts scripts that wil add to the
809# above variables
810for bdir in [ base_dir ] + extras_dir_list:
353else:
354 extras_dir_list = []
355
356Export('base_dir')
357Export('extras_dir_list')
358
359# the ext directory should be on the #includes path
360main.Append(CPPPATH=[Dir('ext')])

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

786
787# Sticky variables that should be exported
788export_vars = []
789Export('export_vars')
790
791# Walk the tree and execute all SConsopts scripts that wil add to the
792# above variables
793for bdir in [ base_dir ] + extras_dir_list:
794 if not isdir(bdir):
795 print "Error: directory '%s' does not exist" % bdir
796 Exit(1)
811 for root, dirs, files in os.walk(bdir):
812 if 'SConsopts' in files:
813 print "Reading", joinpath(root, 'SConsopts')
814 SConscript(joinpath(root, 'SConsopts'))
815
816all_isa_list.sort()
817
818sticky_vars.AddVariables(

--- 232 unchanged lines hidden ---
797 for root, dirs, files in os.walk(bdir):
798 if 'SConsopts' in files:
799 print "Reading", joinpath(root, 'SConsopts')
800 SConscript(joinpath(root, 'SConsopts'))
801
802all_isa_list.sort()
803
804sticky_vars.AddVariables(

--- 232 unchanged lines hidden ---