Coccinelle:Linux 内核的源到源转换工具
发布: (2026年2月21日 GMT+8 16:26)
3 分钟阅读
原文: Hacker News
Source: Hacker News
安装
- 要从源码构建 Coccinelle,请遵循
install.txt中的说明。 - 安装完成后,
spatch脚本会放置在/usr/bin或/usr/local/bin。 - 预编译的
spatch可在此处下载:
不安装直接运行
您可以直接在下载/构建目录中执行 Coccinelle。
设置环境变量,使程序能够找到其配置文件:
# Bash
source env.sh
# tcsh
source env.csh
用法
使用一个简单示例测试 Coccinelle:
spatch --sp-file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
如果您尚未安装 Coccinelle,请从构建目录运行脚本:
./spatch # or ./spatch.opt
使用 spatch 的字节码版本时,可能需要先安装 OCaml(提供 ocamlrun 解释器),然后运行:
ocamlrun spatch --sp-file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
文档
获取更多信息,请运行 make docs 并浏览 docs/ 目录中的文件。
在 Debian/Ubuntu 上,构建 LaTeX 文档可能需要 texlive-fonts-extra 包。
运行时依赖(Debian/Ubuntu)
- SmPL 中的 OCaml 脚本:
ocaml-native-compilers或ocaml-nox - SmPL 中的 Python 脚本:
python3-dev(仅运行时需要;构建 Coccinelle 时不必)
贡献
欢迎贡献代码。请按照 Linux 内核的开发者原始证书 1.1(Developer’s Certificate of Origin 1.1)进行签名:
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have the
right to submit it under the open source license indicated in the file; or
(b) The contribution is based upon previous work that, to the best of my
knowledge, is covered under an appropriate open source license and I
have the right under that license to submit that work with modifications,
whether created in whole or in part by me, under the same open source
license (unless I am permitted to submit under a different license), as
indicated in the file; or
(c) The contribution was provided directly to me by some other person who
certified (a), (b) or (c) and I have not modified it.
(d) I understand and agree that this project and the contribution are public
and that a record of the contribution (including all personal information
I submit with it, including my sign‑off) is maintained indefinitely and
may be redistributed consistent with this project or the open source
license(s) involved.
添加如下行并使用您的真实姓名签名:
Signed-off-by: Your Name