]> git.notmuchmail.org Git - notmuch/commitdiff
build: add target to run cppcheck
authorDavid Bremner <david@tethera.net>
Tue, 29 Aug 2017 11:35:26 +0000 (08:35 -0300)
committerDavid Bremner <david@tethera.net>
Wed, 30 Aug 2017 01:05:37 +0000 (22:05 -0300)
The advantage of having a target as opposed to running cppcheck by
hand

  - reuse list of source files
  - output errors in a format parsable, e.g. by emacs
  - returns exit code 1 on any error, for possibly use in other
    targets.

For the moment, leave this as an optional target. If desired, it can
be added to e.g. the release targets in the same way as the test
target.

Using two levels of directory for the stamps is arguably
overengineering, but it doesn't really cost anything, and leaves open
the possibility of putting other kinds of stamp files there.

This only checks "new" source files (w.r.t. their last check). A future target
(cppcheck-all ?) could blow away the stamp files first.

Makefile.local
configure

index 9e2111f5cc0dfd0961e14a3a3c24dcae9ec3b584..9d9c52c26d9e85d7eac1420b0002e9b6dd9e1872 100644 (file)
@@ -199,6 +199,14 @@ quiet ?= $($(word 1, $(1)))
        @mkdir -p $(patsubst %/.,%,.deps/$(@D))
        $(call quiet,CC $(CPPFLAGS) $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d
 
+CPPCHECK=cppcheck
+.stamps/cppcheck/%: %
+       @mkdir -p $(@D)
+       $(call quiet,CPPCHECK,$<) --template=gcc --error-exitcode=1 --quiet $<
+       @touch $@
+
+CLEAN := $(CLEAN) .stamps
+
 .PHONY : clean
 clean:
        rm -rf $(CLEAN)
@@ -284,6 +292,16 @@ CLEAN := $(CLEAN) .deps
 
 DISTCLEAN := $(DISTCLEAN) .first-build-message Makefile.config sh.config
 
+CPPCHECK_STAMPS := $(SRCS:%=.stamps/cppcheck/%)
+.PHONY: cppcheck
+ifeq ($(HAVE_CPPCHECK),1)
+cppcheck: ${CPPCHECK_STAMPS}
+else
+cppcheck:
+       @echo "No cppcheck found during configure; skipping static checking"
+endif
+
+
 DEPS := $(SRCS:%.c=.deps/%.d)
 DEPS := $(DEPS:%.cc=.deps/%.d)
 -include $(DEPS)
index c5e2ffed9e6705a9b16f5cf52f3c57235bc40044..364854f3d936ac3a2861cd03fbf622cba7793c15 100755 (executable)
--- a/configure
+++ b/configure
@@ -646,6 +646,14 @@ if [ $WITH_DESKTOP = "1" ]; then
     fi
 fi
 
+printf "Checking for cppcheck... "
+if command -v cppcheck > /dev/null; then
+    have_cppcheck=1
+    printf "Yes.\n"
+else
+    printf "No.\n"
+fi
+
 libdir_in_ldconfig=0
 
 printf "Checking which platform we are on... "
@@ -1065,6 +1073,9 @@ zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completio
 # build its own version)
 HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}
 
+# Whether the cppcheck static checker is available
+HAVE_CPPCHECK = ${have_cppcheck}
+
 # Whether the getline function is available (if not, then notmuch will
 # build its own version)
 HAVE_GETLINE = ${have_getline}