How to generate compile_commands.json from GNU make output

As for C/C++ projects, using LSP is not always easy. If the project is built in CMake, you're luck, just use cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ... and you're done.

But if it's built using GNU Make, you need to come up with some solutions to nail it down, I know the pain!

So I come up with Compile Database Generator for this, you can have a compile_commands.json, and you don't need to install anything additionally. All you need is the Internet access.

Here are the steps:

  1. cd into your project directory
  2. Build the project with make. But we don't need to actually build the project, so make clean && make -nw.

    For example, compile the redis source code:

    Run make -nw in the terminal

  3. Copy the output in the terminal, and paste it into the box in the page

  4. Click the "Generate!" button, and it will show you compile_commands.json.

    As shown in the below screenshot:

    Click the Generate button

  5. Save the result by clicking "Download"

It also works perfectly with projects like Redis, which hides the build details from the terminal using ANSI escape code.

Happy hacking GNU make C/C++ projects with Emacs/VSCode/CLion/clang-tidy/Sourcetrail etc!