Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use bear with make to auto-create the json compilation database?

I'm using vim with YouCompleteMe (YCM) plugin for C programming. YCM needs a json file to show code completion suggestions or a manually crafted .ycm_extra_conf.py file.
Build systems like cmake and ninja provide a switch to generate the json file while building but there is no such option for make. bear is a utility to generate the JSON compilation database.
How can I integrate bear with my Makefile? Should I call make all in which bear is an external utility or should I instead call bear make? I'm a little confused by its guide.

For example, here is the a basic example of GTK+. I can compile the code using gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0` .
How can I automate the process of 1- compiling and 2- creating the json file if I want to use make as my build system? What should be in my Makefile?

Thanks

like image 430
Zeta.Investigator Avatar asked Sep 01 '18 06:09

Zeta.Investigator


2 Answers

You need to feed bear every command you use to build from source. For example, you require configure script to be run before make , first do bear ./configure then bear make. Make sure the source folder used to build is not processed earlier with some script (like configure) because it may affect the json file contents.

like image 192
tejasvi88 Avatar answered Sep 30 '22 13:09

tejasvi88


If you aren't able to install Bear or compiledb easily, maybe a web app is an option.

I've built a simple web app to generate compile_commands.json, all you need to have is the output of make, e.g., make --print-directory -n. The web app is https://texttoolkit.com/compilation-database-generator.

like image 32
whatacold Avatar answered Sep 30 '22 14:09

whatacold