From 02f5b741e7888b7da0c2a6a42f0cfb89a51c821e Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 8 Dec 2012 19:38:31 +0100 Subject: [PATCH] Add a shell script to generate the version string. Signed-off-by: Richard Cochran --- version.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 version.sh diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..1aba919 --- /dev/null +++ b/version.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# +# This scripts takes the major and minor release numbers and adds +# local version information from the git version control system. +# Adapted from scripts/setlocalversion in the Linux kernel sources. +# +major=0 +minor=0 +extra= + +usage() { + echo "Usage: $0 [srctree]" >&2 + exit 1 +} + +srctree=. +if test $# -gt 0; then + srctree=$1 + shift +fi +if test $# -gt 0 -o ! -d "$srctree"; then + usage +fi + +scm_version() +{ + cd "$srctree" + + # Check for git and a git repo. + if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then + + # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore + # it, because this version is defined in the top level Makefile. + if [ -z "`git describe --exact-match 2>/dev/null`" ]; then + + # If we are past a tagged commit (like + # "v2.6.30-rc5-302-g72357d5"), we pretty print it. + if atag="`git describe 2>/dev/null`"; then + echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' + + # If we don't have a tag at all we print -g{commitish}. + else + printf '%s%s' -g $head + fi + fi + + # Update index only on r/w media + [ -w . ] && git update-index --refresh --unmerged > /dev/null + + # Check for uncommitted changes + if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then + printf '%s' -dirty + fi + + # All done with git + return + fi +} + +res="${major}.${minor}${extra}$(scm_version)" +echo "$res"