dotat unifdef: expand macros, reduce #ifdefs

warning: unfinished nonfunctional work in progress

The unifdef utility is a partial C and C++ preprocessor. It can expand just the macros you want expanded, selectively process #ifdef and #if conditional directves, and simplify #if controlling expressions. It does not process #include directives. It preserves whitespace and comments.

Every ifdef is an ugly intrusion and a pain to read.

Doug McIlroy

It is useful for manipulating code that uses #ifdef heavily for portability: my original motivation for unifdef was to understand xterm's pty handling code. It can be used as a lightweight preprocessor; for example the Linux kernel uses an older version od unifdef to strip out #ifdef __KERNEL__ sections from the headers it exports to userland.

Documentation

Download

Install

Release tar and zip files contain the complete source in unifdef.c which is mostly standard C, except that it uses getopt() from <unistd.h>. There is no build-time configuration, so you can usually compile it by just running:

    make

To run the tests you will need perl and awk. We use perl's prove test runner.

    make check

If you are building from the git repository you need a few external dependencies. You can build and install them in an ext subdirectory with:

    make deps

This will download, verify checksums, and buid:

I assume your OS has perl, for markdown and the build tooling in the scripts subdirectory, as well as the tests.

Contribute

Please send bug reports, suggestions, and patches by email to me, Tony Finch <dot@dotat.at>. Any contribution that you want included in unifdef must be licensed under the CC0 1.0 Public Domain Dedication, and must include a Signed-off-by: line to certify that you wrote it or otherwise have the right to pass it on as a open-source patch, according to the Developer's Certificate of Origin 1.1.

Licence

unifdef is written by Tony Finch <dot@dotat.at>
You may do anything with this. It has no warranty.
https://creativecommons.org/publicdomain/zero/1.0/
SPDX-License-Identifier: CC0-1.0