[PATCH 1/5] build: add target to run cppcheck

David Bremner david at tethera.net
Sat Aug 26 07:41:37 PDT 2017


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.

Things not addressed here

  - parallelism. Doing this correctly seems like a rabbit-hole.

  - what target to invoke this from.  The 8s delay (on my machine) seems
    acceptable, but not necessarily the resulting fragility in
    autobuilders.
---
 Makefile.local | 10 ++++++++++
 configure      | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/Makefile.local b/Makefile.local
index af12ca7f..6a5168f1 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -283,6 +283,16 @@ CLEAN := $(CLEAN) version.stamp notmuch-*.tar.gz.tmp
 
 DISTCLEAN := $(DISTCLEAN) .first-build-message Makefile.config sh.config
 
+CLEAN := $(CLEAN) cppcheck.stamp
+cppcheck: cppcheck.stamp
+cppcheck.stamp: $(SRCS)
+ifeq ($(HAVE_CPPCHECK),1)
+	cppcheck --template="{file}:{line}: {severity}: {message}" --quiet --error-exitcode=1 ${SRCS}
+	touch $@
+else
+	@echo No cppcheck installed; skipping static checking
+endif
+
 DEPS := $(SRCS:%.c=.deps/%.d)
 DEPS := $(DEPS:%.cc=.deps/%.d)
 -include $(DEPS)
diff --git a/configure b/configure
index c5e2ffed..364854f3 100755
--- 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}
-- 
2.14.1



More information about the notmuch mailing list