Can anyone provide me the syntax of obtaining the value of environment variable in Kconfig file?
Based on the value of environment variable I need to conditionally source another Kconfig file.
What is KConfig? KConfig is a selection-based configuration system originally developed for the Linux kernel. It is commonly used to select build-time options and to enable or disable features, and has now found use in other projects beyond the Linux kernel.
The /etc/environment file contains variables specifying the basic environment for all processes. When a new process begins, the exec subroutine makes an array of strings available that have the form Name=Value. This array of strings is called the environment.
It should be placed at the top of the configuration, before any other statement. '#' Kconfig source file comment: An unquoted '#' character anywhere in a source file line indicates the beginning of a source file comment. The remainder of that line is a comment.
select will force a symbol to a value without visiting the dependencies. By abusing select you are able to select a symbol FOO even if FOO depends on BAR that is not set. In general use select only for non-visible symbols (no prompts anywhere) and for symbols with no dependencies.
You will need to capture the value of the environment variable in a config symbol using 'option env', like in the following:
config ENV_VAR string option env="ENV_VAR" if ENV_VAR = "foo" source "foo_file" endif
As a side note, $-references in 'source' statements refer to config variables, not to environment variables. You can't do something like
source "foo/$ENV_VAR/Kconfig"
You will instead need to do
config ENV_VAR_SYM string option env="ENV_VAR" source "foo/$ENV_VAR_SYM/Kconfig"
(ENV_VAR_SYM could of course be called ENV_VAR as well; I just changed the name to clarify things.)
For another example, see the top-level Kconfig file in the kernel root.
(I'm the author of Kconfiglib Kconfiglib, a library for working with Kconfig-based configuration systems.)
As per the kconfig docs:
<expr> ::= <symbol> (1)
<symbol> '=' <symbol> (2)
<symbol> '!=' <symbol> (3)
'(' <expr> ')' (4)
'!' <expr> (5)
<expr> '&&' <expr> (6)
<expr> '||' <expr> (7)
- misc options: "option" <symbol>[=<value>]
- "env"=<value>
This imports the environment variable into Kconfig.
if:
"if" <expr>
<if block>
"endif"
This defines an if block. The dependency expression <expr> is appended
to all enclosed menu entries.
source:
"source" <prompt>
This reads the specified configuration file. This file is always parsed.
So I'd try
option env="YOURVAR"
if YOURVAR=foo
source "somefile"
endif
if YOURVAR!=foo
source "someotherfile"
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With