An open API service indexing awesome lists of open source software.

https://github.com/jpeach/mj

Generate JSON compilation databases using Clang
https://github.com/jpeach/mj

build-tool clang compilation-database

Last synced: 8 months ago
JSON representation

Generate JSON compilation databases using Clang

Awesome Lists containing this project

README

          

# mj: generate JSON compilation databases using Clang

mj is a simple tool that runs a Clang commandline and injects the [`-MJ`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mj-arg)
option to make it easier to generate a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html).
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.

## Installation

You can install `mj` using the `go install` command:

```bash
$ go install github.com/jpeach/mj@latest
```

## Usage

```
usage: 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.
```

## Example

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.

```bash
$ 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
```