Documentation/kbuild/kconfig-macro-language.rst

Source file repositories/reference/linux-study-clean/Documentation/kbuild/kconfig-macro-language.rst

File Facts

System
Linux kernel
Corpus path
Documentation/kbuild/kconfig-macro-language.rst
Extension
.rst
Size
8261 bytes
Lines
248
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

======================
Kconfig macro language
======================

Concept
-------

The basic idea was inspired by Make. When we look at Make, we notice sort of
two languages in one. One language describes dependency graphs consisting of
targets and prerequisites. The other is a macro language for performing textual
substitution.

There is clear distinction between the two language stages. For example, you
can write a makefile like follows::

    APP := foo
    SRC := foo.c
    CC := gcc

    $(APP): $(SRC)
            $(CC) -o $(APP) $(SRC)

The macro language replaces the variable references with their expanded form,
and handles as if the source file were input like follows::

    foo: foo.c
            gcc -o foo foo.c

Then, Make analyzes the dependency graph and determines the targets to be
updated.

The idea is quite similar in Kconfig - it is possible to describe a Kconfig
file like this::

    CC := gcc

    config CC_HAS_FOO
            def_bool $(shell, $(srctree)/scripts/gcc-check-foo.sh $(CC))

The macro language in Kconfig processes the source file into the following
intermediate::

    config CC_HAS_FOO
            def_bool y

Then, Kconfig moves onto the evaluation stage to resolve inter-symbol
dependency as explained in kconfig-language.rst.


Variables
---------

Like in Make, a variable in Kconfig works as a macro variable.  A macro
variable is expanded "in place" to yield a text string that may then be
expanded further. To get the value of a variable, enclose the variable name in
$( ). The parentheses are required even for single-letter variable names; $X is
a syntax error. The curly brace form as in ${CC} is not supported either.

There are two types of variables: simply expanded variables and recursively
expanded variables.

A simply expanded variable is defined using the := assignment operator. Its
righthand side is expanded immediately upon reading the line from the Kconfig
file.

A recursively expanded variable is defined using the = assignment operator.
Its righthand side is simply stored as the value of the variable without
expanding it in any way. Instead, the expansion is performed when the variable
is used.

Annotation

Implementation Notes