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
- Host: GitHub
- URL: https://github.com/jpeach/mj
- Owner: jpeach
- License: apache-2.0
- Created: 2023-06-08T01:30:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-25T23:54:34.000Z (over 2 years ago)
- Last Synced: 2025-03-19T23:43:56.816Z (about 1 year ago)
- Topics: build-tool, clang, compilation-database
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```