Build: Semantic versioning support

This patch modifies the project's versioning
schema to support semantic versioning.

The new schema going forward is:

<Major>.<Minor>.Hotfix>

The patch updates:

• The TF-M version macros
* Previous releases' documentation
* The version detection logic for documentation to support
  old and new schema

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
Change-Id: I6baa0cab849d656c8d756d4a70c10c258ef3001c
diff --git a/tools/documentation/tfm_cmake_defaults.py b/tools/documentation/tfm_cmake_defaults.py
index a5761c2..5fb7b86 100644
--- a/tools/documentation/tfm_cmake_defaults.py
+++ b/tools/documentation/tfm_cmake_defaults.py
@@ -163,15 +163,34 @@
 
 # Version will be retrieved in that order Git -> Cmake -> Boilerplate
 try:
+    vrex = re.compile(r'TF-Mv(?P<VER_MAJ>\d{1,2}).(?P<VER_MIN>\d{1,2}).?'
+                      r'(?P<VER_HOT>\d{0,2})(?P<RC>\-RC\d)?-'
+                      r'(?P<PATCH_NO>\d+)-(?P<GIT_HASH>[a-g0-9]+)')
     tfm_def_tfm_ver_full = check_output(["git",
                                          "describe",
-                                         "--tags"]).decode('UTF-8').strip()
-    proj, ver, commit_no, git_hash = tfm_def_tfm_ver_full.split("-")
+                                         "--tags",
+                                         "--long"]).decode('UTF-8').strip()
+
+    _v = vrex.search(tfm_def_tfm_ver_full)
+    proj = "TF-M"
+    version  = [ _v.group("VER_MAJ"),
+                 _v.group("VER_MIN"),
+                 _v.group("VER_HOT"),
+                 _v.group("RC")]
+    commit_no  = _v.group("PATCH_NO")
+    git_hash  = _v.group("GIT_HASH")
+
+    # Sanitize the verison and remove empty entries
+    version = [i.replace("-","") for i in version if i]
+    tfm_def_tfm_ver_full = ".".join(version)
+    tfm_def_tfm_ver_shrt = ".".join(version[:2])
 
     if (int(commit_no) > 0):
-        tfm_def_tfm_ver_shrt = tfm_def_tfm_ver_full
-    else:
-        tfm_def_tfm_ver_shrt = proj + ver
+        tfm_def_tfm_ver_full = "%s+ ( #%s )" % (tfm_def_tfm_ver_full, git_hash)
+        tfm_def_tfm_ver_shrt = "%s+ ( #%s )" % (tfm_def_tfm_ver_shrt, git_hash)
+
+    tfm_def_tfm_ver_shrt = tfm_def_tfm_ver_full
+
 
 except Exception as E:
     try: