Skip to contentSkip to conversation

kbuild: Support LOCALVERSION

PATCH In review Sam Ravnborg 4 participants 10 messages Aug 31, 2004 – Sep 5, 2004 Kbuild

lore
Share & tools
lore
#0 lore raw

The following patch combines the request from several people. If you place a file named localversion* in the root of your soruce tree or the root of your output tree the text included in this file will be appended to KERNELRELEASE.

LOCALVERSION was originally introduced by Ian Wienand <[email protected]>

This allows one to put a short string in localversion identifying this particular configuration "-smpacpi", or to identify applied patches to the source "-llat-np".

More specifically:
$(srctree)/localversion-lowlatency contains "-llat" $(srctree)/localversion-scheduler-nick constins "-np"

$(objtree)/localversion contains "-smpacpi"

Resulting KERNELRELEASE would be:
2.6.8.rc1-smpacpi-llat-np

Note that you no longer need to modify your Makefile to identify your kernel so no rejects when applying new patches.
If you add a new localversion* file, or change a existing one kbuild will pick up this and do the proper rebuild next time you run make.

Only issue is that KERNELRELEASE needs to be <= 64 chars - so keep the names short.

kbuild errors out if you are above limit.

$ cat localviersion-long
very-long-version-in-localversion-file-exceeding-64-chars-for-sure
Example:
  CHK     include/linux/version.h
"2.6.9-rc1-very-long-version-in-localversion-file-exceeding-64-chars-for-sure" exceeds 64 characters
make: *** [include/linux/version.h] Error 1

Where do we document this?

[This is deliberately not pushed to my bk tree - want some comments first].

Sam

===== Makefile 1.526 vs edited =====

Makefile +12 -4
@@ -141,7 +141,14 @@ VPATH		:= $(srctree)
 
 export srctree objtree VPATH TOPDIR
 
-KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
+nullstring := 
+space      := $(nullstring) # end of line
+
+LOCALVERSION := $(subst $(space),, \
+                $(shell cat /dev/null $(objtree)/localversion* \
+                $(if $(KBUILD_SRC),$(srctree)/localversion*)))
+
+KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
 
 # SUBARCH tells the usermode build what the underlying arch is.  That is set
 # first, and if a usermode build is happening, the "ARCH=um" on the command
@@ -329,8 +336,8 @@ CFLAGS 		:= -Wall -Wstrict-prototypes -W
 	  	   -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__
 
-export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
-	CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
+export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
+	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_BLOB LDFLAGS_MODULE CHECK CHECKFLAGS
 
@@ -763,7 +770,8 @@ define filechk_version.h
 	)
 endef
 
-include/linux/version.h: Makefile
+include/linux/version.h: $(srctree)/Makefile \
+                         $(objtree)/localversion* $(srctree)/localversion*
 	$(call filechk,version.h)
 
 # ---------------------------------------------------------------------------
#1 lore raw
Quoted 4 lines · Sam Ravnborg

The following patch combines the request from several people. If you place a file named localversion* in the root of your soruce tree or the root of your output tree the text included in this file will be appended to KERNELRELEASE.

With this patch *without* a localversion file I get

ianw@baci:/tmp/kbuild-test$ make
cat: /tmp/kbuild-test/localversion*: No such file or directory
make: *** No rule to make target `/tmp/kbuild-test/localversion*', needed by `include/linux/version.h'.  Stop.

However, with the right files there it works as you describe.

The interaction with LOCALVERSION from the command line (i.e. make LOCALVERSION=aversion) is still a bit funny too, since it won't cause version.h to be rebuilt. Is it going to just be a case of "you can't specify LOCALVERSION" from the command line?

My original patch also had a Kconfig option which would be inserted; I figured this might be good because if you're creating a bunch of different configs you are probably in [menu|x]config to change the options, so it might be convenient to just set it via a string in there. Would anyone else like to see that?

-i

#2 lore raw
Quoted 7 lines · Ian Wienand

With this patch *without* a localversion file I get

ianw@baci:/tmp/kbuild-test$ make
cat: /tmp/kbuild-test/localversion*: No such file or directory
make: *** No rule to make target `/tmp/kbuild-test/localversion*', needed by `include/linux/version.h'.  Stop.

However, with the right files there it works as you describe.

Sorry to reply to myself, but I forgot to include a suggested patch (attached).

-i

===== Makefile 1.523 vs edited =====

Makefile +11 -4
@@ -141,7 +141,14 @@
 
 export srctree objtree VPATH TOPDIR
 
-KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
+nullstring := 
+space      := $(nullstring) # end of line
+localversion-files := $(wildcard $(objtree)/localversion* $(srctree)/localversion*)
+
+LOCALVERSION := $(subst $(space),, \
+                $(shell cat /dev/null $(localversion-files)))
+
+KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
 
 # SUBARCH tells the usermode build what the underlying arch is.  That is set
 # first, and if a usermode build is happening, the "ARCH=um" on the command
@@ -329,8 +336,8 @@
 	  	   -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__
 
-export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
-	CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
+export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
+	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_BLOB LDFLAGS_MODULE CHECK CHECKFLAGS
 
@@ -763,7 +770,7 @@
 	)
 endef
 
-include/linux/version.h: Makefile
+include/linux/version.h: $(srctree)/Makefile $(localversion-files)
 	$(call filechk,version.h)
 
 # ---------------------------------------------------------------------------
#3 lore raw
Quoted 3 lines · Ian Wienand

Sorry to reply to myself, but I forgot to include a suggested patch (attached).

Thanks for the fix.

Makefile line 775

Quoted 8 lines
Makefile +1 -1
@@ -763,7 +770,7 @@
 	)
 endef
 
-include/linux/version.h: Makefile
+include/linux/version.h: $(srctree)/Makefile $(localversion-files)
 	$(call filechk,version.h)
 

We could just make this:
include/linux/version.h: FORCE

       $(call filechk,version.h)

Then version.h would be updated also if LOCALVERSION is specified on the command line.
Only issue is that it will always be checked - but the same goes for a few other files.

Sam

#4 lore raw
In reply to Sam Ravnborg
Quoted 4 lines · Sam Ravnborg

This allows one to put a short string in localversion identifying this particular configuration "-smpacpi", or to identify applied patches to the source "-llat-np".

Quoted 8 lines

More specifically:
$(srctree)/localversion-lowlatency contains "-llat" $(srctree)/localversion-scheduler-nick constins "-np"

$(objtree)/localversion contains "-smpacpi"

Resulting KERNELRELEASE would be:
2.6.8.rc1-smpacpi-llat-np

Wouldn't it make more sense the other way around (i.e. first append $(srctree)/localversion-*, then append $(objtree)/localversion*)?

Hmm, from a second thought the order depends on what your most interested in:
building kernels with different configs, or building kernels from different sources.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#5 lore raw
Quoted 14 lines · Sam Ravnborg
Quoted 4 lines

This allows one to put a short string in localversion identifying this particular configuration "-smpacpi", or to identify applied patches to the source "-llat-np".

Quoted 8 lines

More specifically:
$(srctree)/localversion-lowlatency contains "-llat" $(srctree)/localversion-scheduler-nick constins "-np"

$(objtree)/localversion contains "-smpacpi"

Resulting KERNELRELEASE would be:
2.6.8.rc1-smpacpi-llat-np

Quoted 9 lines

Wouldn't it make more sense the other way around (i.e. first append $(srctree)/localversion-*, then append $(objtree)/localversion*)?

Hmm, from a second thought the order depends on what your most interested in:
building kernels with different configs, or building kernels from different
sources.

My rationale was that the config used would vary more than the source. I also thought about sorting the files - but if Andrew for example start using this it would maybe come in the middle. Therefore this more simple approach.

Sam

#6 lore raw
In reply to Sam Ravnborg

On Tue, 2004-08-31 21:26:43 +0200, Sam Ravnborg <[email protected]> wrote in message <[email protected]>:

Quoted 11 lines

The following patch combines the request from several people. If you place a file named localversion* in the root of your soruce tree or the root of your output tree the text included in this file will be appended to KERNELRELEASE.

LOCALVERSION was originally introduced by Ian Wienand <[email protected]>

This allows one to put a short string in localversion identifying this particular configuration "-smpacpi", or to identify applied patches to the source "-llat-np".

Quoted 8 lines

More specifically:
$(srctree)/localversion-lowlatency contains "-llat" $(srctree)/localversion-scheduler-nick constins "-np"

$(objtree)/localversion contains "-smpacpi"

Resulting KERNELRELEASE would be:
2.6.8.rc1-smpacpi-llat-np

Basically: I love it. Maybe it would also be good (in the longer term) to introduce a config name into one of the Kconfig files, which is preserved in the .config file (eg. SuSE does something like that and even while I'm not a SuSE user, it's really dandy at some times, esp. for things like "SMP-4GB", "VAX-KA4x" and the like). It's basically like adding the defconfig_* name to some of the variables :-)

