+def fetch_git_revision ():
+ cmd = "git describe HEAD"
+ output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
+ rev = output[0].decode ('utf-8')
+ return rev
+
+def fetch_tarball_revision ():
+ if not os.path.exists ('libs/ardour/revision.cc'):
+ print 'This tarball was not created correctly - it is missing libs/ardour/revision.cc'
+ sys.exit (1)
+ with open('libs/ardour/revision.cc') as f:
+ content = f.readlines()
+ remove_punctuation_map = dict((ord(char), None) for char in '";')
+ return content[1].decode('utf-8').strip().split(' ')[7].translate (remove_punctuation_map)
+
+if os.path.isdir (os.path.join(os.getcwd(), '.git')):
+ rev = fetch_git_revision ()
+else:
+ rev = fetch_tarball_revision ()
+
+#
+# rev is now of the form MAJOR.MINOR-rev-commit
+#
+
+parts = rev.split ('.')
+MAJOR = parts[0]
+other = parts[1].split ('-')
+MINOR = other[0]
+MICRO = other[1]
+
+V = MAJOR + '.' + MINOR + '.' + MICRO
+#
+# it is important that VERSION *not* be unicode string
+# because if it is, it breaks waf somehow.
+#
+VERSION = V.encode ('ascii', 'ignore')
+APPNAME = 'Ardour' + MAJOR