kbuild: KERNELRELEASE is only re-defined when buiding the kernel

To avoid running setlocalversion as root no longer (re-)define
KERNELRELEASE for each run. With this patch KERNELRELEASE is
only re-read when we do an actual kernel build.
Rationale behind this is "do as little as possible" when executing
make install - as root!

A new file named .kernelrelease is strored in the root of the kernel
tree containing the actual version string.
So when we use do a kernel build the .kernelrelease file will be updated.
But in all other situations it is left as-is.

To make it more visible the kernel now prints out the version being build.
Sample:
Building kernel 2.6.15-g63b794bf-dirty
...
...

The patch also un-exports VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION
since all users of these are anyway broken - and none is left in the
tree.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

+53 -42
+53 -42
Makefile
··· 141 141 142 142 export srctree objtree VPATH TOPDIR 143 143 144 - nullstring := 145 - space := $(nullstring) # end of line 146 - 147 - # Take the contents of any files called localversion* and the config 148 - # variable CONFIG_LOCALVERSION and append them to KERNELRELEASE. Be 149 - # careful not to include files twice if building in the source 150 - # directory. LOCALVERSION from the command line override all of this 151 - 152 - localver := $(objtree)/localversion* $(srctree)/localversion* 153 - localver := $(sort $(wildcard $(localver))) 154 - # skip backup files (containing '~') 155 - localver := $(foreach f, $(localver), $(if $(findstring ~, $(f)),,$(f))) 156 - 157 - LOCALVERSION = $(subst $(space),, \ 158 - $(shell cat /dev/null $(localver)) \ 159 - $(patsubst "%",%,$(CONFIG_LOCALVERSION))) 160 - 161 - KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION) 162 144 163 145 # SUBARCH tells the usermode build what the underlying arch is. That is set 164 146 # first, and if a usermode build is happening, the "ARCH=um" on the command ··· 335 353 -ffreestanding 336 354 AFLAGS := -D__ASSEMBLY__ 337 355 338 - export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \ 356 + # Read KERNELRELEASE from .kernelrelease (if it exists) 357 + KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null) 358 + 359 + export KERNELRELEASE \ 339 360 ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ 340 361 CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \ 341 362 HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS ··· 535 550 # INSTALL_PATH specifies where to place the updated kernel and system map 536 551 # images. Default is /boot, but you can set it to other values 537 552 export INSTALL_PATH ?= /boot 538 - 539 - # If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests 540 - # and try to determine if the current source tree is a release tree, of any sort, 541 - # or if is a pure development tree. 542 - # 543 - # A 'release tree' is any tree with a git TAG associated 544 - # with it. The primary goal of this is to make it safe for a native 545 - # git/CVS/SVN user to build a release tree (i.e, 2.6.9) and also to 546 - # continue developing against the current Linus tree, without having the Linus 547 - # tree overwrite the 2.6.9 tree when installed. 548 - # 549 - # Currently, only git is supported. 550 - # Other SCMs can edit scripts/setlocalversion and add the appropriate 551 - # checks as needed. 552 - 553 - 554 - ifdef CONFIG_LOCALVERSION_AUTO 555 - localversion-auto := $(shell $(PERL) $(srctree)/scripts/setlocalversion $(srctree)) 556 - LOCALVERSION := $(LOCALVERSION)$(localversion-auto) 557 - endif 558 553 559 554 # 560 555 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory ··· 747 782 $(vmlinux-dirs): prepare scripts 748 783 $(Q)$(MAKE) $(build)=$@ 749 784 785 + # Build the kernel release string 786 + # The KERNELRELEASE is stored in a file named .kernelrelease 787 + # to be used when executing for example make install or make modules_install 788 + # 789 + # Take the contents of any files called localversion* and the config 790 + # variable CONFIG_LOCALVERSION and append them to KERNELRELEASE. 791 + # LOCALVERSION from the command line override all of this 792 + 793 + nullstring := 794 + space := $(nullstring) # end of line 795 + 796 + ___localver = $(objtree)/localversion* $(srctree)/localversion* 797 + __localver = $(sort $(wildcard $(___localver))) 798 + # skip backup files (containing '~') 799 + _localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f))) 800 + 801 + localver = $(subst $(space),, \ 802 + $(shell cat /dev/null $(_localver)) \ 803 + $(patsubst "%",%,$(CONFIG_LOCALVERSION))) 804 + 805 + # If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called 806 + # and if the SCM is know a tag from the SCM is appended. 807 + # The appended tag is determinded by the SCM used. 808 + # 809 + # Currently, only git is supported. 810 + # Other SCMs can edit scripts/setlocalversion and add the appropriate 811 + # checks as needed. 812 + ifdef CONFIG_LOCALVERSION_AUTO 813 + _localver-auto = $(shell $(CONFIG_SHELL) \ 814 + $(srctree)/scripts/setlocalversion $(srctree)) 815 + localver-auto = $(LOCALVERSION)$(_localver-auto) 816 + endif 817 + 818 + localver-full = $(localver)$(localver-auto) 819 + 820 + # Store (new) KERNELRELASE string in .kernelrelease 821 + kernelrelease = \ 822 + $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(localver-full) 823 + .kernelrelease: FORCE 824 + $(Q)rm -f .kernelrelease 825 + $(Q)echo $(kernelrelease) > .kernelrelease 826 + $(Q)echo " Building kernel $(kernelrelease)" 827 + 828 + 750 829 # Things we need to do before we recursively start building the kernel 751 830 # or the modules are listed in "prepare". 752 831 # A multi level approach is used. prepareN is processed before prepareN-1. ··· 807 798 # and if so do: 808 799 # 1) Check that make has not been executed in the kernel src $(srctree) 809 800 # 2) Create the include2 directory, used for the second asm symlink 810 - 811 - prepare3: 801 + prepare3: .kernelrelease 812 802 ifneq ($(KBUILD_SRC),) 813 803 @echo ' Using $(srctree) as source for kernel' 814 804 $(Q)if [ -f $(srctree)/.config ]; then \ ··· 994 986 MRPROPER_DIRS += include/config include2 995 987 MRPROPER_FILES += .config .config.old include/asm .version .old_version \ 996 988 include/linux/autoconf.h include/linux/version.h \ 997 - Module.symvers tags TAGS cscope* 989 + .kernelrelease Module.symvers tags TAGS cscope* 998 990 999 991 # clean - Delete most, but leave enough to build external modules 1000 992 # ··· 1080 1072 @echo ' tags/TAGS - Generate tags file for editors' 1081 1073 @echo ' cscope - Generate cscope index' 1082 1074 @echo ' kernelrelease - Output the release version string' 1075 + @echo ' kernelversion - Output the version stored in Makefile' 1083 1076 @echo '' 1084 1077 @echo 'Static analysers' 1085 1078 @echo ' buildcheck - List dangling references to vmlinux discarded sections' ··· 1302 1293 1303 1294 kernelrelease: 1304 1295 @echo $(KERNELRELEASE) 1296 + kernelversion: 1297 + @echo $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) 1305 1298 1306 1299 # FIXME Should go into a make.lib or something 1307 1300 # ===========================================================================