compile_commands.json serves as input for clangd, while working with
lsp under emacs. It's normal for functions and parameters to be unused while
writing code. Therefore suppress -Werror for this use case. clangd will
display the warnings.

Use "make testprogs" to generate compile_commands.json, in order to be
able to use clangd for the CI code, too.

Finally, don't remove compile_commands.json with "make clean". Normally the
compile commands remain the same, even if a clean rebuild of the binaries
is necessary. Put the file into .gitignore instead.

Signed-off-by: Martin Wilck <[email protected]>
---
 .gitignore   |  1 +
 Makefile     |  4 ++--
 Makefile.inc | 12 +++++++++---
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index 355ddbb..efdbd8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
 *.gz
 *.d
 \#*
+compile_commands.json
 config.mk
 cscope.files
 cscope.out
diff --git a/Makefile b/Makefile
index 4df5f16..14bbac2 100644
--- a/Makefile
+++ b/Makefile
@@ -83,7 +83,7 @@ abi-test:     abi reference-abi $(wildcard abi/*.abi)
 # Requires bear (https://github.com/rizsotto/Bear)
 compile_commands.json: Makefile Makefile.inc $(BUILDDIRS:=/Makefile)
        $(Q)$(MAKE) clean
-       $(Q)bear -- $(MAKE)
+       $(Q)bear -- $(MAKE) WARN_ONLY=1 test-progs || rm $@
 
 libmpathutil libdmmp: libmpathcmd
 libmultipath: libmpathutil
@@ -109,7 +109,7 @@ $(BUILDDIRS:=.uninstall):
 clean:
        @touch config.mk
        $(Q)$(MAKE) $(BUILDDIRS:=.clean) tests.clean || true
-       $(Q)$(RM) -r abi abi.tar.gz abi-test compile_commands.json config.mk
+       $(Q)$(RM) -r abi abi.tar.gz abi-test config.mk
 
 install: $(BUILDDIRS:=.install)
 uninstall: $(BUILDDIRS:=.uninstall)
diff --git a/Makefile.inc b/Makefile.inc
index fe9f1bf..729618b 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -100,9 +100,15 @@ MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 
2>/dev/null || \
                        echo "modprobe@dm_multipath.service")
 
 OPTFLAGS       := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
-WARNFLAGS      := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) 
-Werror=implicit-int \
-                 -Werror=implicit-function-declaration -Werror=format-security 
\
-                 $(WNOCLOBBERED) -Werror=cast-qual 
$(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS)
+
+# Set WARN_ONLY=1 to avoid compilation erroring out due to warnings. Useful 
during development.
+WARN_ONLY       :=
+ERROR           := $(if $(WARN_ONLY),,error=)
+WERROR          := $(if $(WARN_ONLY),,-Werror)
+WARNFLAGS      := $(WERROR) -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) 
-W$(ERROR)implicit-int \
+                 -W$(ERROR)implicit-function-declaration 
-W$(ERROR)format-security \
+                 $(WNOCLOBBERED) -W$(ERROR)cast-qual 
$(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS)
+
 CPPFLAGS       := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \
                   -D_FILE_OFFSET_BITS=64 \
                   -DBIN_DIR=\"$(bindir)\" 
-DMULTIPATH_DIR=\"$(TGTDIR)$(plugindir)\" \
-- 
2.45.2


Reply via email to