summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-10-09 04:58:23 -0700
committerNathan Binkert <nate@binkert.org>2008-10-09 04:58:23 -0700
commita589eb4053d9a902f9e9047830955963aec94e64 (patch)
tree632750baf207005392f7cfc7ab170576dc04d18c
parent0b83563a9c7368ffdb82d70054ceda3cb7f3828f (diff)
downloadgem5-a589eb4053d9a902f9e9047830955963aec94e64.tar.xz
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.
-rw-r--r--ext/libelf/SConscript5
-rw-r--r--src/SConscript63
-rw-r--r--src/sim/init.cc7
3 files changed, 47 insertions, 28 deletions
diff --git a/ext/libelf/SConscript b/ext/libelf/SConscript
index 3db526c13..ab85308de 100644
--- a/ext/libelf/SConscript
+++ b/ext/libelf/SConscript
@@ -110,7 +110,10 @@ m4env.M4(target=File('libelf_fsize.c'),
source=[File('elf_types.m4'), File('libelf_fsize.m4')])
m4env.M4(target=File('libelf_msize.c'),
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(LIBS=['elf'])
diff --git a/src/SConscript b/src/SConscript
index 6b2ea4d60..1b968ec90 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -934,21 +934,26 @@ envList = []
# Object nodes (including an extra one for date.cc). We explicitly
# add the Object nodes so we can set up special dependencies for
# date.cc.
-def make_objs(sources, env):
- objs = [env.Object(s) for s in sources]
+def make_objs(sources, env, static):
+ 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
# 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
# the other cc files and the compiling of program_info.cc
# 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(date_obj, objs)
env.Depends(pinfo_obj, objs)
- objs.extend([date_obj,pinfo_obj])
+ objs.extend([date_obj, pinfo_obj])
return objs
# 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
# build environment vars.
def makeEnv(label, objsfx, strip = False, **kwargs):
- newEnv = env.Copy(OBJSUFFIX=objsfx)
- newEnv.Label = label
- newEnv.Append(**kwargs)
+ # SCons doesn't know to append a library suffix when there is a '.' in the
+ # name. Use '_' instead.
+ libname = 'm5_' + label
+ exename = 'm5.' + label
+
+ new_env = env.Copy(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
+ new_env.Label = label
+ new_env.Append(**kwargs)
- swig_env = newEnv.Copy()
+ swig_env = new_env.Copy()
if env['GCC']:
swig_env.Append(CCFLAGS='-Wno-uninitialized')
swig_env.Append(CCFLAGS='-Wno-sign-compare')
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
# link against m5.
- #
- # SCons doesn't know to append a library suffix when there is a '.' in the
- # name. Use '_' instead.
-
- m5lib = newEnv.Library('m5_' + label,
- make_objs(cc_lib_sources, newEnv) + swig_objs)
+ static_lib = new_env.StaticLibrary(libname, static_objs + static_objs)
+ shared_lib = new_env.SharedLibrary(libname, shared_objs + shared_objs)
for target, sources in unit_tests:
- objs = [ newEnv.StaticObject(s) for s in sources ]
- newEnv.Program("unittest/%s.%s" % (target, label), objs + m5lib)
+ objs = [ new_env.StaticObject(s) for s in sources ]
+ new_env.Program("unittest/%s.%s" % (target, label), objs + static_lib)
- # Now link a stub with main() and the library.
- exe = 'm5.' + label # final executable
- objects = [newEnv.Object(s) for s in cc_bin_sources] + m5lib
+ # Now link a stub with main() and the static library.
+ objects = [new_env.Object(s) for s in cc_bin_sources] + static_lib
if strip:
- unstripped_exe = exe + '.unstripped'
- newEnv.Program(unstripped_exe, objects)
+ unstripped_exe = exename + '.unstripped'
+ new_env.Program(unstripped_exe, objects)
if sys.platform == 'sunos5':
cmd = 'cp $SOURCE $TARGET; strip $TARGET'
else:
cmd = 'strip $SOURCE -o $TARGET'
- targets = newEnv.Command(exe, unstripped_exe, cmd)
+ targets = new_env.Command(exename, unstripped_exe, cmd)
else:
- targets = newEnv.Program(exe, objects)
+ targets = new_env.Program(exename, objects)
- newEnv.M5Binary = targets[0]
- envList.append(newEnv)
+ new_env.M5Binary = targets[0]
+ envList.append(new_env)
# Debug binary
ccflags = {}
diff --git a/src/sim/init.cc b/src/sim/init.cc
index 804389dae..66eddfb6f 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -200,3 +200,10 @@ m5Main(int argc, char **argv)
return 0;
}
+
+PyMODINIT_FUNC
+initm5(void)
+{
+ initM5Python();
+ PyImport_ImportModule(PyCC("m5"));
+}