+def makeEnv(env, label, objsfx, strip = False, **kwargs):
+ # SCons doesn't know to append a library suffix when there is a '.' in the
+ # name. Use '_' instead.
+ libname = variant('gem5_' + label)
+ exename = variant('gem5.' + label)
+ secondary_exename = variant('m5.' + label)
+
+ new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
+ new_env.Label = label
+ new_env.Append(**kwargs)
+
+ swig_env = new_env.Clone()
+
+ # Both gcc and clang have issues with unused labels and values in
+ # the SWIG generated code
+ swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value'])
+
+ # Add additional warnings here that should not be applied to
+ # the SWIG generated code
+ new_env.Append(CXXFLAGS='-Wmissing-declarations')
+
+ if env['GCC']:
+ # Depending on the SWIG version, we also need to supress
+ # warnings about uninitialized variables and missing field
+ # initializers.
+ swig_env.Append(CCFLAGS=['-Wno-uninitialized',
+ '-Wno-missing-field-initializers',
+ '-Wno-unused-but-set-variable'])
+
+ # If gcc supports it, also warn for deletion of derived
+ # classes with non-virtual desctructors. For gcc >= 4.7 we
+ # also have to disable warnings about the SWIG code having
+ # potentially uninitialized variables.
+ if compareVersions(env['GCC_VERSION'], '4.7') >= 0:
+ new_env.Append(CXXFLAGS='-Wdelete-non-virtual-dtor')
+ swig_env.Append(CCFLAGS='-Wno-maybe-uninitialized')
+
+ # Only gcc >= 4.9 supports UBSan, so check both the version
+ # and the command-line option before adding the compiler and
+ # linker flags.
+ if GetOption('with_ubsan') and \
+ compareVersions(env['GCC_VERSION'], '4.9') >= 0:
+ new_env.Append(CCFLAGS='-fsanitize=undefined')
+ new_env.Append(LINKFLAGS='-fsanitize=undefined')
+
+ if env['CLANG']:
+ # Always enable the warning for deletion of derived classes
+ # with non-virtual destructors
+ new_env.Append(CXXFLAGS=['-Wdelete-non-virtual-dtor'])
+
+ swig_env.Append(CCFLAGS=[
+ # Some versions of SWIG can return uninitialized values
+ '-Wno-sometimes-uninitialized',
+ # Register storage is requested in a lot of places in
+ # SWIG-generated code.
+ '-Wno-deprecated-register',
+ ])
+
+ # All supported clang versions have support for UBSan, so if
+ # asked to use it, append the compiler and linker flags.
+ if GetOption('with_ubsan'):
+ new_env.Append(CCFLAGS='-fsanitize=undefined')
+ new_env.Append(LINKFLAGS='-fsanitize=undefined')
+
+ werror_env = new_env.Clone()
+ werror_env.Append(CCFLAGS='-Werror')
+
+ def make_obj(source, static, extra_deps = None):
+ '''This function adds the specified source to the correct
+ build environment, and returns the corresponding SCons Object
+ nodes'''
+
+ if source.swig:
+ env = swig_env
+ elif source.Werror:
+ env = werror_env
+ else:
+ env = new_env
+
+ if static:
+ obj = env.StaticObject(source.tnode)
+ else:
+ obj = env.SharedObject(source.tnode)
+
+ if extra_deps:
+ env.Depends(obj, extra_deps)
+
+ return obj
+
+ lib_guards = {'main': False, 'skip_lib': False}
+
+ # Without Python, leave out all SWIG and Python content from the
+ # library builds. The option doesn't affect gem5 built as a program
+ if GetOption('without_python'):
+ lib_guards['skip_no_python'] = False
+
+ static_objs = [ make_obj(s, True) for s in Source.get(**lib_guards) ]
+ shared_objs = [ make_obj(s, False) for s in Source.get(**lib_guards) ]
+
+ static_date = make_obj(date_source, static=True, extra_deps=static_objs)
+ static_objs.append(static_date)
+
+ shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
+ shared_objs.append(shared_date)
+
+ # First make a library of everything but main() so other programs can
+ # link against m5.
+ static_lib = new_env.StaticLibrary(libname, static_objs)
+ shared_lib = new_env.SharedLibrary(libname, shared_objs)
+
+ # Now link a stub with main() and the static library.
+ main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
+
+ for test in UnitTest.all:
+ flags = { test.target : True }
+ test_sources = Source.get(**flags)
+ test_objs = [ make_obj(s, static=True) for s in test_sources ]
+ if test.main:
+ test_objs += main_objs
+ path = variant('unittest/%s.%s' % (test.target, label))
+ new_env.Program(path, test_objs + static_objs)
+
+ progname = exename
+ if strip:
+ progname += '.unstripped'
+
+ targets = new_env.Program(progname, main_objs + static_objs)
+