]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - scripts/setlocalversion
Merge branch 'linux-3.10.40' into rel-21
[linux-3.10.git] / scripts / setlocalversion
1 #!/bin/sh
2 #
3 # This scripts adds local version information from the version
4 # control systems git, mercurial (hg) and subversion (svn).
5 #
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>.
9 #
10 #
11
12 usage() {
13         echo "Usage: $0 [--save-scmversion] [srctree]" >&2
14         exit 1
15 }
16
17 scm_only=false
18 srctree=.
19 if test "$1" = "--save-scmversion"; then
20         scm_only=true
21         shift
22 fi
23 if test $# -gt 0; then
24         srctree=$1
25         shift
26 fi
27 if test $# -gt 0 -o ! -d "$srctree"; then
28         usage
29 fi
30
31 scm_version()
32 {
33         local short
34         short=false
35
36         cd "$srctree"
37         if test -e .scmversion; then
38                 cat .scmversion
39                 return
40         fi
41         if test "$1" = "--short"; then
42                 short=true
43         fi
44
45         # Check for git and a git repo.
46         if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
47
48                 # Regardless whether it is a tagged commit (like "v2.6.30-rc6"),
49                 # we will put the commit info in.
50                 printf '%s%s' -g $head
51
52                 # Is this git on svn?
53                 if git config --get svn-remote.svn.url >/dev/null; then
54                         printf -- '-svn%s' "`git svn find-rev $head`"
55                 fi
56
57                 # Update index only on r/w media
58                 [ -w . ] && git update-index --refresh --unmerged > /dev/null
59
60                 # Check for uncommitted changes
61                 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
62                         printf '%s' -dirty
63                 fi
64
65                 # All done with git
66                 return
67         fi
68
69         # Check for mercurial and a mercurial repo.
70         if test -d .hg && hgid=`hg id 2>/dev/null`; then
71                 # Do we have an tagged version?  If so, latesttagdistance == 1
72                 if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
73                         id=`hg log -r . --template '{latesttag}'`
74                         printf '%s%s' -hg "$id"
75                 else
76                         tag=`printf '%s' "$hgid" | cut -d' ' -f2`
77                         if [ -z "$tag" -o "$tag" = tip ]; then
78                                 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
79                                 printf '%s%s' -hg "$id"
80                         fi
81                 fi
82
83                 # Are there uncommitted changes?
84                 # These are represented by + after the changeset id.
85                 case "$hgid" in
86                         *+|*+\ *) printf '%s' -dirty ;;
87                 esac
88
89                 # All done with mercurial
90                 return
91         fi
92
93         # Check for svn and a svn repo.
94         if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
95                 rev=`echo $rev | awk '{print $NF}'`
96                 printf -- '-svn%s' "$rev"
97
98                 # All done with svn
99                 return
100         fi
101 }
102
103 collect_files()
104 {
105         local file res
106
107         for file; do
108                 case "$file" in
109                 *\~*)
110                         continue
111                         ;;
112                 esac
113                 if test -e "$file"; then
114                         res="$res$(cat "$file")"
115                 fi
116         done
117         echo "$res"
118 }
119
120 if $scm_only; then
121         if test ! -e .scmversion; then
122                 res=$(scm_version)
123                 echo "$res" >.scmversion
124         fi
125         exit
126 fi
127
128 if test -e include/config/auto.conf; then
129         . include/config/auto.conf
130 else
131         echo "Error: kernelrelease not valid - run 'make prepare' to update it"
132         exit 1
133 fi
134
135 # localversion* files in the build and source directory
136 res="$(collect_files localversion*)"
137 if test ! "$srctree" -ef .; then
138         res="$res$(collect_files "$srctree"/localversion*)"
139 fi
140
141 # CONFIG_LOCALVERSION and LOCALVERSION (if set)
142 res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
143
144 # scm version string if not at a tagged commit
145 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
146         # full scm version string
147         res="$res$(scm_version)"
148 else
149         # append a plus sign if the repository is not in a clean
150         # annotated or signed tagged state (as git describe only
151         # looks at signed or annotated tags - git tag -a/-s) and
152         # LOCALVERSION= is not specified
153         if test "${LOCALVERSION+set}" != "set"; then
154                 scm=$(scm_version --short)
155                 res="$res${scm:++}"
156         fi
157 fi
158
159 echo "$res"