perf tools: Fix build error on read only source.
[sfrench/cifs-2.6.git] / scripts / setlocalversion
index d6a866ed1835c8f1ee4524c6bb26df554c83c6e1..e90a91cc5185709d31a9a128b4790b676a35599e 100755 (executable)
 #
 
 usage() {
-       echo "Usage: $0 [--scm-only] [srctree]" >&2
+       echo "Usage: $0 [--save-scmversion] [srctree]" >&2
        exit 1
 }
 
 scm_only=false
 srctree=.
-if test "$1" = "--scm-only"; then
+if test "$1" = "--save-scmversion"; then
        scm_only=true
        shift
 fi
@@ -30,11 +30,12 @@ fi
 
 scm_version()
 {
-       local short=false
+       local short
+       short=false
 
        cd "$srctree"
        if test -e .scmversion; then
-               cat "$_"
+               cat .scmversion
                return
        fi
        if test "$1" = "--short"; then
@@ -85,7 +86,7 @@ scm_version()
 
        # Check for mercurial and a mercurial repo.
        if hgid=`hg id 2>/dev/null`; then
-               tag=`printf '%s' "$hgid" | cut -d' ' -f2`
+               tag=`printf '%s' "$hgid" | cut -s -d' ' -f2`
 
                # Do we have an untagged version?
                if [ -z "$tag" -o "$tag" = tip ]; then
@@ -131,12 +132,15 @@ collect_files()
 }
 
 if $scm_only; then
-       scm_version
+       if test ! -e .scmversion; then
+               res=$(scm_version)
+               echo "$res" >.scmversion
+       fi
        exit
 fi
 
 if test -e include/config/auto.conf; then
-       source "$_"
+       . include/config/auto.conf
 else
        echo "Error: kernelrelease not valid - run 'make prepare' to update it"
        exit 1