Skip to content

Commit 491aae5

Browse files
kdaveadam900710
authored andcommitted
btrfs-progs: build: add target to generate compile_commands.json
To support LSP in editors add a convenience command to generate the commands that eg. clangd uses to generate it's database. This requires the Bear tool to scan build. Compilation can be done by gcc or clang, only the .json needs the explicit CC=clang. LSP is sensitive to the CFLAGS. Signed-off-by: David Sterba <[email protected]>
1 parent 772e951 commit 491aae5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,17 @@ test-build-real:
875875
manpages:
876876
$(Q)$(MAKE) $(MAKEOPTS) -C Documentation
877877

878+
# Generate database for LSP. This depends on Bear and clang, gcc can be used
879+
# for compilation though.
880+
compile_commands.json: FORCE
881+
@if ! type -p bear 2>/dev/null; then echo "ERROR: please install bear (https://github.com/rizsotto/Bear)"; exit 1; fi
882+
@if ! test -f config.status; then echo "ERROR: please configure first and build with CC=clang"; exit 1; fi
883+
@-rm -- $@
884+
@echo "Clean before generating $@"
885+
@$(MAKE) clean
886+
@echo "Capture build commands and generate $@"
887+
@bear -- $(MAKE) CC=clang
888+
878889
tags: FORCE
879890
@echo " TAGS $(TAGS_CMD)"
880891
$(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] \

0 commit comments

Comments
 (0)