Kconfig extensions
Zephyr uses the Kconfiglib implementation of Kconfig, which includes some Kconfig extensions:
Default values can be applied to existing symbols without weakening the symbols dependencies through the use of
configdefault.config FOO bool "FOO" depends on BAR configdefault FOO default y if FIZZThe statement above is equivalent to:
config FOO bool "Foo" default y if FIZZ depends on BARconfigdefaultsymbols cannot contain any fields other thandefault, however they can be wrapped inifstatements. The two statements below are equivalent:configdefault FOO default y if BAR if BAR configdefault FOO default y endif # BAREnvironment variables in
sourcestatements are expanded directly, meaning no “bounce” symbols withoption env="ENV_VAR"need to be defined.Note
option envhas been removed from the C tools as of Linux 4.18 as well.The recommended syntax for referencing environment variables is
$(FOO)rather than$FOO. This uses the new Kconfig preprocessor. The$FOOsyntax for expanding environment variables is only supported for backwards compatibility.The
sourcestatement supports glob patterns and includes each matching file. A pattern is required to match at least one file.Consider the following example:
source "foo/bar/*/Kconfig"
If the pattern
foo/bar/*/Kconfigmatches the filesfoo/bar/baz/Kconfigandfoo/bar/qaz/Kconfig, the statement above is equivalent to the following twosourcestatements:source "foo/bar/baz/Kconfig" source "foo/bar/qaz/Kconfig"
If no files match the pattern, an error is generated.
The wildcard patterns accepted are the same as for the Python glob module.
For cases where it’s okay for a pattern to match no files (or for a plain filename to not exist), a separate
osource(optional source) statement is available.osourceis a no-op if no file matches.Note
sourceandosourceare analogous toincludeand-includein Make.An
rsourcestatement is available for including files specified with a relative path. The path is relative to the directory of theKconfigfile that contains thersourcestatement.As an example, assume that
foo/Kconfigis the top-levelKconfigfile, and thatfoo/bar/Kconfighas the following statements:source "qaz/Kconfig1" rsource "qaz/Kconfig2"
This will include the two files
foo/qaz/Kconfig1andfoo/bar/qaz/Kconfig2.rsourcecan be used to createKconfig“subtrees” that can be moved around freely.rsourcealso supports glob patterns.A drawback of
rsourceis that it can make it harder to figure out where a file gets included, so only use it if you need it.An
orsourcestatement is available that combinesosourceandrsource.For example, the following statement will include
Kconfig1andKconfig2from the current directory (if they exist):orsource "Kconfig[12]"
def_int,def_hex, anddef_stringkeywords are available, analogous todef_bool. These set the type and add adefaultat the same time.A symbol name can be associated to
choicegroups using thechoice <symbol>syntax. Such choices, called named choices, can be modified from places other than their initial definition. For example, the following statements define the named choiceFOOBAR:choice FOOBAR prompt "Example choice" default BAR config FOO bool "Foo" config BAR bool "Bar" endchoice
The following statements could then be used, in a
Kconfig.defconfigfile for example, to override the default option of choiceFOOBAR:# Note how "prompt" is not present here choice FOOBAR default FOO endchoice
Note
The named choices feature originates from Linux, but it is no longer supported in Linux since kernel release 6.9, and has thus become a Kconfiglib language extension.