Coccinelle: The Linux kernel's source-to-source transformation tool

Published: (February 21, 2026 at 03:26 AM EST)
3 min read

Source: Hacker News

Installation

  • To build Coccinelle from source, follow the instructions in install.txt.
  • After installation, the spatch script is placed in /usr/bin or /usr/local/bin.
  • Pre‑compiled versions of spatch can be downloaded here:

Running without installing

You can execute Coccinelle directly from the download/build directory.
Set up the environment variables so the program can locate its configuration files:

# Bash
source env.sh
# tcsh
source env.csh

Usage

Test Coccinelle with a simple example:

spatch --sp-file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c

If you have not installed Coccinelle, run the script from the build directory:

./spatch          # or ./spatch.opt

When using the bytecode version of spatch, you may need to install OCaml (provides the ocamlrun interpreter) and then run:

ocamlrun spatch --sp-file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c

Documentation

For more information, run make docs and explore the files in the docs/ directory.
On Debian/Ubuntu you may need the texlive-fonts-extra package to build the LaTeX documentation.

Runtime dependencies (Debian/Ubuntu)

  • OCaml scripting in SmPL: ocaml-native-compilers or ocaml-nox
  • Python scripting in SmPL: python3-dev (runtime only; not required for building Coccinelle)

Contributing

Contributions are welcome. Please sign your contributions according to the Linux kernel’s 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.

Add a line like the following with your real name:

Signed-off-by: Your Name 
0 views
Back to Blog

Related posts

Read more »

How We Made Our E2E Tests 12x Faster

!Alex Neamtuhttps://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2F...