3 # This scripts adds local version information from the version
4 # control systems git, mercurial (hg) and subversion (svn).
6 # If something goes wrong, send a mail the kernel build mailinglist
7 # (see MAINTAINERS) and CC Nico Schottelius
8 # <nico-linuxsetlocalversion -at- schottelius.org>.
13 echo "Usage: $0 [--scm-only] [srctree]" >&2
19 if test "$1" = "--scm-only"; then
23 if test $# -gt 0; then
27 if test $# -gt 0 -o ! -d "$srctree"; then
36 if test -e .scmversion; then
40 if test "$1" = "--short"; then
44 # Check for git and a git repo.
45 if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
47 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
48 # it, because this version is defined in the top level Makefile.
49 if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
51 # If only the short version is requested, don't bother
52 # running further git commands
57 # If we are past a tagged commit (like
58 # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
59 if atag="`git describe 2>/dev/null`"; then
60 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
62 # If we don't have a tag at all we print -g{commitish}.
64 printf '%s%s' -g $head
69 if git config --get svn-remote.svn.url >/dev/null; then
70 printf -- '-svn%s' "`git svn find-rev $head`"
73 # Update index only on r/w media
74 [ -w . ] && git update-index --refresh --unmerged > /dev/null
76 # Check for uncommitted changes
77 if git diff-index --name-only HEAD | grep -v "^scripts/package" \
86 # Check for mercurial and a mercurial repo.
87 if hgid=`hg id 2>/dev/null`; then
88 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
90 # Do we have an untagged version?
91 if [ -z "$tag" -o "$tag" = tip ]; then
92 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
93 printf '%s%s' -hg "$id"
96 # Are there uncommitted changes?
97 # These are represented by + after the changeset id.
99 *+|*+\ *) printf '%s' -dirty ;;
102 # All done with mercurial
106 # Check for svn and a svn repo.
107 if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
108 rev=`echo $rev | awk '{print $NF}'`
109 printf -- '-svn%s' "$rev"
126 if test -e "$file"; then
127 res="$res$(cat "$file")"
138 if test -e include/config/auto.conf; then
141 echo "Error: kernelrelease not valid - run 'make prepare' to update it"
145 # localversion* files in the build and source directory
146 res="$(collect_files localversion*)"
147 if test ! "$srctree" -ef .; then
148 res="$res$(collect_files "$srctree"/localversion*)"
151 # CONFIG_LOCALVERSION and LOCALVERSION (if set)
152 res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
154 # scm version string if not at a tagged commit
155 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
156 # full scm version string
157 res="$res$(scm_version)"
159 # apped a plus sign if the repository is not in a clean tagged
160 # state and LOCALVERSION= is not specified
161 if test "${LOCALVERSION+set}" != "set"; then
162 scm=$(scm_version --short)