+# mkversion.mk
+#
+# Determine the repository checkout id. Assume that there are no local
+# changes in the workspace. Support svn, git svn, and git.
+#
+# Usage example:
+#
+# VERSION_FILE := "version.h"
+# $(VERSION_FILE):%.h: %.in
+# sed -e 's|__appVersion__|$(VERSION)|g' < $^ > $@
+#
+# Contents of version.h:
+#
+# #ifndef VERSION_H
+# #define VERSION_H
+#
+# #define VERSION "__appVersion__"
+#
+# #endif
+
+ifeq (.svn,$(shell ls -d .svn 2>/dev/null))
+ VERSION := $(shell svnversion . 2>/dev/null | sed -e 's|M$$|-dirty|')
+ ifneq (,$(VERSION))
+ VERSION := r$(VERSION)
+ endif
+ VERFROM := svn
+endif
+ifeq (.git,$(shell ls -d .git))
+ VERSION := $(shell git svn info 2>/dev/null | grep "Revision: " | \
+ sed -e s'/^[^0-9]*\([0-9]*\).*$$/r\1/')
+ ifneq (,$(VERSION))
+ # git-svn
+ ifeq (,$(shell git log -n1 2>/dev/null | grep "git-svn-id: "))
+ VERSION := $(VERSION)-dirty
+ else
+ ifneq (,$(shell git diff-index --name-only HEAD 2>/dev/null))
+ VERSION := $(VERSION)-dirty
+ endif
+ endif
+ VERFROM := svn
+ else
+ # git
+ VERSION := $(shell git describe --tags --always 2>/dev/null)
+ ifneq (,$(VERSION))
+ ifneq (,$(shell git diff-index --name-only HEAD 2>/dev/null))
+ VERSION := $(VERSION)-dirty
+ endif
+ endif
+ VERFROM := git
+ endif
+endif
+ifeq (,$(VERSION))
+ VERSION := unknown
+endif
+#$(warning VERSION $(VERSION))