Index: rtemstoolkit/git.py
===================================================================
--- rtemstoolkit/git.py	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/git.py	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -1,11 +1,8 @@
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
+# Copyright 2010-2015 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
 #
 # 1. Redistributions of source code must retain the above copyright notice,
@@ -62,12 +59,15 @@
         return exit_code, output
 
-    def __init__(self, _path, opts, macros = None):
+    def __init__(self, _path, opts = None, macros = None):
         self.path = _path
         self.opts = opts
-        if macros is None:
+        if macros is None and opts is not None:
             self.macros = opts.defaults
         else:
             self.macros = macros
-        self.git = self.macros.expand('%{__git}')
+        if self.macros is None:
+            self.git = 'git'
+        else:
+            self.git = self.macros.expand('%{__git}')
 
     def git_version(self):
@@ -87,4 +87,7 @@
         ec, output = self._run(['fetch'], check = True)
 
+    def merge(self):
+        ec, output = self._run(['merge'], check = True)
+
     def pull(self):
         ec, output = self._run(['pull'], check = True)
@@ -105,4 +108,12 @@
     def checkout(self, branch = 'master'):
         ec, output = self._run(['checkout', branch], check = True)
+
+    def submodule(self, module):
+        ec, output = self._run(['submodule', 'update', '--init', module], check = True)
+
+    def clean(self, args = []):
+        if type(args) == str:
+            args = [args]
+        ec, output = self._run(['clean'] + args, check = True)
 
     def status(self):
@@ -113,25 +124,31 @@
                 state = 'none'
                 for l in output.split('\n'):
-                    if l.startswith('# On branch '):
-                        _status['branch'] = l[len('# On branch '):]
-                    elif l.startswith('# Changes to be committed:'):
+                    if l.startswith('# '):
+                        l = l[2:]
+                    if l.startswith('On branch '):
+                        _status['branch'] = l[len('On branch '):]
+                    elif l.startswith('Changes to be committed:'):
                         state = 'staged'
-                    elif l.startswith('# Changes not staged for commit:'):
+                    elif l.startswith('Changes not staged for commit:'):
                         state = 'unstaged'
-                    elif l.startswith('# Untracked files:'):
+                    elif l.startswith('Untracked files:'):
                         state = 'untracked'
-                    elif state != 'none' and l[0] == '#':
-                        if l.strip() != '#' and not l.startswith('#   ('):
-                            if state not in _status:
-                                _status[state] = []
-                            l = l[1:]
-                            if ':' in l:
-                                l = l.split(':')[1]
-                            _status[state] += [l.strip()]
+                    elif l.startswith('HEAD detached'):
+                        state = 'detached'
+                    elif state != 'none' and len(l.strip()) != 0:
+                        if l[0].isspace():
+                            l = l.strip()
+                            if l[0] != '(':
+                                if state not in _status:
+                                    _status[state] = []
+                                l = l[1:]
+                                if ':' in l:
+                                    l = l.split(':')[1]
+                                _status[state] += [l.strip()]
         return _status
 
-    def clean(self):
+    def dirty(self):
         _status = self.status()
-        return len(_status) == 1 and 'branch' in _status
+        return not (len(_status) == 1 and 'branch' in _status)
 
     def valid(self):
Index: rtemstoolkit/options.py
===================================================================
--- rtemstoolkit/options.py	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/options.py	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -354,5 +354,5 @@
             repo_valid = '1'
             repo_head = repo.head()
-            repo_clean = repo.clean()
+            repo_clean = not repo.dirty()
             repo_id = repo_head
             if not repo_clean:
