Bear is a tool to generate compilation database for clang tooling.
The JSON compilation database is used in clang project to provide information how a single compilation unit was processed. When that is available then it is easy to re-run the compilation with different programs.
One way to get compilation database is to use
cmake as build tool. Passing
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake generates
file into the current directory.
When the project compiles with no cmake, but another build system, there is no free json file. Bear is a tool to generate such file during the build process.
The concept behind Bear is to exec the original build command and
exec calls of the build tool. To achive that Bear uses the
DYLD_INSERT_LIBRARIES mechanisms provided by the dynamic
linker. So it has two components: the library and the binary. The library
exec methods and used in every child processes. The executable
sets the environment up to child processes and writes the output file.
How to build
Bear should be quite portable on UNIX OSs, it has been tested on FreeBSD, Linux and OS X only.
- ANSI C compiler to compile the sources.
- cmake to configure the build process.
- pkg-config to find dependencies during configure step.
- make to run the build. Makefiles are generated by
- libconfig to parse the config file. (Version shall be greater than 1.4)
It could be the best to build it in a separate build directory.
cmake $BEAR_SOURCE_DIR make all make install # to install make check # to run tests make package # to make packages
You can configure the build process with passing arguments to cmake.
How to use
After installation the usage is like this:
bear -- make
-- separate the parameters from the build command. The output file
compile_commands.json found in current directory.
For more options you can check the man page or pass
If you find a bug in this documentation or elsewhere in the program or would like to propose an improvement, please use the project's github issue tracker. Please describing the bug and where you found it. If you have a suggestion how to fix it, include that as well. Patches are also welcome.