chdir: collapse /./ and /../ in path for conventional filesystems
[profile/ivi/syslinux.git] / gen-id.sh
index 02be21a..301ea4e 100755 (executable)
--- a/gen-id.sh
+++ b/gen-id.sh
@@ -1,22 +1,33 @@
 #!/bin/sh
 #
-# Create a 10-character ID for this build.  If we're using a git tree,
-# generate an ID of the form g[-*]XXXXXXXX (* = modified); otherwise use
-# the passed-in timestamp.
+# Create a build ID for this build.  If we're using a git tree,
+# generate an ID from "git describe", otherwise use the passed-in
+# timestamp.
 #
+# Usage: gen-id.sh version timestamp
+#
+
+ver="$1"
+tim="$2"
+top=`dirname "$0"`
 
-if test -n "$GIT_DIR" -o -d ../.git -o -f ../.git; then
-    ver="$(git rev-parse HEAD | cut -c1-8)"
-    if test -n "$ver"; then
+if test -n "$GIT_DIR" -o -d "$top"/.git -o -f "$top"/.git; then
+    id="$(git describe)"
+    if test -n "$id"; then
+       if test x"$(echo "$id" | cut -d- -f1)" = xsyslinux; then
+            id="$(echo "$id" | cut -d- -f2-)"
+            if test x"$(echo "$id" | cut -d- -f1)" = x"$ver"; then
+               id="$(echo "$id" | cut -d- -f2-)"
+            fi
+        fi
+    fi
+    if test -n "$id"; then
        if test -n "$(git diff-index --name-only HEAD)"; then
-           ver='g*'"$ver"
-       else
-           ver='g-'"$ver"
+           id="${id}"\*
        fi
     fi
 fi
-if test -z "$ver"; then
-  echo "$1"
-else
-  echo "$ver"
+if test -z "$id"; then
+  id="$tim"
 fi
+echo "$id"