+ 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 main 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
+
+main = Environment(ENV=use_env)
+main.root = Dir(".") # The current directory (where this file lives).
+main.srcdir = Dir("src") # The source directory
+
+########################################################################
+#
+# Mercurial Stuff.
+#
+# If the M5 directory is a mercurial repository, we should do some
+# extra things.
+#
+########################################################################
+
+hgdir = main.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
+""" % (main.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=main.root.abspath).strip()
+ except OSError:
+ print mercurial_bin_not_found