當user在compiler Linux kernel 2.6的時候,打make menuconfig時,會出現選單讓user選擇想安裝的項目,而這些設定檔都寫在Kconfig file中,source code tree下幾乎每一個目錄夾都會有Kconfig file。(Linux kernel 2.4 則為Config.in file)
How to write Kconfig
1. How to Add a Item in Menu List
每一個選項開始都必須以”config”開頭
Ex.
config DM9000
tristate “DM9000A support”
depends on NET_ETHERNET
select CRC32
- type definition:”bool” / ”tristate” / ”string” / ”hex” / ”int”
選擇想要輸入的型態,通常driver類都用bool或是tristate,如果是參數或 是變數,則用string, hex or int。
bool:built-in and exclude
當你用bool type ---> [ ]DM9000A support
tristate:built-in, module, exclude
當你用tristate type ---> < >DM9000A support
int, string, hex:
當你用int, string, or hex --->( ) DM9000A support.
- input prompt: "prompt"
選單上所看到的選項的字
Ex.
bool “Networking Support”
or
bool
prompt “Networking Support”
- default value: "default"
設定預設的值。
Ex.
config VECTORS_BASE
hex
default 0xffff0000 if MMU CPU_HIGH_VECTOR
default DRAM_BASE if REMAP_VECTORS_TO_RAM
default 0x00000000
- dependencies: "depends on"/"requires"
Ex.
config DM9000A
tristate "DM9000A support"
depends on NET_ETHERNET
select CRC32
如果NET_ETHERNET選項有選,才能看見DM9000A這選項。
- reverse dependencies: "select"
While normal dependencies reduce the upper limit of a symbol, reverse dependencies can be used to force a lower limit of another symbol. Reverse dependencies can only be used with bool or tristate symbols.
Ex.
config DM9000A
tristate "DM9000A support"
depends on NET_ETHERNET
select CRC32
當選擇DM9000A選項時,CRC32也一起被選入。
- help text: "help" or "---help---"
help的文字。
2. How to Add a Directory in Menu List
- menu:
主要是用menu and endmenu來建立。
menu “Device Driver”
config NETDEVICE
:
endmenu
- choice
目錄內選定的項目,會顯示在母目錄上,而且只能選一個選項。
Ex.
A--
-----a
-----b
-----c
a, b, c只能選一個,如果選擇a,則會顯示A (a) --->
=========================================
Choice
prompt "Subarchitecture Type"
default X86_PC
config X86_PC
bool "PC-compatible"
help
Choose this option if your computer is a standard PC or compatible.
config X86_ELAN
bool "AMD Elan"
help
Select this for an AMD Elan processor.
:
:
Endchoice
====================================================
如果選擇” PC-compatible”,則menulist上會顯示 Subarchitecture Type (PC-compatible) --->。
如果選擇” AMD Elan”,則menulist上會顯示 Subarchitecture Type (AMD Elan) --->。
- comment:在menu list 中顯示文字
comment "SCSI support type (disk, tape, CD-ROM)"