0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 usage() {
0014 echo "Usage: $0 [--save-scmversion] [srctree]" >&2
0015 exit 1
0016 }
0017
0018 scm_only=false
0019 srctree=.
0020 if test "$1" = "--save-scmversion"; then
0021 scm_only=true
0022 shift
0023 fi
0024 if test $
0025 srctree=$1
0026 shift
0027 fi
0028 if test $
0029 usage
0030 fi
0031
0032 scm_version()
0033 {
0034 local short
0035 short=false
0036
0037 cd "$srctree"
0038 if test -e .scmversion; then
0039 cat .scmversion
0040 return
0041 fi
0042 if test "$1" = "--short"; then
0043 short=true
0044 fi
0045
0046
0047 if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
0048 head=$(git rev-parse --verify HEAD 2>/dev/null); then
0049
0050
0051
0052 if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
0053
0054
0055
0056 if $short; then
0057 echo "+"
0058 return
0059 fi
0060
0061
0062 if atag="$(git describe 2>/dev/null)"; then
0063 echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
0064 fi
0065
0066
0067 printf '%s%s' -g "$(echo $head | cut -c1-12)"
0068 fi
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 if {
0081 git --no-optional-locks status -uno --porcelain 2>/dev/null ||
0082 git diff-index --name-only HEAD
0083 } | read dummy; then
0084 printf '%s' -dirty
0085 fi
0086 fi
0087 }
0088
0089 collect_files()
0090 {
0091 local file res=
0092
0093 for file; do
0094 case "$file" in
0095 *\~*)
0096 continue
0097 ;;
0098 esac
0099 if test -e "$file"; then
0100 res="$res$(cat "$file")"
0101 fi
0102 done
0103 echo "$res"
0104 }
0105
0106 if $scm_only; then
0107 if test ! -e .scmversion; then
0108 res=$(scm_version)
0109 echo "$res" >.scmversion
0110 fi
0111 exit
0112 fi
0113
0114 if ! test -e include/config/auto.conf; then
0115 echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
0116 exit 1
0117 fi
0118
0119
0120 res="$(collect_files localversion*)"
0121 if test ! "$srctree" -ef .; then
0122 res="$res$(collect_files "$srctree"/localversion*)"
0123 fi
0124
0125
0126 config_localversion=$(sed -n 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/p' include/config/auto.conf)
0127 res="${res}${config_localversion}${LOCALVERSION}"
0128
0129
0130 if grep -q "^CONFIG_LOCALVERSION_AUTO=y$" include/config/auto.conf; then
0131
0132 res="$res$(scm_version)"
0133 elif [ "${LOCALVERSION+set}" != "set" ]; then
0134
0135
0136
0137
0138
0139
0140
0141 scm=$(scm_version --short)
0142 res="$res${scm:++}"
0143 fi
0144
0145 echo "$res"