内核2.6.39/Documentation/kbuild/kconfig-language.txt

介绍
------------


这个配置数据库是以树形结构组织的配置选项的集合:

 - 代码成熟级别选项
| - 提示开发和/或不完整的代码/驱动器
- 常规设置
| - 网络支持
| - 系统V IPC
| - BSD的进程记帐
| - sysctl的支持
- 支持可装载模块
| - 启用支持可装载模块
| - 所有模块符号上设置版本信息
| - 内核模块加载
- ... ...



每个条目都有其自己的依赖。这些相依确定一个条目的知名度。任何子条目只可见,如果它的父条目也同样明显。

Menu 条目
------------


大多数条目定义一个配置选项:所有其他条目帮助组织它们。一个单个的配置是像这样定义的:


config MODVERSIONS
bool "Set version information on all module symbols"
depends on MODULES
help
 Usually, modules have to be recompiled whenever you switch to a new
 kernel.  ...

每行开始一个关键的词,并可跟随多个参数。“配置”启动一个新的配置项。下面的几行定义这个配置选项的属性。属性可以是配置选项类型,输入提示,依赖,帮助文本和默认
值。一个配置选项可以以同名方式多次定义,但是每一次定义只有一个输入提示并且类型不能冲突。




Menu attributes
---------------


菜单项可以有一些属性。它们并不是所有的都在任何地方适用。(见语法)


- 类型的定义:“BOOL”/“三态”/“字符串”/“十六进制”/“诠释”  
 每一个配置选项必须有一个类型。
 只有两个基本类型:  态和字符串;
 其它类型的基于这两个。类型 定义选择性地接受一个输入提示,所以这两个例子 是等价的:


bool "Networking support"

bool
prompt "Networking support"


 -输入提示:“提示”<prompt>[“if<expr>]
  每个菜单项可以有至多一个提示,这是用来显示
  给用户。仅适用于这条提示的可选依赖可以使用 ["if" <expr>]添加。


 -默认值:“default<expr>[“if<expr>]
   一个配置选项可以有任意数量的默认值。如果多个默认值是可见的,只有第一个定义是可用的。
  默认值是不局限于他们定义的菜单项。这意味着默认值可以定义在别处或者被一个早期定义覆盖。
  默认值是只分配给配置符号,如果用户没有设置其他值(通过上面的输入提示)。
  如果输入 提示是可见的默认值是呈现给用户,并且可以被他所覆盖。
  可选,仅此默认值的依赖关系,可加用  “if”。



- 类型定义 + 默认值:
"def_bool"/"def_tristate" <expr> ["if" <expr>]

  这是一个类型定义+一个值得速记符号。这个默认值的可选依赖可以通过“if”添加。



- dependencies: "depends on" <expr>

  它定义了这个菜单条目的依赖关系。如果多个依赖关系被定义了,他们将通过‘&&’连接。依赖关系同样适用于本菜单条目的其他所有选项(也能够接受“if”表达式的),所以下面两个示例是相等的:

bool "foo" if BAR

default y if BAR

depends on BAR
bool "foo"
default y


- 反向依赖关系:: "select" <symbol> ["if" <expr>]
 当正常的依赖关系降低了一个符号的上限,反向依赖关系可以用来强制另一个符号的下限。当前菜单符号的值被设置做最小值<symbol> . 如果<symbol>被多次选择,极限则可设置为最大选择。反向依赖只能被 boolean或者 tristate符号使用。
注意:
select 应该小心使用。 select将强制使一个符号转变成一个值,而并不访问其依赖关系。通过滥用select,你能够选择一个符号FOO,即使FOO依赖的BAR并没有设置。在通常的使用中,select只被用于非可见符号(不是任何地方都提示)和一些没有依赖关系的符号。这将限制限制某些用途,但是从另一方面来讲,避免了各处的非法配置 。 


- 数值范围: "range" <symbol> <symbol> ["if" <expr>]
  它允许限制整型或者十六进制符号的可能的输入值的范围。用户可以仅仅输入一个大于或者等译第一个符号的值,或者小于等于第二个符号。


- 帮助文本: "help" or "---help---"
  它定义了一个帮助文本。帮助文本的结尾This defines a help text. The end of the help text is determined by
  the indentation level, 这意味着它在第一行结束this means it ends at the first line which has
  a smaller indentation than the first line of the help text.
  "---help---" and "help" do not differ in behaviour, "---help---" is
  used to help visually separate configuration logic from help within
  the file as an aid to developers.


- 混合 options: "option" <symbol>[=<value>]
  Various less common options can be defined via this option syntax,
  which can modify the behaviour of the menu entry and its config
  symbol. These options are currently possible:


  - "defconfig_list"
    This declares a list of default entries which can be used when
    looking for the default configuration (which is used when the main
    .config doesn't exists yet.)


  - "modules"
    This declares the symbol to be used as the MODULES symbol, which
    enables the third modular state for all config symbols.


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


Menu dependencies
-----------------


Dependencies define the visibility of a menu entry and can also reduce
the input range of tristate symbols. The tristate logic used in the
expressions uses one more state than normal boolean logic to express the
module state. Dependency expressions have the following syntax:


<expr> ::= <symbol>                             (1)
           <symbol> '=' <symbol>                (2)
           <symbol> '!=' <symbol>               (3)
           '(' <expr> ')'                       (4)
           '!' <expr>                           (5)
           <expr> '&&' <expr>                   (6)
           <expr> '||' <expr>                   (7)


Expressions are listed in decreasing order of precedence. 


(1) Convert the symbol into an expression. Boolean and tristate symbols
    are simply converted into the respective expression values. All
    other symbol types result in 'n'.
(2) If the values of both symbols are equal, it returns 'y',
    otherwise 'n'.
(3) If the values of both symbols are equal, it returns 'n',
    otherwise 'y'.
(4) Returns the value of the expression. Used to override precedence.
(5) Returns the result of (2-/expr/).
(6) Returns the result of min(/expr/, /expr/).
(7) Returns the result of max(/expr/, /expr/).


An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
respectively for calculations). A menu entry becomes visible when its
expression evaluates to 'm' or 'y'.


