Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 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 | # |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 11 | |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 12 | usage() { |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 13 | echo "Usage: $0 [--scm-only] [srctree]" >&2 |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 14 | exit 1 |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 15 | } |
| 16 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 17 | scm_only=false |
| 18 | srctree=. |
| 19 | if test "$1" = "--scm-only"; 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 |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 30 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 31 | scm_version() |
| 32 | { |
| 33 | local short=false |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 34 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 35 | cd "$srctree" |
| 36 | if test -e .scmversion; then |
| 37 | cat "$_" |
| 38 | return |
| 39 | fi |
| 40 | if test "$1" = "--short"; then |
| 41 | short=true |
| 42 | fi |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 43 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 44 | # Check for git and a git repo. |
| 45 | if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 46 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 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 |
| 50 | |
| 51 | # If only the short version is requested, don't bother |
| 52 | # running further git commands |
| 53 | if $short; then |
| 54 | echo "+" |
| 55 | return |
| 56 | fi |
| 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))}' |
| 61 | |
| 62 | # If we don't have a tag at all we print -g{commitish}. |
| 63 | else |
| 64 | printf '%s%s' -g $head |
| 65 | fi |
Nico Schottelius | 3325257 | 2009-05-16 14:00:56 +0200 | [diff] [blame] | 66 | fi |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 67 | |
| 68 | # Is this git on svn? |
| 69 | if git config --get svn-remote.svn.url >/dev/null; then |
| 70 | printf -- '-svn%s' "`git svn find-rev $head`" |
| 71 | fi |
| 72 | |
| 73 | # Update index only on r/w media |
| 74 | [ -w . ] && git update-index --refresh --unmerged > /dev/null |
| 75 | |
| 76 | # Check for uncommitted changes |
| 77 | if git diff-index --name-only HEAD | grep -v "^scripts/package" \ |
| 78 | | read dummy; then |
| 79 | printf '%s' -dirty |
| 80 | fi |
| 81 | |
| 82 | # All done with git |
| 83 | return |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 84 | fi |
Ryan Anderson | aaebf43 | 2005-07-31 04:57:49 -0400 | [diff] [blame] | 85 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 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` |
| 89 | |
| 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" |
| 94 | fi |
| 95 | |
| 96 | # Are there uncommitted changes? |
| 97 | # These are represented by + after the changeset id. |
| 98 | case "$hgid" in |
| 99 | *+|*+\ *) printf '%s' -dirty ;; |
| 100 | esac |
| 101 | |
| 102 | # All done with mercurial |
| 103 | return |
Peter Korsgaard | ff80aa9 | 2008-12-02 21:58:06 +0100 | [diff] [blame] | 104 | fi |
| 105 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 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" |
Nico Schottelius | a2bb90a | 2009-06-12 09:59:52 +0200 | [diff] [blame] | 110 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 111 | # All done with svn |
| 112 | return |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 113 | fi |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 114 | } |
Aron Griffis | 3dce174 | 2007-11-28 16:55:44 -0500 | [diff] [blame] | 115 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 116 | collect_files() |
| 117 | { |
| 118 | local file res |
| 119 | |
| 120 | for file; do |
| 121 | case "$file" in |
| 122 | *\~*) |
| 123 | continue |
| 124 | ;; |
| 125 | esac |
| 126 | if test -e "$file"; then |
| 127 | res="$res$(cat "$file")" |
| 128 | fi |
| 129 | done |
| 130 | echo "$res" |
| 131 | } |
| 132 | |
| 133 | if $scm_only; then |
| 134 | scm_version |
Aron Griffis | 3dce174 | 2007-11-28 16:55:44 -0500 | [diff] [blame] | 135 | exit |
| 136 | fi |
| 137 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 138 | if test -e include/config/auto.conf; then |
| 139 | source "$_" |
| 140 | else |
| 141 | echo "Error: kernelrelease not valid - run 'make prepare' to update it" |
| 142 | exit 1 |
| 143 | fi |
Aron Griffis | 3dce174 | 2007-11-28 16:55:44 -0500 | [diff] [blame] | 144 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 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*)" |
| 149 | fi |
| 150 | |
| 151 | # CONFIG_LOCALVERSION and LOCALVERSION (if set) |
| 152 | res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}" |
| 153 | |
| 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)" |
| 158 | else |
| 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) |
| 163 | res="$res${scm:++}" |
Aron Griffis | 3dce174 | 2007-11-28 16:55:44 -0500 | [diff] [blame] | 164 | fi |
Rene Scharfe | 117a93d | 2006-01-04 20:42:03 +0100 | [diff] [blame] | 165 | fi |
Bryan Wu | ba3d05f | 2008-02-03 14:13:26 +0800 | [diff] [blame] | 166 | |
Michal Marek | 0915512 | 2010-06-17 15:14:58 +0200 | [diff] [blame^] | 167 | echo "$res" |