Index: rtemstoolkit/rld-rtems.cpp
===================================================================
--- rtemstoolkit/rld-rtems.cpp	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/rld-rtems.cpp	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -25,5 +25,5 @@
   namespace rtems
   {
-    static std::string _version = "4.12";
+    static std::string _version = RTEMS_VERSION;
     static std::string _path;
     static std::string _arch_bsp;
Index: rtemstoolkit/rld.cpp
===================================================================
--- rtemstoolkit/rld.cpp	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/rld.cpp	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -33,8 +33,4 @@
 #include <rld.h>
 
-#define RLD_VERSION_MAJOR   (1)
-#define RLD_VERSION_MINOR   (0)
-#define RLD_VERSION_RELEASE (0)
-
 namespace rld
 {
@@ -203,8 +199,5 @@
   version ()
   {
-    std::string v = (rld::to_string (RLD_VERSION_MAJOR) + '.' +
-                     rld::to_string (RLD_VERSION_MINOR) + '.' +
-                     rld::to_string (RLD_VERSION_RELEASE));
-    return v;
+    return RTEMS_RELEASE;
   }
 
@@ -212,5 +205,5 @@
   rtems_version ()
   {
-    return rld::to_string (RTEMS_VERSION);
+    return RTEMS_VERSION;
   }
 
Index: rtemstoolkit/version.py
===================================================================
--- rtemstoolkit/version.py	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/version.py	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -1,5 +1,5 @@
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
+# Copyright 2010-2015 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -30,19 +30,65 @@
 
 #
-# Manage paths locally. The internally the path is in Unix or shell format and
-# we convert to the native format when performing operations at the Python
-# level. This allows macro expansion to work.
+# To release RTEMS Tools create a git archive and then add a suitable VERSION
+# file to the top directory.
 #
 
-major = 0
-minor = 0
-revision = 0
+import sys
+
+import error
+import git
+import path
+
+#
+# Default to an internal string.
+#
+_version_str = '4.12.not_release'
+_released = False
+_git = False
+
+def _at():
+    return path.dirname(__file__)
+
+def _load_released_version():
+    global _released
+    global _version_str
+    at = _at()
+    for ver in [at, path.join(at, '..')]:
+        if path.exists(path.join(ver, 'VERSION')):
+            try:
+                with open(path.join(ver, 'VERSION')) as v:
+                    _version_str = v.readline().strip()
+                v.close()
+                _released = True
+            except:
+                raise error.general('Cannot access the VERSION file')
+    return _released
+
+def _load_git_version():
+    global _git
+    global _version_str
+    repo = git.repo(_at())
+    if repo.valid():
+        head = repo.head()
+        if repo.dirty():
+            modified = ' modified'
+        else:
+            modified = ''
+        _version_str = '%s (%s%s)' % (_version_str, head[0:12], modified)
+        _git = True
+    return _git
+
+def released():
+    return _load_released_version()
+
+def version_control():
+    return _load_git_version()
 
 def str():
-    return '%d.%d.%d'% (major, minor, revision)
+    if not _released and not _git:
+        if not _load_released_version():
+            _load_git_version()
+    return _version_str
 
 if __name__ == '__main__':
-    print('major = %d' % (major))
-    print('minor = %d' % (minor))
-    print('revision = %d' % (revision))
-    print('Version: %s' % (str()))
+    print 'Version: %s' % (str())
Index: rtemstoolkit/wscript
===================================================================
--- rtemstoolkit/wscript	(revision 04a52040aef69910e9ac2218fea48077e34d4017)
+++ rtemstoolkit/wscript	(revision efc4f099b459833cc424f133716824bc0efc060e)
@@ -34,8 +34,4 @@
 import sys
 
-version_major = 1
-version_minor = 0
-version_revision = 0
-
 #
 # Waf system setup. Allow more than one build in the same tree.
@@ -60,4 +56,9 @@
                   features = 'c', mandatory = False)
     conf.write_config_header('config.h')
+
+    conf.load('python')
+    conf.check_python_version((2,6,6))
+    conf.env['PYO'] = 0
+    conf.env['PYC'] = 0
 
 def build(bld):
@@ -126,5 +127,6 @@
               source = rld_source + rtems_utils + compression,
               defines = ['HAVE_CONFIG_H=1',
-                         'RTEMS_VERSION=' + bld.env.RTEMS_VERSION,
+                         'RTEMS_VERSION=\"%s\"' % (bld.env.RTEMS_VERSION),
+                         'RTEMS_RELEASE=\"%s\"' % (bld.env.RTEMS_RELEASE),
                          'FASTLZ_LEVEL=1'],
               includes = ['.'] + conf['includes'],
@@ -154,5 +156,5 @@
                   'version.py',
                   'windows.py'],
-        install_path = '${PREFIX}/share/rtems/rtemstoolkit')
+        install_path = '${PREFIX}/share/rtems')
 
 def rebuild(ctx):
