From 7eedb6ec56545f556a40ab9ce423d511e03e36da Mon Sep 17 00:00:00 2001
From: Jerome Martin <jxm@netiant.com>
Date: Mon, 19 May 2014 22:58:45 +0200
Subject: [PATCH] Makefile: VERSION uses "~" for "-" in git tags

* This makes for better version comparison in distributions.
  In Debian, 3.0~rc1 < 3.0 < 3.0-rc1.
* Added version target to display computed version string
* Use the same variable for rpm and deb changelogs
---
 Makefile | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index c723d0f..6e80575 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,13 @@
 
 NAME = rtslib
 GIT_BRANCH = $$(git branch | grep \* | tr -d \*)
-VERSION = $$(basename $$(git describe --tags | tr - . | grep -o '[0-9].*$$'))
+GIT_DESC = $$(basename $$(git describe --tags | grep -o '[0-9].*$$'))
+GIT_LAST_TAG = $$(git describe --tags --abbrev=0 | grep -o '[0-9].*$$')
+GIT_PKG_TAG = $$(echo $(GIT_LAST_TAG) | tr - \~)
+VERSION = $$(echo $(GIT_DESC) | sed s/^$(GIT_LAST_TAG)/$(GIT_PKG_TAG)/)
+
+version:
+	@echo $(VERSION)
 
 all:
 	@echo "Usage:"
@@ -95,7 +101,7 @@ build/release-stamp:
 		rm -r rpm
 	@echo "Generating rpm changelog..."
 	@( \
-		version=$$(basename $$(git describe HEAD --tags | tr - . | grep -o '[0-9].*$$')); \
+		version=$(VERSION); \
 		author=$$(git show HEAD --format="format:%an <%ae>" -s); \
 		date=$$(git show HEAD --format="format:%ad" -s \
 			| awk '{print $$1,$$2,$$3,$$5}'); \
@@ -105,7 +111,7 @@ build/release-stamp:
 	) >> $$(ls build/${NAME}-${VERSION}/*.spec)
 	@echo "Generating debian changelog..."
 	@( \
-		version=$$(basename $$(git describe HEAD --tags | tr - . | grep -o '[0-9].*$$')); \
+		version=$(VERSION); \
 		author=$$(git show HEAD --format="format:%an <%ae>" -s); \
 		date=$$(git show HEAD --format="format:%aD" -s); \
 		day=$$(git show HEAD --format='format:%ai' -s \