home | list info | list archive | date index | thread index

[OCLUG-Tech] make environment variables and the kbuild system

  • Subject: [OCLUG-Tech] make environment variables and the kbuild system
  • From: "Robert P. J. Day" <rpjday [ at ] crashcourse [ dot ] ca>
  • Date: Mon, 20 Apr 2015 08:30:44 -0400 (EDT)
  as a followup to my last post, i want to clarify the use of the
"option env=" directive in kernel Kconfig files, which i thought i
understood pretty well but (again) i want to make sure.

  first, under normal circumstances, there is no relationship between
make variables and Kconfig variables when configuring the kernel, that
much i'm pretty sure about. but there is a kconfig directive that
allows a Kconfig file access to an environment variable, and here's a
convenient example in the kernel source.

  in the top-level Makefile, there's the variable KERNELVERSION set
and exported thusly:



and which can be checked via the trivial and convenient target in the
very same Makefile:

        @echo $(KERNELVERSION)

so it's easy enough to verify the value of that variable from the
perspective of the Makefile:

$ make kernelversion

  related to that, in the top-level Kconfig file, a variable by that
same name is used to generate the "make menuconfig" banner thusly:

mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration"

and in the file init/Kconfig, there's the snippet that allows the
kbuild system to the environment variable by that name:

        option env="KERNELVERSION"

so all of the above means that, regardless of how the KERNELVERSION
variable is added to the make environment, it will be accessible to
the kbuild environment under the same name, and all of that is
explained in the doc file Documentation/kbuild/kconfig-language.txt:

  - "env"=<value>
    This imports the environment variable into Kconfig. It behaves like
    a default, except that the value comes from the environment, this
    also means that the behaviour when mixing it with normal defaults is
    undefined at this point. The symbol is currently not exported back
    to the build environment (if this is desired, it can be done via
    another symbol).

so given all of the above, it's also fairly easy to verify that the
kbuild system is picking up that variable from the environment by just
running, say, "make menuconfig" and reading the banner line at the
top of the configuration dialog screen:

       .config - Linux/x86 4.0.0 Kernel Configuration

the one thing i did notice just recently is that in order to override
that variable, one has to do it on the make command line with:

  $ make KERNELVERSION=rday kernelversion

now here's the part that i just stumbled across that confuses me. what
does the documentation mean with:

"The symbol is currently not exported back to the build environment
(if this is desired, it can be done via another symbol)."

  it had never occurred to me to try to export such a variable back to
the [make?] build environment, but apparently it can be done with
"another symbol", and just recently while playing with buildroot, i
saw this in the top-level Config.in file:

config BR2_VERSION
        option env="BR2_VERSION_FULL"

so this would seem to be an example of a kbuild variable that is being
associated with an environment variable of a different name. can
someone clarify what is being done here, and why?



Robert P. J. Day                                 Ottawa, Ontario, CANADA

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday