# cckconfig
**Repository Path**: yezc/cckconfig
## Basic Information
- **Project Name**: cckconfig
- **Description**: 移植Linux源码中的kconfig工具,支持跨平台编译。
- **Primary Language**: C
- **License**: GPL-2.0
- **Default Branch**: single_file
- **Homepage**: https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2026-07-02
- **Last Updated**: 2026-07-04
## Categories & Tags
**Categories**: Uncategorized
**Tags**: kconfig, C语言
## README
# Kconfig - 单文件跨平台编译
Linux Kconfig `conf` 工具,仅需 **两个文件** — `kconfig.c` + `kconfig.h` — 即可在 **Windows、Linux、macOS** 上编译为单个可执行文件。
零依赖,无需 bison/flex,无需多文件编译。直接编译即用。
## 快速开始
### Windows
```bat
kconfig_single_build.bat
```
### Linux / macOS
```sh
./kconfig_single_build.sh
```
编译器自动检测(gcc / clang)。
## 为什么用单文件?
原始的 Linux Kconfig 工具位于内核源码树的 `scripts/kconfig/` 目录下,需要完整的构建环境(bison、flex、用于 mconf 的 ncurses 等)。
本项目将所有 Kconfig 源文件合并为两个文件:
| 文件 | 说明 |
|------|------|
| `kconfig.c` | 合并后的源码(lexer、parser、confdata、expr、menu、symbol 等) |
| `kconfig.h` | 合并后的头文件(所有内部头文件 + 平台兼容性) |
两个平台通过合并源码中的 `#ifdef _WIN32` 条件编译来自动处理。
## 使用方法
### 编译脚本参数
```
kconfig_single_build.bat [-cc 编译器] [-h]
kconfig_single_build.sh [-cc 编译器] [-h]
```
| 参数 | 说明 |
|------|------|
| `-cc 编译器` | 指定 C 编译器(默认自动检测 gcc/clang) |
| `-h`, `--help` | 显示帮助信息 |
### 手动编译
不一定非要用构建脚本。只需一行编译命令即可:
**Windows (MinGW/MSYS2):**
```bat
gcc -O2 -std=gnu99 -D_WIN32 -I. kconfig.c -o conf.exe
```
**Linux / macOS:**
```sh
gcc -O2 -Wall -std=gnu99 -I. kconfig.c -o conf
```
### 示例
```bat
:: 自动检测编译器
kconfig_single_build.bat
:: 指定编译器
kconfig_single_build.bat -cc gcc
:: 手动编译(任意平台)
gcc -O2 -I. kconfig.c -o conf
```
## 验证
```bat
:: Windows
conf.exe --help
:: Linux/macOS
./conf --help
```
## 文件说明
| 文件 | 说明 |
|------|------|
| `kconfig.c` | 合并的跨平台 Kconfig 源码 |
| `kconfig.h` | 合并的跨平台 Kconfig 头文件 |
| `kconfig_single_build.bat` | Windows 编译脚本 |
| `kconfig_single_build.sh` | Linux / macOS 编译脚本 |
| `LICENSE` | GNU General Public License v2 |
## 平台支持
| 平台 | 编译器 | 输出 |
|------|--------|------|
| **Windows** (MinGW / MSYS2) | gcc, clang | `conf.exe` |
| **Linux** | gcc, clang | `conf` |
| **macOS** | gcc, clang | `conf` |
## Kconfig 是什么?
Kconfig 是 Linux 内核(以及 Buildroot、BusyBox、U-Boot 等许多其他项目)使用的配置语言,用于以树状结构描述编译时选项。
`conf` 工具是命令行前端,用于读取 `Kconfig` 文件并生成 `.config` 输出。
### `conf` 快速用法
```sh
# 生成默认配置
conf -s Kconfig
# 更新已有的 .config
conf -s Kconfig --oldconfig
# 交互式文本模式配置
conf Kconfig
# 从命令行设置配置值
conf -s Kconfig --alldefconfig
```
## 参考链接
### 官方源码
Kconfig 源自 Linux 内核源代码树,位于 `scripts/kconfig/` 目录下。
- **Linux 内核仓库**:
- **Kconfig 源码目录**: 内核源码树中的 `scripts/kconfig/`
- **Git 网页界面**:
### 官方文档
- **Kconfig 语言参考**:
- **Kconfig 使用指南** (`kconfig.txt`):
- **Linux 内核构建系统 (Kbuild)**:
### 使用 Kconfig 的项目
- **Linux 内核**:
- **Buildroot**:
- **BusyBox**:
- **U-Boot**:
- **Zephyr RTOS**:
## 许可证
Kconfig 是 Linux 内核的一部分,以 **GNU General Public License v2**(或更高版本)发布。
详见 [LICENSE](LICENSE) 文件。