]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - mkversion.mk
Add version option, derived from repository tags
[repo_shell.git] / mkversion.mk
diff --git a/mkversion.mk b/mkversion.mk
new file mode 100644 (file)
index 0000000..0a4f124
--- /dev/null
@@ -0,0 +1,55 @@
+# 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))