+ v1 = make_version_list(v1)
+ v2 = make_version_list(v2)
+ # Compare corresponding elements of lists
+ for n1,n2 in zip(v1, v2):
+ if n1 < n2: return -1
+ if n1 > n2: return 1
+ # all corresponding values are equal... see if one has extra values
+ if len(v1) < len(v2): return -1
+ if len(v1) > len(v2): return 1
+ return 0
+
+########################################################################
+#
+# Set up the base build environment.
+#
+########################################################################
+use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
+ 'RANLIB' ])
+
+use_env = {}
+for key,val in os.environ.iteritems():
+ if key in use_vars or key.startswith("M5"):
+ use_env[key] = val
+
+env = Environment(ENV=use_env)
+env.root = Dir(".") # The current directory (where this file lives).
+env.srcdir = Dir("src") # The source directory
+
+########################################################################
+#
+# Mercurial Stuff.
+#
+# If the M5 directory is a mercurial repository, we should do some
+# extra things.
+#
+########################################################################
+
+hgdir = env.root.Dir(".hg")
+
+mercurial_style_message = """
+You're missing the M5 style hook.
+Please install the hook so we can ensure that all code fits a common style.
+
+All you'd need to do is add the following lines to your repository .hg/hgrc
+or your personal .hgrc
+----------------
+
+[extensions]
+style = %s/util/style.py
+
+[hooks]
+pretxncommit.style = python:style.check_whitespace
+""" % (env.root)
+
+mercurial_bin_not_found = """
+Mercurial binary cannot be found, unfortunately this means that we
+cannot easily determine the version of M5 that you are running and
+this makes error messages more difficult to collect. Please consider
+installing mercurial if you choose to post an error message
+"""
+
+mercurial_lib_not_found = """
+Mercurial libraries cannot be found, ignoring style hook
+If you are actually a M5 developer, please fix this and
+run the style hook. It is important.
+"""
+
+hg_info = "Unknown"
+if hgdir.exists():
+ # 1) Grab repository revision if we know it.
+ cmd = "hg id -n -i -t -b"
+ try:
+ hg_info = read_command(cmd, cwd=env.root.abspath).strip()
+ except OSError:
+ print mercurial_bin_not_found
+
+ # 2) Ensure that the style hook is in place.
+ try:
+ ui = None
+ if ARGUMENTS.get('IGNORE_STYLE') != 'True':
+ from mercurial import ui
+ ui = ui.ui()
+ except ImportError:
+ print mercurial_lib_not_found
+
+ if ui is not None:
+ ui.readconfig(hgdir.File('hgrc').abspath)
+ style_hook = ui.config('hooks', 'pretxncommit.style', None)
+
+ if not style_hook:
+ print mercurial_style_message
+ sys.exit(1)
+else:
+ print ".hg directory not found"
+env['HG_INFO'] = hg_info