X86: Move startup code to the system object to initialize a Linux system.
[gem5.git] / SConstruct
index 82a281190c80aa4bf1f11cf286ce6ea853bf1341..062df47d6db3d4b59728545cd2dcbdc4733539d6 100644 (file)
 
 import sys
 import os
-import subprocess
 
 from os.path import isdir, join as joinpath
 
+import SCons
+
 # Check for recent-enough Python and SCons versions.  If your system's
 # default installation of Python is not recent enough, you can use a
 # non-default installation of the Python interpreter by either (1)
@@ -77,6 +78,10 @@ from os.path import isdir, join as joinpath
 # scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
 EnsurePythonVersion(2,4)
 
+# Import subprocess after we check the version since it doesn't exist in
+# Python < 2.4.
+import subprocess
+
 # Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
 # 3-element version number.
 min_scons_version = (0,96,91)
@@ -118,7 +123,7 @@ pretxncommit.style = python:style.check_whitespace
 """ % (ROOT)
         sys.exit(1)
 
-if ARGUMENTS['IGNORE_STYLE'] != 'True' and isdir(joinpath(ROOT, '.hg')):
+if ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
     try:
         from mercurial import ui
         check_style_hook(ui.ui())
@@ -236,7 +241,7 @@ if False:
     env.TargetSignatures('content')
 
 # M5_PLY is used by isa_parser.py to find the PLY package.
-env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
+env.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
 env['GCC'] = False
 env['SUNCC'] = False
 env['ICC'] = False
@@ -329,6 +334,41 @@ conf = Configure(env,
                  conf_dir = joinpath(build_root, '.scons_config'),
                  log_file = joinpath(build_root, 'scons_config.log'))
 
+# Check if we should compile a 64 bit binary on Mac OS X/Darwin
+try:
+    import platform
+    uname = platform.uname()
+    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
+        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
+               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+               close_fds=True).communicate()[0][0]):
+            env.Append(CCFLAGS='-arch x86_64')
+            env.Append(CFLAGS='-arch x86_64')
+            env.Append(LINKFLAGS='-arch x86_64')
+            env.Append(ASFLAGS='-arch x86_64')
+            env['OSX64bit'] = True
+except:
+    pass
+
+# Recent versions of scons substitute a "Null" object for Configure()
+# when configuration isn't necessary, e.g., if the "--help" option is
+# present.  Unfortuantely this Null object always returns false,
+# breaking all our configuration checks.  We replace it with our own
+# more optimistic null object that returns True instead.
+if not conf:
+    def NullCheck(*args, **kwargs):
+        return True
+
+    class NullConf:
+        def __init__(self, env):
+            self.env = env
+        def Finish(self):
+            return self.env
+        def __getattr__(self, mname):
+            return NullCheck
+
+    conf = NullConf(env)
+
 # Find Python include and library directories for embedding the
 # interpreter.  For consistency, we will use the same Python
 # installation used to run scons (and thus this script).  If you want
@@ -435,14 +475,19 @@ all_isa_list.sort()
 all_cpu_list.sort()
 default_cpus.sort()
 
-def ExtraPathValidator(key, val, env):
+def PathListMakeAbsolute(val):
+    if not val:
+        return val
+    f = lambda p: os.path.abspath(os.path.expanduser(p))
+    return ':'.join(map(f, val.split(':')))
+
+def PathListAllExist(key, val, env):
     if not val:
         return
     paths = val.split(':')
     for path in paths:
-        path = os.path.expanduser(path)
         if not isdir(path):
-            raise AttributeError, "Invalid path: '%s'" % path
+            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
 
 sticky_opts.AddOptions(
     EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
@@ -472,7 +517,7 @@ sticky_opts.AddOptions(
      'Override the default PYTHONHOME for this system (use with caution)',
      '%s:%s' % (sys.prefix, sys.exec_prefix)),
     ('EXTRAS', 'Add Extra directories to the compilation', '',
-     ExtraPathValidator)
+     PathListAllExist, PathListMakeAbsolute)
     )
 
 nonsticky_opts.AddOptions(