···883$(vmlinux-dirs): prepare scripts884 $(Q)$(MAKE) $(build)=$@885886-# Build the kernel release string887-#888-# The KERNELRELEASE value built here is stored in the file889-# include/config/kernel.release, and is used when executing several890-# make targets, such as "make install" or "make modules_install."891-#892-# The eventual kernel release string consists of the following fields,893-# shown in a hierarchical format to show how smaller parts are concatenated894-# to form the larger and final value, with values coming from places like895-# the Makefile, kernel config options, make command line options and/or896-# SCM tag information.897-#898-# $(KERNELVERSION)899-# $(VERSION) eg, 2900-# $(PATCHLEVEL) eg, 6901-# $(SUBLEVEL) eg, 18902-# $(EXTRAVERSION) eg, -rc6903-# $(localver-full)904-# $(localver)905-# localversion* (files without backups, containing '~')906-# $(CONFIG_LOCALVERSION) (from kernel config setting)907-# $(LOCALVERSION) (from make command line, if provided)908-# $(localver-extra)909-# $(scm-identifier) (unique SCM tag, if one exists)910-# ./scripts/setlocalversion (only with CONFIG_LOCALVERSION_AUTO)911-# .scmversion (only with CONFIG_LOCALVERSION_AUTO)912-# + (only without CONFIG_LOCALVERSION_AUTO913-# and without LOCALVERSION= and914-# repository is at non-tagged commit)915-#916-# For kernels without CONFIG_LOCALVERSION_AUTO compiled from an SCM that has917-# been revised beyond a tagged commit, `+' is appended to the version string918-# when not overridden by using "make LOCALVERSION=". This indicates that the919-# kernel is not a vanilla release version and has been modified.920-921-pattern = ".*/localversion[^~]*"922-string = $(shell cat /dev/null \923- `find $(objtree) $(srctree) -maxdepth 1 -regex $(pattern) | sort -u`)924-925-localver = $(subst $(space),, $(string) \926- $(patsubst "%",%,$(CONFIG_LOCALVERSION)))927-928-# scripts/setlocalversion is called to create a unique identifier if the source929-# is managed by a known SCM and the repository has been revised since the last930-# tagged (release) commit. The format of the identifier is determined by the931-# SCM's implementation.932-#933-# .scmversion is used when generating rpm packages so we do not loose934-# the version information from the SCM when we do the build of the kernel935-# from the copied source936-ifeq ($(wildcard .scmversion),)937- scm-identifier = $(shell $(CONFIG_SHELL) \938- $(srctree)/scripts/setlocalversion $(srctree))939-else940- scm-identifier = $(shell cat .scmversion 2> /dev/null)941-endif942-943-ifdef CONFIG_LOCALVERSION_AUTO944- localver-extra = $(scm-identifier)945-else946- ifneq ($(scm-identifier),)947- ifeq ("$(origin LOCALVERSION)", "undefined")948- localver-extra = +949- endif950- endif951-endif952-953-localver-full = $(localver)$(LOCALVERSION)$(localver-extra)954-955# Store (new) KERNELRELASE string in include/config/kernel.release956-kernelrelease = $(KERNELVERSION)$(localver-full)957include/config/kernel.release: include/config/auto.conf FORCE958 $(Q)rm -f $@959- $(Q)echo $(kernelrelease) > $@960961962# Things we need to do before we recursively start building the kernel
···883$(vmlinux-dirs): prepare scripts884 $(Q)$(MAKE) $(build)=$@885000000000000000000000000000000000000000000000000000000000000000000000886# Store (new) KERNELRELASE string in include/config/kernel.release0887include/config/kernel.release: include/config/auto.conf FORCE888 $(Q)rm -f $@889+ $(Q)echo "$(KERNELVERSION)$$($(CONFIG_SHELL) scripts/setlocalversion $(srctree))" > $@890891892# Things we need to do before we recursively start building the kernel
···10#1112usage() {13- echo "Usage: $0 [srctree]" >&214 exit 115}1617-cd "${1:-.}" || usage0000000000001819-# Check for git and a git repo.20-if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then02122- # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it,23- # because this version is defined in the top level Makefile.24- if [ -z "`git describe --exact-match 2>/dev/null`" ]; then000002526- # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),27- # we pretty print it.28- if atag="`git describe 2>/dev/null`"; then29- echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'3031- # If we don't have a tag at all we print -g{commitish}.32- else33- printf '%s%s' -g $head000000000000000034 fi0000000000000000035 fi3637- # Is this git on svn?38- if git config --get svn-remote.svn.url >/dev/null; then39- printf -- '-svn%s' "`git svn find-rev $head`"00000000000000040 fi4142- # Update index only on r/w media43- [ -w . ] && git update-index --refresh --unmerged > /dev/null004445- # Check for uncommitted changes46- if git diff-index --name-only HEAD | grep -v "^scripts/package" \47- | read dummy; then48- printf '%s' -dirty49 fi05051- # All done with git00000000000000000052 exit53fi5455-# Check for mercurial and a mercurial repo.56-if hgid=`hg id 2>/dev/null`; then57- tag=`printf '%s' "$hgid" | cut -d' ' -f2`0005859- # Do we have an untagged version?60- if [ -z "$tag" -o "$tag" = tip ]; then61- id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`62- printf '%s%s' -hg "$id"00000000000000063 fi64-65- # Are there uncommitted changes?66- # These are represented by + after the changeset id.67- case "$hgid" in68- *+|*+\ *) printf '%s' -dirty ;;69- esac70-71- # All done with mercurial72- exit73fi7475-# Check for svn and a svn repo.76-if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then77- rev=`echo $rev | awk '{print $NF}'`78- printf -- '-svn%s' "$rev"79-80- # All done with svn81- exit82-fi
···10#1112usage() {13+ echo "Usage: $0 [--scm-only] [srctree]" >&214 exit 115}1617+scm_only=false18+srctree=.19+if test "$1" = "--scm-only"; then20+ scm_only=true21+ shift22+fi23+if test $# -gt 0; then24+ srctree=$125+ shift26+fi27+if test $# -gt 0 -o ! -d "$srctree"; then28+ usage29+fi3031+scm_version()32+{33+ local short=false3435+ cd "$srctree"36+ if test -e .scmversion; then37+ cat "$_"38+ return39+ fi40+ if test "$1" = "--short"; then41+ short=true42+ fi4344+ # Check for git and a git repo.45+ if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then004647+ # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore48+ # it, because this version is defined in the top level Makefile.49+ if [ -z "`git describe --exact-match 2>/dev/null`" ]; then50+51+ # If only the short version is requested, don't bother52+ # running further git commands53+ if $short; then54+ echo "+"55+ return56+ fi57+ # If we are past a tagged commit (like58+ # "v2.6.30-rc5-302-g72357d5"), we pretty print it.59+ if atag="`git describe 2>/dev/null`"; then60+ 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+ else64+ printf '%s%s' -g $head65+ fi66 fi67+68+ # Is this git on svn?69+ if git config --get svn-remote.svn.url >/dev/null; then70+ printf -- '-svn%s' "`git svn find-rev $head`"71+ fi72+73+ # Update index only on r/w media74+ [ -w . ] && git update-index --refresh --unmerged > /dev/null75+76+ # Check for uncommitted changes77+ if git diff-index --name-only HEAD | grep -v "^scripts/package" \78+ | read dummy; then79+ printf '%s' -dirty80+ fi81+82+ # All done with git83+ return84 fi8586+ # Check for mercurial and a mercurial repo.87+ if hgid=`hg id 2>/dev/null`; then88+ tag=`printf '%s' "$hgid" | cut -d' ' -f2`89+90+ # Do we have an untagged version?91+ if [ -z "$tag" -o "$tag" = tip ]; then92+ id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`93+ printf '%s%s' -hg "$id"94+ fi95+96+ # Are there uncommitted changes?97+ # These are represented by + after the changeset id.98+ case "$hgid" in99+ *+|*+\ *) printf '%s' -dirty ;;100+ esac101+102+ # All done with mercurial103+ return104 fi105106+ # Check for svn and a svn repo.107+ if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then108+ rev=`echo $rev | awk '{print $NF}'`109+ printf -- '-svn%s' "$rev"110111+ # All done with svn112+ return00113 fi114+}115116+collect_files()117+{118+ local file res119+120+ for file; do121+ case "$file" in122+ *\~*)123+ continue124+ ;;125+ esac126+ if test -e "$file"; then127+ res="$res$(cat "$file")"128+ fi129+ done130+ echo "$res"131+}132+133+if $scm_only; then134+ scm_version135 exit136fi137138+if test -e include/config/auto.conf; then139+ source "$_"140+else141+ echo "Error: kernelrelease not valid - run 'make prepare' to update it"142+ exit 1143+fi144145+# localversion* files in the build and source directory146+res="$(collect_files localversion*)"147+if test ! "$srctree" -ef .; then148+ res="$res$(collect_files "$srctree"/localversion*)"149+fi150+151+# CONFIG_LOCALVERSION and LOCALVERSION (if set)152+res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"153+154+# scm version string if not at a tagged commit155+if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then156+ # full scm version string157+ res="$res$(scm_version)"158+else159+ # apped a plus sign if the repository is not in a clean tagged160+ # state and LOCALVERSION= is not specified161+ if test "${LOCALVERSION+set}" != "set"; then162+ scm=$(scm_version --short)163+ res="$res${scm:++}"164 fi000000000165fi166167+echo "$res"0000000