123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #!/bin/sh
- usage() {
- echo "Usage: $0 [--save-scmversion] [srctree]" >&2
- exit 1
- }
- scm_only=false
- srctree=.
- if test "$1" = "--save-scmversion"; then
- scm_only=true
- shift
- fi
- if test $# -gt 0; then
- srctree=$1
- shift
- fi
- if test $# -gt 0 -o ! -d "$srctree"; then
- usage
- fi
- _scm_version()
- {
- local short
- short=false
- if test "$1" = "--short"; then
- short=true
- fi
-
- if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
- head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
-
-
- if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
-
-
- if $short; then
- echo "+"
- return
- fi
-
-
- if atag="`git describe 2>/dev/null`"; then
- echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
-
- else
- printf '%s%s' -g $head
- fi
- fi
-
- if git config --get svn-remote.svn.url >/dev/null; then
- printf -- '-svn%s' "`git svn find-rev $head`"
- fi
-
-
-
-
-
-
- if {
- git --no-optional-locks status -uno --porcelain 2>/dev/null ||
- git diff-index --name-only HEAD
- } | grep -qvE '^(.. )?scripts/package'; then
- printf '%s' -dirty
- fi
-
- return
- fi
-
- if test -d .hg && hgid=`hg id 2>/dev/null`; then
-
- if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
- id=`hg log -r . --template '{latesttag}'`
- printf '%s%s' -hg "$id"
- else
- tag=`printf '%s' "$hgid" | cut -d' ' -f2`
- if [ -z "$tag" -o "$tag" = tip ]; then
- id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
- printf '%s%s' -hg "$id"
- fi
- fi
-
-
- case "$hgid" in
- *+|*+\ *) printf '%s' -dirty ;;
- esac
-
- return
- fi
-
- if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
- rev=`echo $rev | awk '{print $NF}'`
- printf -- '-svn%s' "$rev"
-
- return
- fi
- }
- scm_version()
- {
- local git_path res git_all_proj name
- cd "$srctree"
- if test -e .scmversion; then
- cat .scmversion
- return
- fi
- git_all_proj=$(find . -name .git -type d | sort)
- if [ ! -z "$git_all_proj" ] ; then
- res=""
- for git_path in $git_all_proj; do
- git_path=${git_path%.git}
- name=$(basename ${git_path})
- if [ $name = "." ] ; then
- name=""
- else
- name="_$name"
- fi
- res="$res$name$(cd $git_path;_scm_version)"
- done
- printf -- '%s' "$res"
- else
- _scm_version
- fi
- }
- collect_files()
- {
- local file res
- for file; do
- case "$file" in
- *\~*)
- continue
- ;;
- esac
- if test -e "$file"; then
- res="$res$(cat "$file")"
- fi
- done
- echo "$res"
- }
- if $scm_only; then
- if test ! -e .scmversion; then
- res=$(scm_version)
- echo "$res" >.scmversion
- fi
- exit
- fi
- if test -e include/config/auto.conf; then
- . include/config/auto.conf
- else
- echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
- exit 1
- fi
- res="$(collect_files localversion*)"
- if test ! "$srctree" -ef .; then
- res="$res$(collect_files "$srctree"/localversion*)"
- fi
- res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
- if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
-
- res="$res$(scm_version)"
- else
-
-
-
-
- if test "${LOCALVERSION+set}" != "set"; then
- scm=$(scm_version --short)
- res="$res${scm:++}"
- fi
- fi
- echo "$res"
|