Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # This scripts adds local version information from the version
0005 # control systems git, mercurial (hg) and subversion (svn).
0006 #
0007 # If something goes wrong, send a mail the kernel build mailinglist
0008 # (see MAINTAINERS) and CC Nico Schottelius
0009 # <nico-linuxsetlocalversion -at- schottelius.org>.
0010 #
0011 #
0012 
0013 usage() {
0014         echo "Usage: $0 [--save-scmversion] [srctree]" >&2
0015         exit 1
0016 }
0017 
0018 scm_only=false
0019 srctree=.
0020 if test "$1" = "--save-scmversion"; then
0021         scm_only=true
0022         shift
0023 fi
0024 if test $# -gt 0; then
0025         srctree=$1
0026         shift
0027 fi
0028 if test $# -gt 0 -o ! -d "$srctree"; then
0029         usage
0030 fi
0031 
0032 scm_version()
0033 {
0034         local short
0035         short=false
0036 
0037         cd "$srctree"
0038         if test -e .scmversion; then
0039                 cat .scmversion
0040                 return
0041         fi
0042         if test "$1" = "--short"; then
0043                 short=true
0044         fi
0045 
0046         # Check for git and a git repo.
0047         if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
0048            head=$(git rev-parse --verify HEAD 2>/dev/null); then
0049 
0050                 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
0051                 # it, because this version is defined in the top level Makefile.
0052                 if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
0053 
0054                         # If only the short version is requested, don't bother
0055                         # running further git commands
0056                         if $short; then
0057                                 echo "+"
0058                                 return
0059                         fi
0060                         # If we are past a tagged commit (like
0061                         # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
0062                         if atag="$(git describe 2>/dev/null)"; then
0063                                 echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
0064                         fi
0065 
0066                         # Add -g and exactly 12 hex chars.
0067                         printf '%s%s' -g "$(echo $head | cut -c1-12)"
0068                 fi
0069 
0070                 # Check for uncommitted changes.
0071                 # This script must avoid any write attempt to the source tree,
0072                 # which might be read-only.
0073                 # You cannot use 'git describe --dirty' because it tries to
0074                 # create .git/index.lock .
0075                 # First, with git-status, but --no-optional-locks is only
0076                 # supported in git >= 2.14, so fall back to git-diff-index if
0077                 # it fails. Note that git-diff-index does not refresh the
0078                 # index, so it may give misleading results. See
0079                 # git-update-index(1), git-diff-index(1), and git-status(1).
0080                 if {
0081                         git --no-optional-locks status -uno --porcelain 2>/dev/null ||
0082                         git diff-index --name-only HEAD
0083                 } | read dummy; then
0084                         printf '%s' -dirty
0085                 fi
0086         fi
0087 }
0088 
0089 collect_files()
0090 {
0091         local file res=
0092 
0093         for file; do
0094                 case "$file" in
0095                 *\~*)
0096                         continue
0097                         ;;
0098                 esac
0099                 if test -e "$file"; then
0100                         res="$res$(cat "$file")"
0101                 fi
0102         done
0103         echo "$res"
0104 }
0105 
0106 if $scm_only; then
0107         if test ! -e .scmversion; then
0108                 res=$(scm_version)
0109                 echo "$res" >.scmversion
0110         fi
0111         exit
0112 fi
0113 
0114 if ! test -e include/config/auto.conf; then
0115         echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
0116         exit 1
0117 fi
0118 
0119 # localversion* files in the build and source directory
0120 res="$(collect_files localversion*)"
0121 if test ! "$srctree" -ef .; then
0122         res="$res$(collect_files "$srctree"/localversion*)"
0123 fi
0124 
0125 # CONFIG_LOCALVERSION and LOCALVERSION (if set)
0126 config_localversion=$(sed -n 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/p' include/config/auto.conf)
0127 res="${res}${config_localversion}${LOCALVERSION}"
0128 
0129 # scm version string if not at a tagged commit
0130 if grep -q "^CONFIG_LOCALVERSION_AUTO=y$" include/config/auto.conf; then
0131         # full scm version string
0132         res="$res$(scm_version)"
0133 elif [ "${LOCALVERSION+set}" != "set" ]; then
0134         # If the variable LOCALVERSION is not set, append a plus
0135         # sign if the repository is not in a clean annotated or
0136         # signed tagged state (as git describe only looks at signed
0137         # or annotated tags - git tag -a/-s).
0138         #
0139         # If the variable LOCALVERSION is set (including being set
0140         # to an empty string), we don't want to append a plus sign.
0141         scm=$(scm_version --short)
0142         res="$res${scm:++}"
0143 fi
0144 
0145 echo "$res"