Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / git-gen-version.sh
index 601b2b2..9395647 100755 (executable)
 # The version number is stored in a dedicated Nit module.
 
 gen_version() {
-cat > nit_version.nit<<END
+       if ! grep "$*" version.nit >/dev/null 2>&1; then
+               cat > version.nit <<END
 # This file was generated by git-gen-version.sh
-package nit_version
-meth nit_version: String do return "$*"
+module version
+fun nit_version: String do return "$*"
 END
-echo "Version $*"
+               echo "Version $*"
+       fi
 }
 
-# Are we in the nitc.nit directory?
-if [ ! -f nitc.nit ]; then
-       if [ -f src/nitc.nit ]; then
+# Are we in the nit.nit directory?
+if [ ! -f nit.nit ]; then
+       if [ -f src/nit.nit ]; then
                cd src
        else
-               echo "Error: no nitc.nit found." >&2
+               echo "Error: no nit.nit found." >&2
                exit 1
        fi
 fi
 
-VN=$(git describe --tags --always HEAD)
+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)" ]; then
+if [ -n "$(git diff HEAD 2>/dev/null)" ]; then
        VN="${VN}_dirty"
 fi