Back to home page

LXR

 
 

    


0001 #!/bin/sh
0002 #
0003 # This scripts adds local version information from the version
0004 # control systems git, mercurial (hg) and subversion (svn).
0005 #
0006 # If something goes wrong, send a mail the kernel build mailinglist
0007 # (see MAINTAINERS) and CC Nico Schottelius
0008 # <nico-linuxsetlocalversion -at- schottelius.org>.
0009 #
0010 #
0011 
0012 usage() {
0013         echo "Usage: $0 [--save-scmversion] [srctree]" >&2
0014         exit 1
0015 }
0016 
0017 scm_only=false
0018 srctree=.
0019 if test "$1" = "--save-scmversion"; then
0020         scm_only=true
0021         shift
0022 fi
0023 if test $# -gt 0; then
0024         srctree=$1
0025         shift
0026 fi
0027 if test $# -gt 0 -o ! -d "$srctree"; then
0028         usage
0029 fi
0030 
0031 scm_version()
0032 {
0033         local short
0034         short=false
0035 
0036         cd "$srctree"
0037         if test -e .scmversion; then
0038                 cat .scmversion
0039                 return
0040         fi
0041         if test "$1" = "--short"; then
0042                 short=true
0043         fi
0044 
0045         # Check for git and a git repo.
0046         if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
0047            head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
0048 
0049                 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
0050                 # it, because this version is defined in the top level Makefile.
0051                 if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
0052 
0053                         # If only the short version is requested, don't bother
0054                         # running further git commands
0055                         if $short; then
0056                                 echo "+"
0057                                 return
0058                         fi
0059                         # If we are past a tagged commit (like
0060                         # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
0061                         if atag="`git describe 2>/dev/null`"; then
0062                                 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
0063 
0064                         # If we don't have a tag at all we print -g{commitish}.
0065                         else
0066                                 printf '%s%s' -g $head
0067                         fi
0068                 fi
0069 
0070                 # Is this git on svn?
0071                 if git config --get svn-remote.svn.url >/dev/null; then
0072                         printf -- '-svn%s' "`git svn find-rev $head`"
0073                 fi
0074 
0075                 # Check for uncommitted changes
0076                 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
0077                         printf '%s' -dirty
0078                 fi
0079 
0080                 # All done with git
0081                 return
0082         fi
0083 
0084         # Check for mercurial and a mercurial repo.
0085         if test -d .hg && hgid=`hg id 2>/dev/null`; then
0086                 # Do we have an tagged version?  If so, latesttagdistance == 1
0087                 if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
0088                         id=`hg log -r . --template '{latesttag}'`
0089                         printf '%s%s' -hg "$id"
0090                 else
0091                         tag=`printf '%s' "$hgid" | cut -d' ' -f2`
0092                         if [ -z "$tag" -o "$tag" = tip ]; then
0093                                 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
0094                                 printf '%s%s' -hg "$id"
0095                         fi
0096                 fi
0097 
0098                 # Are there uncommitted changes?
0099                 # These are represented by + after the changeset id.
0100                 case "$hgid" in
0101                         *+|*+\ *) printf '%s' -dirty ;;
0102                 esac
0103 
0104                 # All done with mercurial
0105                 return
0106         fi
0107 
0108         # Check for svn and a svn repo.
0109         if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
0110                 rev=`echo $rev | awk '{print $NF}'`
0111                 printf -- '-svn%s' "$rev"
0112 
0113                 # All done with svn
0114                 return
0115         fi
0116 }
0117 
0118 collect_files()
0119 {
0120         local file res
0121 
0122         for file; do
0123                 case "$file" in
0124                 *\~*)
0125                         continue
0126                         ;;
0127                 esac
0128                 if test -e "$file"; then
0129                         res="$res$(cat "$file")"
0130                 fi
0131         done
0132         echo "$res"
0133 }
0134 
0135 if $scm_only; then
0136         if test ! -e .scmversion; then
0137                 res=$(scm_version)
0138                 echo "$res" >.scmversion
0139         fi
0140         exit
0141 fi
0142 
0143 if test -e include/config/auto.conf; then
0144         . include/config/auto.conf
0145 else
0146         echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
0147         exit 1
0148 fi
0149 
0150 # localversion* files in the build and source directory
0151 res="$(collect_files localversion*)"
0152 if test ! "$srctree" -ef .; then
0153         res="$res$(collect_files "$srctree"/localversion*)"
0154 fi
0155 
0156 # CONFIG_LOCALVERSION and LOCALVERSION (if set)
0157 res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
0158 
0159 # scm version string if not at a tagged commit
0160 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
0161         # full scm version string
0162         res="$res$(scm_version)"
0163 else
0164         # append a plus sign if the repository is not in a clean
0165         # annotated or signed tagged state (as git describe only
0166         # looks at signed or annotated tags - git tag -a/-s) and
0167         # LOCALVERSION= is not specified
0168         if test "${LOCALVERSION+set}" != "set"; then
0169                 scm=$(scm_version --short)
0170                 res="$res${scm:++}"
0171         fi
0172 fi
0173 
0174 echo "$res"