SCons: add code to provide a libm5 shared library.
Targets look like libm5_debug.so. This target can be dynamically linked into another C++ program and provide just about all of the M5 features. Additionally, this library is a standalone module that can be imported into python with an "import libm5_debug" type command line.
This commit is contained in:
parent
0b83563a9c
commit
a589eb4053
3 changed files with 47 additions and 28 deletions
|
@ -110,7 +110,10 @@ m4env.M4(target=File('libelf_fsize.c'),
|
||||||
source=[File('elf_types.m4'), File('libelf_fsize.m4')])
|
source=[File('elf_types.m4'), File('libelf_fsize.m4')])
|
||||||
m4env.M4(target=File('libelf_msize.c'),
|
m4env.M4(target=File('libelf_msize.c'),
|
||||||
source=[File('elf_types.m4'), File('libelf_msize.m4')])
|
source=[File('elf_types.m4'), File('libelf_msize.m4')])
|
||||||
m4env.Library('elf', elf_files)
|
|
||||||
|
# Build libelf as a static library with PIC code so it can be linked
|
||||||
|
# into either m5 or the library
|
||||||
|
m4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
|
||||||
|
|
||||||
env.Append(CPPPATH=Dir('.'))
|
env.Append(CPPPATH=Dir('.'))
|
||||||
env.Append(LIBS=['elf'])
|
env.Append(LIBS=['elf'])
|
||||||
|
|
|
@ -934,21 +934,26 @@ envList = []
|
||||||
# Object nodes (including an extra one for date.cc). We explicitly
|
# Object nodes (including an extra one for date.cc). We explicitly
|
||||||
# add the Object nodes so we can set up special dependencies for
|
# add the Object nodes so we can set up special dependencies for
|
||||||
# date.cc.
|
# date.cc.
|
||||||
def make_objs(sources, env):
|
def make_objs(sources, env, static):
|
||||||
objs = [env.Object(s) for s in sources]
|
if static:
|
||||||
|
XObject = env.StaticObject
|
||||||
|
else:
|
||||||
|
XObject = env.SharedObject
|
||||||
|
|
||||||
|
objs = [ XObject(s) for s in sources ]
|
||||||
|
|
||||||
# make date.cc depend on all other objects so it always gets
|
# make date.cc depend on all other objects so it always gets
|
||||||
# recompiled whenever anything else does
|
# recompiled whenever anything else does
|
||||||
date_obj = env.Object('base/date.cc')
|
date_obj = XObject('base/date.cc')
|
||||||
|
|
||||||
# Make the generation of program_info.cc dependend on all
|
# Make the generation of program_info.cc dependend on all
|
||||||
# the other cc files and the compiling of program_info.cc
|
# the other cc files and the compiling of program_info.cc
|
||||||
# dependent on all the objects but program_info.o
|
# dependent on all the objects but program_info.o
|
||||||
pinfo_obj = env.Object('base/program_info.cc')
|
pinfo_obj = XObject('base/program_info.cc')
|
||||||
env.Depends('base/program_info.cc', sources)
|
env.Depends('base/program_info.cc', sources)
|
||||||
env.Depends(date_obj, objs)
|
env.Depends(date_obj, objs)
|
||||||
env.Depends(pinfo_obj, objs)
|
env.Depends(pinfo_obj, objs)
|
||||||
objs.extend([date_obj,pinfo_obj])
|
objs.extend([date_obj, pinfo_obj])
|
||||||
return objs
|
return objs
|
||||||
|
|
||||||
# Function to create a new build environment as clone of current
|
# Function to create a new build environment as clone of current
|
||||||
|
@ -956,46 +961,50 @@ def make_objs(sources, env):
|
||||||
# binary. Additional keyword arguments are appended to corresponding
|
# binary. Additional keyword arguments are appended to corresponding
|
||||||
# build environment vars.
|
# build environment vars.
|
||||||
def makeEnv(label, objsfx, strip = False, **kwargs):
|
def makeEnv(label, objsfx, strip = False, **kwargs):
|
||||||
newEnv = env.Copy(OBJSUFFIX=objsfx)
|
# SCons doesn't know to append a library suffix when there is a '.' in the
|
||||||
newEnv.Label = label
|
# name. Use '_' instead.
|
||||||
newEnv.Append(**kwargs)
|
libname = 'm5_' + label
|
||||||
|
exename = 'm5.' + label
|
||||||
|
|
||||||
swig_env = newEnv.Copy()
|
new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
|
||||||
|
new_env.Label = label
|
||||||
|
new_env.Append(**kwargs)
|
||||||
|
|
||||||
|
swig_env = new_env.Copy()
|
||||||
if env['GCC']:
|
if env['GCC']:
|
||||||
swig_env.Append(CCFLAGS='-Wno-uninitialized')
|
swig_env.Append(CCFLAGS='-Wno-uninitialized')
|
||||||
swig_env.Append(CCFLAGS='-Wno-sign-compare')
|
swig_env.Append(CCFLAGS='-Wno-sign-compare')
|
||||||
swig_env.Append(CCFLAGS='-Wno-parentheses')
|
swig_env.Append(CCFLAGS='-Wno-parentheses')
|
||||||
swig_objs = [ swig_env.Object(s) for s in cc_swig_sources ]
|
|
||||||
|
static_objs = make_objs(cc_lib_sources, new_env, static=True)
|
||||||
|
shared_objs = make_objs(cc_lib_sources, new_env, static=False)
|
||||||
|
static_objs += [ swig_env.StaticObject(s) for s in cc_swig_sources ]
|
||||||
|
shared_objs += [ swig_env.SharedObject(s) for s in cc_swig_sources ]
|
||||||
|
|
||||||
# First make a library of everything but main() so other programs can
|
# First make a library of everything but main() so other programs can
|
||||||
# link against m5.
|
# link against m5.
|
||||||
#
|
static_lib = new_env.StaticLibrary(libname, static_objs + static_objs)
|
||||||
# SCons doesn't know to append a library suffix when there is a '.' in the
|
shared_lib = new_env.SharedLibrary(libname, shared_objs + shared_objs)
|
||||||
# name. Use '_' instead.
|
|
||||||
|
|
||||||
m5lib = newEnv.Library('m5_' + label,
|
|
||||||
make_objs(cc_lib_sources, newEnv) + swig_objs)
|
|
||||||
|
|
||||||
for target, sources in unit_tests:
|
for target, sources in unit_tests:
|
||||||
objs = [ newEnv.StaticObject(s) for s in sources ]
|
objs = [ new_env.StaticObject(s) for s in sources ]
|
||||||
newEnv.Program("unittest/%s.%s" % (target, label), objs + m5lib)
|
new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib)
|
||||||
|
|
||||||
# Now link a stub with main() and the library.
|
# Now link a stub with main() and the static library.
|
||||||
exe = 'm5.' + label # final executable
|
objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib
|
||||||
objects = [newEnv.Object(s) for s in cc_bin_sources] + m5lib
|
|
||||||
if strip:
|
if strip:
|
||||||
unstripped_exe = exe + '.unstripped'
|
unstripped_exe = exename + '.unstripped'
|
||||||
newEnv.Program(unstripped_exe, objects)
|
new_env.Program(unstripped_exe, objects)
|
||||||
if sys.platform == 'sunos5':
|
if sys.platform == 'sunos5':
|
||||||
cmd = 'cp $SOURCE $TARGET; strip $TARGET'
|
cmd = 'cp $SOURCE $TARGET; strip $TARGET'
|
||||||
else:
|
else:
|
||||||
cmd = 'strip $SOURCE -o $TARGET'
|
cmd = 'strip $SOURCE -o $TARGET'
|
||||||
targets = newEnv.Command(exe, unstripped_exe, cmd)
|
targets = new_env.Command(exename, unstripped_exe, cmd)
|
||||||
else:
|
else:
|
||||||
targets = newEnv.Program(exe, objects)
|
targets = new_env.Program(exename, objects)
|
||||||
|
|
||||||
newEnv.M5Binary = targets[0]
|
new_env.M5Binary = targets[0]
|
||||||
envList.append(newEnv)
|
envList.append(new_env)
|
||||||
|
|
||||||
# Debug binary
|
# Debug binary
|
||||||
ccflags = {}
|
ccflags = {}
|
||||||
|
|
|
@ -200,3 +200,10 @@ m5Main(int argc, char **argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyMODINIT_FUNC
|
||||||
|
initm5(void)
|
||||||
|
{
|
||||||
|
initM5Python();
|
||||||
|
PyImport_ImportModule(PyCC("m5"));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue