Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax to get the value of environment variable in Kconfig file

Tags:

linux-kernel

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.

like image 650
Vivek Maran Avatar asked Apr 11 '12 03:04

Vivek Maran


People also ask

What is the use of KConfig file in Linux?

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.

What is environment variable file?

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.

How do I comment in KConfig file?

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.

What is select in KConfig?

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.


2 Answers

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.)

like image 124
Ulf Magnusson Avatar answered Sep 29 '22 03:09

Ulf Magnusson


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
like image 21
Mikel Avatar answered Sep 29 '22 02:09

Mikel