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 actually need to actually build the project, make clean && make -nw is enough. (See screenshot #1 below.)
  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. (See screenshot #2 below.)
  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. Click Compile Database Generator to use it right now!

Screenshot #1: Compile 'make -nw' to "build" the redis source code: Run 'make -nw' in a terminal

Screenshot #2: Click the "Generate!" button to have a compile_commands.json: Click the Generate button