kbuild: create .kernelrelease at *config step

To enable 'make kernelrelease' earlier now create .kernelrelease when
one of the *config targets are used.
Also introduce KERNELVERSION - only user is kconfig.
KERNELVERSION was needed to display kernel version in menuconfig -
KERNELRELEASE is not valid until configuration has completed.
kconfig files modified to use KERNELVERSION.
Bug reported by: Rene Rebe <rene@exactcode.de>

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
diff --git a/Makefile b/Makefile
index b3dd9db..22e322f 100644
--- a/Makefile
+++ b/Makefile
@@ -338,8 +338,9 @@
 
 # Read KERNELRELEASE from .kernelrelease (if it exists)
 KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null)
+KERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
-export	VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE \
+export	VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
 	ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
 	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
 	HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
@@ -434,6 +435,7 @@
 config %config: scripts_basic outputmakefile FORCE
 	$(Q)mkdir -p include/linux
 	$(Q)$(MAKE) $(build)=scripts/kconfig $@
+	$(Q)$(MAKE) .kernelrelease
 
 else
 # ===========================================================================
@@ -784,12 +786,10 @@
 localver-full = $(localver)$(localver-auto)
 
 # Store (new) KERNELRELASE string in .kernelrelease
-kernelrelease = \
-       $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(localver-full)
+kernelrelease = $(KERNELVERSION)$(localver-full)
 .kernelrelease: FORCE
-	$(Q)rm -f .kernelrelease
-	$(Q)echo $(kernelrelease) > .kernelrelease
-	$(Q)echo "  Building kernel $(kernelrelease)"
+	$(Q)rm -f $@
+	$(Q)echo $(kernelrelease) > $@
 
 
 # Things we need to do before we recursively start building the kernel
@@ -899,7 +899,7 @@
 	)
 endef
 
-include/linux/version.h: $(srctree)/Makefile FORCE
+include/linux/version.h: $(srctree)/Makefile .config FORCE
 	$(call filechk,version.h)
 
 # ---------------------------------------------------------------------------
@@ -1302,9 +1302,10 @@
 	$(PERL) $(src)/scripts/checkstack.pl $(ARCH)
 
 kernelrelease:
-	@echo $(KERNELRELEASE)
+	$(if $(wildcard .kernelrelease), $(Q)echo $(KERNELRELEASE), \
+	$(error kernelrelease not valid - run 'make *config' to update it))
 kernelversion:
-	@echo $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
+	@echo $(KERNELVERSION)
 
 # FIXME Should go into a make.lib or something 
 # ===========================================================================