kconfig 实例1: 基于 python 的 kconfig 系统
安装
pip install kconfiglib
使用
-
kconfig.py
#!/usr/bin/env python # -*- coding: UTF-8 -*- import os, sys from kconfiglib import Kconfig from menuconfig import menuconfig def mconf_set_env(): """ Set Kconfig Env """ os.environ["MENUCONFIG_STYLE"] = "default selection=fg:white,bg:blue" os.environ["KCONFIG_CONFIG"] = os.path.join(".config") os.environ["KCONFIG_CONFIG_HEADER"] = "# Generated by My Kconfig Demo" os.environ["KCONFIG_AUTOHEADER"] = os.path.join("config.h") os.environ["CONFIG_"] = "" def mconfig(argv): mconf_set_env() kconf = Kconfig(filename="./config.in") menuconfig(kconf) kconf.write_autoconf() if __name__ == "__main__": mconfig(sys.argv)
-
config.in
mainmenu "My Kconfig Demo" menu "Debug" config CONFIG_DEBUG bool "Enable debug" default n help Will print debug information if enable. config CONFIG_DEBUG_UART bool "Enable UART debug" default n depends on CONFIG_DEBUG endmenu
-
Makefile
menuconfig: python kconfig.py
演示
$ ls -a
Makefile config.in kconfig.py
$ make menuconfig
python kconfig.py
Loaded configuration '.config'
Configuration saved to '.config'
$ ls -a
Makefile config.in kconfig.py .config config.h
执行 make menuconfig 后多出 .config config.h
网友评论