+# To speed things up, we only instantiate the build environments we
+# need. We try to identify the needed environment for each target; if
+# we can't, we fall back on instantiating all the environments just to
+# be safe.
+target_types = ['debug', 'opt', 'fast', 'prof', 'perf']
+obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
+ 'gpo' : 'perf'}
+
+def identifyTarget(t):
+ ext = t.split('.')[-1]
+ if ext in target_types:
+ return ext
+ if obj2target.has_key(ext):
+ return obj2target[ext]
+ match = re.search(r'/tests/([^/]+)/', t)
+ if match and match.group(1) in target_types:
+ return match.group(1)
+ return 'all'
+
+needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
+if 'all' in needed_envs:
+ needed_envs += target_types
+
+gem5_root = Dir('.').up().up().abspath
+def makeEnvirons(target, source, env):
+ # cause any later Source() calls to be fatal, as a diagnostic.
+ Source.done()
+
+ envList = []
+
+ # Debug binary
+ if 'debug' in needed_envs:
+ envList.append(
+ makeEnv(env, 'debug', '.do',
+ CCFLAGS = Split(ccflags['debug']),
+ CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
+ LINKFLAGS = Split(ldflags['debug'])))
+
+ # Optimized binary
+ if 'opt' in needed_envs:
+ envList.append(
+ makeEnv(env, 'opt', '.o',
+ CCFLAGS = Split(ccflags['opt']),
+ CPPDEFINES = ['TRACING_ON=1'],
+ LINKFLAGS = Split(ldflags['opt'])))
+
+ # "Fast" binary
+ if 'fast' in needed_envs:
+ envList.append(
+ makeEnv(env, 'fast', '.fo', strip = True,
+ CCFLAGS = Split(ccflags['fast']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['fast'])))
+
+ # Profiled binary using gprof
+ if 'prof' in needed_envs:
+ envList.append(
+ makeEnv(env, 'prof', '.po',
+ CCFLAGS = Split(ccflags['prof']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['prof'])))
+
+ # Profiled binary using google-pprof
+ if 'perf' in needed_envs:
+ envList.append(
+ makeEnv(env, 'perf', '.gpo',
+ CCFLAGS = Split(ccflags['perf']),
+ CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
+ LINKFLAGS = Split(ldflags['perf'])))
+
+ # Set up the regression tests for each build.
+ for e in envList:
+ SConscript(os.path.join(gem5_root, 'tests', 'SConscript'),
+ variant_dir = variantd('tests', e.Label),
+ exports = { 'env' : e }, duplicate = False)
+
+# The MakeEnvirons Builder defers the full dependency collection until
+# after processing the ISA definition (due to dynamically generated
+# source files). Add this dependency to all targets so they will wait
+# until the environments are completely set up. Otherwise, a second
+# process (e.g. -j2 or higher) will try to compile the requested target,
+# not know how, and fail.
+env.Append(BUILDERS = {'MakeEnvirons' :
+ Builder(action=MakeAction(makeEnvirons,
+ Transform("ENVIRONS", 1)))})
+
+isa_target = env['PHONY_BASE'] + '-deps'
+environs = env['PHONY_BASE'] + '-environs'
+env.Depends('#all-deps', isa_target)
+env.Depends('#all-environs', environs)
+env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA']))
+envSetup = env.MakeEnvirons(environs, isa_target)
+
+# make sure no -deps targets occur before all ISAs are complete
+env.Depends(isa_target, '#all-isas')
+# likewise for -environs targets and all the -deps targets
+env.Depends(environs, '#all-deps')