doc: forgot to add doc/git-get-version.sh
authorJean Privat <jean@pryen.org>
Fri, 18 Feb 2011 20:26:42 +0000 (15:26 -0500)
committerJean Privat <jean@pryen.org>
Fri, 18 Feb 2011 20:26:42 +0000 (15:26 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

.gitignore
doc/git-gen-version.sh [new file with mode: 0755]

index c6bbb96..a4d3ff1 100644 (file)
@@ -11,6 +11,7 @@ doc/stdlib
 *.log
 *.out
 *.toc
+doc/nit_version.sty
 
 src/nitc
 src/nitc_?
diff --git a/doc/git-gen-version.sh b/doc/git-gen-version.sh
new file mode 100755 (executable)
index 0000000..145f2f7
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2008 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This program is used to generate version number from git refs.
+# The version number is stored in a dedicated Nit module.
+
+gen_version() {
+       if ! grep "$*" nit_version.sty >/dev/null 2>&1; then
+               cat > nit_version.sty<<END
+% This file was generated by git-gen-version.sh
+\\newcommand\\nitversion{$*}
+END
+               echo "Version $*"
+       fi
+}
+
+VN=$(git describe --always HEAD 2>/dev/null)
+if [ "$?" != "0" ]; then
+       if [ -r ../VERSION ]; then
+               VN="$(cat ../VERSION)"
+       else
+               echo >&2 "Error: no VERSION file and not a .git repository."
+               exit 1
+       fi
+fi
+if [ -z "$VN" ]; then
+       VN="undefined"
+fi
+if [ -n "$1" ]; then
+       VN="${VN}-$1"
+fi
+if [ -n "$(git diff HEAD 2>/dev/null)" ]; then
+       VN="${VN}-dirty"
+fi
+
+gen_version "$VN"