Kconfig

开发平台 Embedded-RTOS Embedded-NoOS Embedded-Linux
linux kconfiglib.menuconfig
Kconfig
makefile/sconscript
kconfiglib.menuconfig
Kconfig
makefile/sconscript
kconfiglib.menuconfig
Kconfig
makefile/sconscript
windows windows-curses
kconfiglib.menuconfig
Kconfig
makefile/sconscript
or
env-windows
Kconfig
makefile/sconscript
windows-curses
kconfiglib.menuconfig
Kconfig
makefile/sconscript




windows-curses
kconfiglib.menuconfig
Kconfig
makefile/sconscript




安装

Linux

python -m pip install kconfiglib
/usr/local/bin
alldefconfig
allmodconfig
allnoconfig
allyesconfig
defconfig
genconfig
guiconfig
listnewconfig
menuconfig
oldconfig
olddefconfig
savedefconfig
setconfig

Windows

python -m pip install kconfiglib
python -m pip install windows-curses
..\python\Scripts\
alldefconfig.exe
allmodconfig.exe
allnoconfig.exe
allyesconfig.exe
defconfig.exe
genconfig.exe
guiconfig.exe
listnewconfig.exe
menuconfig.exe
oldconfig.exe
olddefconfig.exe
savedefconfig.exe
setconfig.exe

测试

menuconfig -h
genconfig -h

使用

1. 新建 demo 工程
main.c
Kconfig
Makefile
2. 使用 make 编译
make
make clean
3. 手动打开配置界面
make menuconfig

例程

example: main.c
#include <stdio.h>
#include "config.h"

int main()
{
printf("hello, world\n");

#ifdef CONFIG_FUNCTION_1_ENABLE
printf("CONFIG_FUNCTION_1_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_1_1_ENABLE
printf("CONFIG_FUNCTION_1_1_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_1_2_ENABLE
printf("CONFIG_FUNCTION_1_2_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_1_3_ENABLE
printf("CONFIG_FUNCTION_1_3_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_2_ENABLE
printf("CONFIG_FUNCTION_2_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_2_1_ENABLE
printf("CONFIG_FUNCTION_2_1_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_2_2_ENABLE
printf("CONFIG_FUNCTION_2_2_ENABLE\n");
#endif

#ifdef CONFIG_FUNCTION_2_3_ENABLE
printf("CONFIG_FUNCTION_2_3_ENABLE\n");
#endif

printf("USERNAME: %s\n", CONFIG_USERNAME);
printf("PASSWORD: %d\n", CONFIG_PASSWORD);

return 0;
}
example: Kconfig
mainmenu "Kconfig"

menu "example"

config FUNCTION_1_ENABLE
bool "Function 1"
default n
help
Function 1

config FUNCTION_1_1_ENABLE
bool "Function 1.1"
default n
depends on FUNCTION_1_ENABLE
help
Function 1.1

config FUNCTION_1_2_ENABLE
bool "Function 1.2"
default n
depends on FUNCTION_1_ENABLE
help
Function 1.2

config FUNCTION_1_3_ENABLE
bool "Function 1.3"
default n
depends on FUNCTION_1_ENABLE
help
Function 1.3

config FUNCTION_2_ENABLE
bool "Function 2"
default n
help
Function 2

config FUNCTION_2_1_ENABLE
bool "Function 2.1"
default n
depends on FUNCTION_2_ENABLE
help
Function 2.1

config FUNCTION_2_2_ENABLE
bool "Function 2.2"
default n
depends on FUNCTION_2_ENABLE
help
Function 2.2

config FUNCTION_2_3_ENABLE
bool "Function 2.3"
default n
depends on FUNCTION_2_ENABLE
help
Function 2.3

config USERNAME
string "username"
default "abc"
help
Input a string value.

config PASSWORD
int "password"
range 0 255
default 123
help
Input a int value. Range from 0 to 255.

endmenu
example: Makefile
all: main.o
gcc main.o -o main
main.o: main.c config.h
gcc main.c -c -o main.o
clean:
rm main.o main

config.h:.config
genconfig --header-path config.h
.config:
menuconfig
menuconfig:
menuconfig