MfG, JBG
PS: When will the package support show up?

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#7 lore raw
Quoted 6 lines · Jan-Benedict Glaw

Maybe it would also be good (in the longer term)
to introduce a config name into one of the Kconfig files, which is preserved in the .config file (eg. SuSE does something like that and even while I'm not a SuSE user, it's really dandy at some times, esp. for things like "SMP-4GB", "VAX-KA4x" and the like). It's basically like adding the defconfig_* name to some of the variables :-)

Ian addedconfig CONFIG_LOCALVERSION to a Kconfig file. I will try to add it and see how it turns out. If Ian does not beat me..

Quoted 1 line

PS: When will the package support show up?

UML needs to be finised first.
I have several packages related patches queued up. But I want to give it an extra look since there are several basic issues I am not satisfied with.

Sam

#8 lore raw

PATCH 1/1 kbuild: Support LOCALVERSION

Quoted 2 lines · Sam Ravnborg

Ian addedconfig CONFIG_LOCALVERSION to a Kconfig file. I will try to add it and see how it turns out. If Ian does not beat me..

Ok, here is my attempt. I think it does everything everyone wants

* localversion* files are read first
* config variable is appended last
* LOCALVERSION from the command line overrides all of this
* check is forced on build, since we can't really know when the config or environment options change.

Thanks,

-i

Add LOCALVERSION so we can append strings that show up in uname without having to fiddle with the Makefile and EXTRAVERSION, etc.

===== Makefile 1.523 vs edited =====

Makefile +25 -6
@@ -141,7 +141,26 @@
 
 export srctree objtree VPATH TOPDIR
 
-KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
+nullstring := 
+space      := $(nullstring) # end of line
+
+# Take the contents of any files called localversion and the config
+# variable CONFIG_LOCALVERSION and append them to KERNELRELEASE.  Be
+# careful not to include files twice if building in the source
+# directory.  LOCALVERSION from the command line should override all
+# of this
+
+ifeq ($(objtree),$(srctree))
+localversion-files := $(wildcard $(srctree)/localversion*)
+else
+localversion-files := $(wildcard $(objtree)/localversion* $(srctree)/localversion*)
+endif
+
+LOCALVERSION = $(subst $(space),, \
+	       $(shell cat /dev/null $(localversion-files)) \
+	       $(subst ",,$(CONFIG_LOCALVERSION)))
+
+KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
 
 # SUBARCH tells the usermode build what the underlying arch is.  That is set
 # first, and if a usermode build is happening, the "ARCH=um" on the command
@@ -329,8 +348,8 @@
 	  	   -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__
 
-export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
-	CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
+export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
+	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_BLOB LDFLAGS_MODULE CHECK CHECKFLAGS
 
@@ -747,8 +766,8 @@
 # Generate some files
 # ---------------------------------------------------------------------------
 
-#	version.h changes when $(KERNELRELEASE) etc change, as defined in
-#	this Makefile
+#	KERNELRELEASE can change from a few different places, meaning version.h 
+#	needs to be updated, so this check is forced on all builds
 
 uts_len := 64
 
@@ -763,7 +782,7 @@
 	)
 endef
 
-include/linux/version.h: Makefile
+include/linux/version.h: $(srctree)/Makefile $(localversion-files) FORCE
 	$(call filechk,version.h)
 
 # ---------------------------------------------------------------------------

===== init/Kconfig 1.48 vs edited =====

init/Kconfig +10 -0
@@ -293,6 +293,16 @@
 	  option replaces shmem and tmpfs with the much simpler ramfs code,
 	  which may be appropriate on small systems without swap.
 
+config LOCALVERSION
+	string "Local Version"
+	help
+	  Append an extra string to the end of your kernel version.
+	  This will show up when you type uname, for example.
+	  The string you set here will be appended after the contents of 
+	  any files with a filename matching localversion* in your 
+	  object and source tree, in that order.  Your total string can
+	  be a maximum of 64 characters.
+
 endmenu		# General setup
 
 config TINY_SHMEM
#9 lore raw
Quoted 12 lines · Ian Wienand
Quoted 2 lines · Sam Ravnborg

Ian addedconfig CONFIG_LOCALVERSION to a Kconfig file. I will try to add it and see how it turns out. If Ian does not beat me..

Ok, here is my attempt. I think it does everything everyone wants

* localversion* files are read first
* config variable is appended last
* LOCALVERSION from the command line overrides all of this
* check is forced on build, since we can't really know when the config or environment options change.

Quoted 3 lines

Thanks,

-i

applied - thanks (your mailer broke the patch but I fixed it up)

Sam