There are two types of symbols: constant and non-constant symbols.
Non-constant symbols are the most common ones and are defined with the
'config' statement. Non-constant symbols consist entirely of alphanumeric
characters or underscores.
Constant symbols are only part of expressions. Constant symbols are
always surrounded by single or double quotes. Within the quote, any
other character is allowed and the quotes can be escaped using '\'.


Menu structure
--------------


The position of a menu entry in the tree is determined in two ways. First
it can be specified explicitly:


menu "Network device support"
depends on NET


config NETDEVICES
...


endmenu


All entries within the "menu" ... "endmenu" block become a submenu of
"Network device support". All subentries inherit the dependencies from
the menu entry, e.g. this means the dependency "NET" is added to the
dependency list of the config option NETDEVICES.


The other way to generate the menu structure is done by analyzing the
dependencies. If a menu entry somehow depends on the previous entry, it
can be made a submenu of it. First, the previous (parent) symbol must
be part of the dependency list and then one of these two conditions
must be true:
- the child entry must become invisible, if the parent is set to 'n'
- the child entry must only be visible, if the parent is visible


config MODULES
bool "Enable loadable module support"


config MODVERSIONS
bool "Set version information on all module symbols"
depends on MODULES


comment "module support disabled"
depends on !MODULES


MODVERSIONS directly depends on MODULES, this means it's only visible if
MODULES is different from 'n'. The comment on the other hand is always
visible when MODULES is visible (the (empty) dependency of MODULES is
also part of the comment dependencies).




Kconfig syntax
--------------


The configuration file describes a series of menu entries, where every
line starts with a keyword (except help texts). The following keywords
end a menu entry:
- config
- menuconfig
- choice/endchoice
- comment
- menu/endmenu
- if/endif
- source
The first five also start the definition of a menu entry.


config:


"config" <symbol>
<config options>


This defines a config symbol <symbol> and accepts any of above
attributes as options.


menuconfig:
"menuconfig" <symbol>
<config options>


This is similar to the simple config entry above, but it also gives a
hint to front ends, that all suboptions should be displayed as a
separate list of options.


choices:


"choice" [symbol]
<choice options>
<choice block>
"endchoice"


This defines a choice group and accepts any of the above attributes as
options. A choice can only be of type bool or tristate, while a boolean
choice only allows a single config entry to be selected, a tristate
choice also allows any number of config entries to be set to 'm'. This
can be used if multiple drivers for a single hardware exists and only a
single driver can be compiled/loaded into the kernel, but all drivers
can be compiled as modules.
A choice accepts another option "optional", which allows to set the
choice to 'n' and no entry needs to be selected.
If no [symbol] is associated with a choice, then you can not have multiple
definitions of that choice. If a [symbol] is associated to the choice,
then you may define the same choice (ie. with the same entries) in another
place.


comment:


"comment" <prompt>
<comment options>


This defines a comment which is displayed to the user during the
configuration process and is also echoed to the output files. The only
possible options are dependencies.


menu:


"menu" <prompt>
<menu options>
<menu block>
"endmenu"


This defines a menu block, see "Menu structure" above for more
information. The only possible options are dependencies.


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.


mainmenu:


"mainmenu" <prompt>


This sets the config program's title bar if the config program chooses
to use it. It should be placed at the top of the configuration, before any
other statement.




Kconfig hints
-------------
This is a collection of Kconfig tips, most of which aren't obvious at
first glance and most of which have become idioms in several Kconfig
files.


Adding common features and make the usage configurable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is a common idiom to implement a feature/functionality that are
relevant for some architectures but not all.
The recommended way to do so is to use a config variable named HAVE_*
that is defined in a common Kconfig file and selected by the relevant
architectures.
An example is the generic IOMAP functionality.


我们可以在 lib/Kconfig中看到:


# Generic IOMAP is used to ...
config HAVE_GENERIC_IOMAP


config GENERIC_IOMAP
depends on HAVE_GENERIC_IOMAP && FOO


然后在 lib/Makefile中我们可以看到:
obj-$(CONFIG_GENERIC_IOMAP) += iomap.o


对于每一个使用通用IOMAP功能的架构我们可以看到:


config X86
select ...
select HAVE_GENERIC_IOMAP
select ...


注意: 我们使用已存在的配置选项并且避免创建一个新的配置变量在使用select HAVE_GENERIC_IOMAP的时候



注意: 内部配置变量 HAVE_GENERIC_IOMAP的用法, it is
introduced to overcome the limitation of select which will force a
config option to 'y' no matter the dependencies.
The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the
situation where select forces a symbol equals to 'y'.


Build as module only
~~~~~~~~~~~~~~~~~~~~
To restrict a component build to module-only, qualify its config symbol
with "depends on m".  E.g.:


config FOO
depends on BAR && m


limits FOO to module (=m) or disabled (=n).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值