summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-08-03 18:19:54 -0700
committerNathan Binkert <nate@binkert.org>2008-08-03 18:19:54 -0700
commitede89c2d541051c2ed647e2967712e10b3c0fab0 (patch)
tree03f79b80ab56a55416bb2017d0ee7bec87b56242 /SConstruct
parent678abbc3646695f7d9693ce0757abaf7463d0354 (diff)
downloadgem5-ede89c2d541051c2ed647e2967712e10b3c0fab0.tar.xz
libm5: Create a libm5 static library for embedding m5.
This should allow m5 to be more easily embedded into other simulators. The m5 binary adds a simple main function which then calls into the m5 libarary to start the simulation. In order to make this work correctly, it was necessary embed python code directly into the library instead of the zipfile hack. This is because you can't just append the zipfile to the end of a library the way you can a binary. As a result, Python files that are part of the m5 simulator are now compile, marshalled, compressed, and then inserted into the library's data section with a certain symbol name. Additionally, a new Importer was needed to allow python to get at the embedded python code. Small additional changes include: - Get rid of the PYTHONHOME stuff since I don't think anyone ever used it, and it just confuses things. Easy enough to add back if I'm wrong. - Create a few new functions that are key to initializing and running the simulator: initSignals, initM5Python, m5Main. The original code for creating libm5 was inspired by a patch Michael Adler, though the code here was done by me.
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct38
1 files changed, 33 insertions, 5 deletions
diff --git a/SConstruct b/SConstruct
index 792cb7554..f7798b25e 100644
--- a/SConstruct
+++ b/SConstruct
@@ -424,11 +424,42 @@ scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
# replace the scanners list that has what we want
env['SCANNERS'] = scanners
+# Add a custom Check function to the Configure context so that we can
+# figure out if the compiler adds leading underscores to global
+# variables. This is needed for the autogenerated asm files that we
+# use for embedding the python code.
+def CheckLeading(context):
+ context.Message("Checking for leading underscore in global variables...")
+ # 1) Define a global variable called x from asm so the C compiler
+ # won't change the symbol at all.
+ # 2) Declare that variable.
+ # 3) Use the variable
+ #
+ # If the compiler prepends an underscore, this will successfully
+ # link because the external symbol 'x' will be called '_x' which
+ # was defined by the asm statement. If the compiler does not
+ # prepend an underscore, this will not successfully link because
+ # '_x' will have been defined by assembly, while the C portion of
+ # the code will be trying to use 'x'
+ ret = context.TryLink('''
+ asm(".globl _x; _x: .byte 0");
+ extern int x;
+ int main() { return x; }
+ ''', extension=".c")
+ context.env.Append(LEADING_UNDERSCORE=ret)
+ context.Result(ret)
+ return ret
+
# Platform-specific configuration. Note again that we assume that all
# builds under a given build root run on the same host platform.
conf = Configure(env,
conf_dir = joinpath(build_root, '.scons_config'),
- log_file = joinpath(build_root, 'scons_config.log'))
+ log_file = joinpath(build_root, 'scons_config.log'),
+ custom_tests = { 'CheckLeading' : CheckLeading })
+
+# Check for leading underscores. Don't really need to worry either
+# way so don't need to check the return code.
+conf.CheckLeading()
# Check if we should compile a 64 bit binary on Mac OS X/Darwin
try:
@@ -596,9 +627,6 @@ 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),
- ('PYTHONHOME',
- 'Override the default PYTHONHOME for this system (use with caution)',
- '%s:%s' % (sys.prefix, sys.exec_prefix)),
)
nonsticky_opts.AddOptions(
@@ -609,7 +637,7 @@ nonsticky_opts.AddOptions(
env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
- 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
+ 'USE_CHECKER', 'TARGET_ISA']
# Define a handy 'no-op' action
def no_action(target, source, env):