diff options
-rw-r--r-- | SConstruct | 101 | ||||
-rw-r--r-- | src/SConscript | 39 |
2 files changed, 80 insertions, 60 deletions
diff --git a/SConstruct b/SConstruct index 062df47d6..6e2d170f3 100644 --- a/SConstruct +++ b/SConstruct @@ -205,6 +205,10 @@ for t in abs_targets: if build_path not in build_paths: build_paths.append(build_path) +# Make sure build_root exists (might not if this is the first build there) +if not isdir(build_root): + os.mkdir(build_root) + ################################################### # # Set up the default build environment. This environment is copied @@ -216,14 +220,6 @@ env = Environment(ENV = os.environ, # inherit user's environment vars ROOT = ROOT, SRCDIR = SRCDIR) -#Parse CC/CXX early so that we use the correct compiler for -# to test for dependencies/versions/libraries/includes -if ARGUMENTS.get('CC', None): - env['CC'] = ARGUMENTS.get('CC') - -if ARGUMENTS.get('CXX', None): - env['CXX'] = ARGUMENTS.get('CXX') - Export('env') env.SConsignFile(joinpath(build_root,"sconsign")) @@ -240,6 +236,61 @@ env.SetOption('duplicate', 'soft-copy') if False: env.TargetSignatures('content') +# +# Set up global sticky options... these are common to an entire build +# tree (not specific to a particular build like ALPHA_SE) +# + +# Option validators & converters for global sticky options +def PathListMakeAbsolute(val): + if not val: + return val + f = lambda p: os.path.abspath(os.path.expanduser(p)) + return ':'.join(map(f, val.split(':'))) + +def PathListAllExist(key, val, env): + if not val: + return + paths = val.split(':') + for path in paths: + if not isdir(path): + raise SCons.Errors.UserError("Path does not exist: '%s'" % path) + +global_sticky_opts_file = joinpath(build_root, 'options.global') + +global_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) + +global_sticky_opts.AddOptions( + ('CC', 'C compiler', os.environ.get('CC', env['CC'])), + ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), + ('EXTRAS', 'Add Extra directories to the compilation', '', + PathListAllExist, PathListMakeAbsolute) + ) + + +# base help text +help_text = ''' +Usage: scons [scons options] [build options] [target(s)] + +''' + +help_text += "Global sticky options:\n" \ + + global_sticky_opts.GenerateHelpText(env) + +# Update env with values from ARGUMENTS & file global_sticky_opts_file +global_sticky_opts.Update(env) + +# Save sticky option settings back to current options file +global_sticky_opts.Save(global_sticky_opts_file, env) + +# Parse EXTRAS option to build list of all directories where we're +# look for sources etc. This list is exported as base_dir_list. +base_dir_list = [ROOT] +if env['EXTRAS']: + base_dir_list += env['EXTRAS'].split(':') + +Export('base_dir_list') + # M5_PLY is used by isa_parser.py to find the PLY package. env.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) env['GCC'] = False @@ -467,28 +518,16 @@ Export('nonsticky_opts') # Walk the tree and execute all SConsopts scripts that wil add to the # above options -for root, dirs, files in os.walk('.'): - if 'SConsopts' in files: - SConscript(os.path.join(root, 'SConsopts')) +for base_dir in base_dir_list: + for root, dirs, files in os.walk(base_dir): + if 'SConsopts' in files: + print "Reading", os.path.join(root, 'SConsopts') + SConscript(os.path.join(root, 'SConsopts')) all_isa_list.sort() all_cpu_list.sort() default_cpus.sort() -def PathListMakeAbsolute(val): - if not val: - return val - f = lambda p: os.path.abspath(os.path.expanduser(p)) - return ':'.join(map(f, val.split(':'))) - -def PathListAllExist(key, val, env): - if not val: - return - paths = val.split(':') - for path in paths: - if not isdir(path): - raise SCons.Errors.UserError("Path does not exist: '%s'" % path) - sticky_opts.AddOptions( EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), BoolOption('FULL_SYSTEM', 'Full-system support', False), @@ -509,15 +548,11 @@ sticky_opts.AddOptions( BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), - ('CC', 'C compiler', os.environ.get('CC', env['CC'])), - ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), BoolOption('BATCH', 'Use batch pool for build and tests', False), ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), ('PYTHONHOME', 'Override the default PYTHONHOME for this system (use with caution)', '%s:%s' % (sys.prefix, sys.exec_prefix)), - ('EXTRAS', 'Add Extra directories to the compilation', '', - PathListAllExist, PathListMakeAbsolute) ) nonsticky_opts.AddOptions( @@ -607,12 +642,6 @@ concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', env.Append(BUILDERS = { 'Concat' : concat_builder }) -# base help text -help_text = ''' -Usage: scons [scons options] [build options] [target(s)] - -''' - # libelf build is shared across all configs in the build root. env.SConscript('ext/libelf/SConscript', build_dir = joinpath(build_root, 'libelf'), @@ -712,7 +741,7 @@ for build_path in build_paths: sticky_opts.Update(env) nonsticky_opts.Update(env) - help_text += "Sticky options for %s:\n" % build_dir \ + help_text += "\nSticky options for %s:\n" % build_dir \ + sticky_opts.GenerateHelpText(env) \ + "\nNon-sticky options for %s:\n" % build_dir \ + nonsticky_opts.GenerateHelpText(env) diff --git a/src/SConscript b/src/SConscript index 8e6e1b45e..7163e55d7 100644 --- a/src/SConscript +++ b/src/SConscript @@ -33,7 +33,7 @@ import os import sys from os.path import basename -from os.path import join as joinpath +from os.path import isdir, join as joinpath from os.path import exists from os.path import isdir from os.path import isfile @@ -181,31 +181,22 @@ env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())]) ######################################################################## # -# Walk the tree and execute all SConscripts +# Walk the tree and execute all SConscripts in 'src' subdirectories # -srcdir = env['SRCDIR'] -for root, dirs, files in os.walk(srcdir, topdown=True): - if root == srcdir: - # we don't want to recurse back into this SConscript - continue - if 'SConscript' in files: - # strip off the srcdir part since scons will try to find the - # script in the build directory - base = root[len(srcdir) + 1:] - SConscript(joinpath(base, 'SConscript')) - -extra_string = env['EXTRAS'] -if extra_string and extra_string != '' and not extra_string.isspace(): - for extra in extra_string.split(':'): - print 'Adding', extra, 'to source directory list' - env.Append(CPPPATH=[Dir(extra)]) - for root, dirs, files in os.walk(extra, topdown=True): - if 'SConscript' in files: - subdir = root[len(os.path.dirname(extra))+1:] - print ' Found SConscript in', subdir - build_dir = joinpath(env['BUILDDIR'], subdir) - SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) +for base_dir in base_dir_list: + src_dir = joinpath(base_dir, 'src') + if not isdir(src_dir): + continue + here = Dir('.').srcnode().abspath + for root, dirs, files in os.walk(src_dir, topdown=True): + if root == here: + # we don't want to recurse back into this SConscript + continue + + if 'SConscript' in files: + build_dir = joinpath(env['BUILDDIR'], root[len(src_dir) + 1:]) + SConscript(joinpath(root, 'SConscript'), build_dir=build_dir) for opt in env.ExportOptions: env.ConfigFile(opt) |