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.
the unifdef(1) man page describes:
the command-line usage
details of how unifdef preprocesses your code
notes on standards conformance
This is version 3 of unifdef. There is a summary of
differences between unifdef3 and unifdef2.
Browse the source repository at: https://dotat.at/cgi/git/unifdef3.git
Clone the development repository with:
git clone https://dotat.at/git/unifdef3.git
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:
re2c -
The regex-based lexical analyser in the source unifdef.re
is compiled to a big DFA in unifdef.c by re2c.
mandoc -
Turns the unifdef(1) man page into nice HTML.
markdown -
Other documentation is formatted with markdown.
I assume your OS has perl, for markdown and the build tooling in
the scripts subdirectory, as well as the tests.
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.
unifdefis 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