ILD

kbuild language
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2019-5-17 站点:Inside Linux Development

配置数据库是依据配置选项树生成的。

配置选项可以依赖另外一个选项,这些依赖用来决定这个选项是否可见。


1 Menu entries

大多数entries定义一个配置选项,但是其它一些entries用来组织它们,单个配置选项看起来像:

1
2
3
4
5
6
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.  ...


每一行以一个关键字开始,可以接多个参数。config开始一个新的config entry,接下来的行定义配置选项的属性。


Menu attributes

每个menu entry可以有多个属性:


1 type definition

bool, tristate, string, hex, int

type可以接上可选的input prompt作为参数。

1
2
3
4
bool "Networking support"
等价于
bool
prompt "Networking support"


2 input prompt

prompt <prompt> [if <expr>]

注意:没有prompt的选项,在menuconfig中不会显示,显示一个空白的选项是没有意义的。


3 default value

default <expr> [if <expr>]


4 type definition + default value

一种简写方式,例如:

def_bool <expr> [if <expr>]


5 defpendencies

depends on <expr>


6 reverse dependencies

select <symbol> [if <expr>]

select的符号只能是bool和trisate,select要小心使用,它会选择一个符号,即使它的依赖不成立。因此select通常只用来选择那些不可见的符号和没有依赖的符号。


7 limiting menu display

visible if [expr]

只用来在menu blocks,如果条件是假,则menu block对用户不可见。


8 numerical ranges

range <symbol> <symbol> [if <expr>]


9 help text

help


10 misc options

option <symbol>[=value]


Menu dependencies

<expr> ::= <symbol>                             (1)

           <symbol> '=' <symbol>                (2)

           <symbol> '!=' <symbol>               (3)

           '(' <expr> ')'                       (4)

           '!' <expr>                           (5)

           <expr> '&&' <expr>                   (6)

           <expr> '||' <expr>                   (7)


n,m,y 对应0, 1, 2


2 Menu structure

menu 条目在树中的位置由两种方式决定,首先,可以显式地指定:

1
2
3
4
5
6
7
menu "Network device support"
    depends on NET
 
config NETDEVICES
    ...
 
endmenu


menu和endmenu中的所有条目,成为Network device support的submenu。所有的subentries继承menu entry的依赖关系。如上,所有的子条目都依赖于NET。


如果被依赖的条目没有被选中,那么所有依赖它的条目都不会被选中,被依赖的条目在配置文件中显示:

# CONFIG_XXX is not set
而那些依赖它的条目则啥也不显示。


另一种产生menu struct的是依赖关系,如果一个条目依赖于前一个条目,它:

如果parent变成n,那么子条目变成不可见。只有当parent是可见时,子条目才能变成可见。


3 Kconfig syntax

config

menuconfig

choice/endchoice

comment

menu/endmenu

if/endif

source

这些都意味着一个menu条目的结束(也许新的条目要开始了)。


config定义一个配置项。


menuconfig

和config是一样的,它也是一个配置项,只不过它本身也是一个菜单,后面的配置项依赖于它,从不依赖它的选项开始的选项,不是它的子菜单。

menuconfig M

if M

    config C1

    config C2

endif

用depends on也是可以的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
menuconfig M
        bool "M"
 
config MODVERSIONS
        bool "Set version information on all module symbols"
        depends on M
        help
          Usually, modules have to be recompiled whenever you switch to a new
          kernel.  ...
 
menu "Net work device"
        depends on MODVERSIONS
 
config NETDEVICES
        bool "net device"
 
endmenu


choices

choice就是多个配置项选择一个。这些配置项只能是bool或者3态。

choice [symbol]

<choice options>

<choice block>

endchoice

1
2
3
4
5
6
7
8
9
10
choice ARCH                                                                                                                                                                                                         
        prompt "select arch"                                                                                                                                                                                        
                                                                                                                                                                                                                     
config X86                                                                                                                                                                                                          
        bool "X86"                                                                                                                                                                                                  
                                                                                                                                                                                                                     
config ARM
        bool "ARM"
 
endchoice


comment

comment <prompt>

<comment options>

comment会显示,也会写到输出文件中。唯一支持的选项是依赖。

1
2
3
4
5
6
CONFIG_X86=y
# CONFIG_ARM is not set
 
#
# notice
#


menu

语法

menu <prompt>

<menu options>

<menu block>

endmenu


if

if <expr>

<if block>

endif

条件包含


source <prompt>

包含另外一个配置文件。


mainmenu

mainmenu prompt

设置配置程序的标题栏。



Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.