mj is a simple tool that runs a Clang commandline and injects the -MJ
option to make it easier to generate a JSON compilation database.
The clang -MJ option emits a compilation database fragment for the
single file that is being compiled.
Once the full project build is complete, you can run mj --collect
to gather the fragments into a single compile_commands.json file.
You can install mj using the go install command:
$ go install github.com/jpeach/mj@latestusage: mj OPTIONS|COMPILATION...
mj injects Clang compiler options to generate a compilation database.
If no options are provided, the arguments to mj should be a full Clang
commandline. mj will inject the '-MJ' option and run the Clang command.
Options:
--clean This option recursively removes all the ".mj" directories
generated during a compilation.
--collate This option finds all the compilation database fragments
generated by Clang, and collates them into a single file
named "compile_commands.json".
--help, --usage
Show this help message.
Say you have a build that accepts the CC and CXX environment
variables, but does not explicitly support building a JSON compilation
database.
You can build your project normally, but substitute mj as a compiler wrapper.
The compilation process will emit JSON fragments as files with the
extension .db.json in a .mj directory next to your object files.
When the build is complete, mj can collate these into a single JSON
compilation database.
$ make CC="mj clang" CXX="mj clang++"
...
$ find . -name *.db.json | wc -l
495
$ mj --collate
$ ls -hl compile_commands.json
-rw-r--r-- 1 jpeach staff 1.3M Jun 8 11:47 compile_commands.json