1 Kconfig和Makefile
2 菜单组织结构
menu 菜单名
菜单项或菜单链接1
菜单项或菜单链接2
...
菜单项或菜单链接n
endmenu
其中菜单项就是指菜单的子菜单,所谓菜单链接就是指链接到另一个Kconfig文件,如此一下,菜单就可以实现随意嵌套了.
# drivers/Kconfig
menu "Device Drivers"
source "drivers/base/Kconfig"
source "drivers/connector/Kconfig"
source "drivers/mtd/Kconfig"
source "drivers/of/Kconfig"
source "drivers/parport/Kconfig"
source "drivers/pnp/Kconfig"
source "drivers/block/Kconfig"
source "drivers/hello/Kconfig"
config test
bool "提示字符串"
default y
...
endmenu
2.1 菜单项
config <symbol>
<config options>
<symbol>为一符号,就好像代码中的局部变量x一样,可用于后边的表达式中.
config UEVENT_HELPER_PATH
string "path to uevent helper"
depends on HOTPLUG
default "/sbin/hotplug"
help
Path to uevent helper program forked by the kernel for
every uevent.
上面菜单项的属性string表示菜单的类型,每一个菜单项必须有一个类型.
2.2 菜单链接
source "路径"
如:
source "drivers/pnp/Kconfig"
2.3 菜单属性2.3.1 类型
string "path to uevent helper"
bool "Prevent firmware from being built"
注:每一个菜单项必须有类型属性。
2.3.2 默认值
config UEVENT_HELPER_PATH
string "path to uevent helper"
default "/sbin/hotplug"
表示当前菜单项若用户没有选择或输入任何值时,所取的默认值.上述所示为当前的默认值为"/sbin/totplug".
2.3.3 依赖
depends on/requires <expr>
<expre>为表达式,可为之前定义的菜单项名.
depends on HOTPLUG
表示此菜单项显示与否取决于另外一个菜单项HOTPLUG ,只有当菜单项HOTPLUG这个菜单项有效显示,当前菜单项才会显示。
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的显示与否取决于菜单项MODULES。这种信赖关系常用在子菜单项中。
2.3.4 选择
choice
选择项
..
endchoice
2.3.5 提示
comment "提示信息字符串"
comment选项
2.3.6 帮助
help/---help--- <字符串>
例如:
config EXTRA_FIRMWARE_DIR
string "Firmware blobs root directory"
depends on EXTRA_FIRMWARE != ""
default "firmware"
help
This option controls the directory in which the kernel build system
looks for the firmware files listed in the EXTRA_FIRMWARE option.
The default is the firmware/ directory in the kernel source tree,
but by changing this option you can point it elsewhere, such as
the /lib/firmware/ directory or another separate directory
containing firmware files.
help相当于注释一样,在给编辑Kconfig文件的人看的,这样可以保持其可读性.
3 举例
# drivers/Kconfig
menu "Device Drivers"
source "drivers/base/Kconfig"
source "drivers/connector/Kconfig"
source "drivers/mtd/Kconfig"
...
endmenu
其对应的make menuconfig界面如下图所示:
source "drivers/base/Kconfig"中的Kconfig内容如下:即对应着上图中的第一项"Generic Driver Option"的子菜单内容:
这里不再列出来!
显示效果如下图所示:
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.29
# Thu Dec 15 21:15:25 2011
#
CONFIG_ARM=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
# CONFIG_GENERIC_GPIO is not set
CONFIG_GENERIC_TIME=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_MMU=y
# CONFIG_NO_IOPORT is not set
CONFIG_GENERIC_HARDIRQS=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_HAVE_LATENCYTOP_SUPPORT=y
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_TRACE_IRQFLAGS_SUPPORT=y
CONFIG_HARDIRQS_SW_RESEND=y
CONFIG_GENERIC_IRQ_PROBE=y
CONFIG_RWSEM_GENERIC_SPINLOCK=y
# CONFIG_ARCH_HAS_ILOG2_U32 is not set
# CONFIG_ARCH_HAS_ILOG2_U64 is not set
CONFIG_GENERIC_HWEIGHT=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
CONFIG_VECTORS_BASE=0xffff0000
CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
每一个CONFIG_xxx记录着之前Kconfig文件内的菜单项的值.