From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 825936DE024A for ; Tue, 29 Aug 2017 04:35:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.011, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yZ3KTD-cv3x3 for ; Tue, 29 Aug 2017 04:35:35 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 9F22D6DE012F for ; Tue, 29 Aug 2017 04:35:35 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1dmekM-0007KF-Ot; Tue, 29 Aug 2017 07:31:54 -0400 Received: (nullmailer pid 10492 invoked by uid 1000); Tue, 29 Aug 2017 11:35:30 -0000 From: David Bremner To: Jani Nikula , David Bremner , notmuch@notmuchmail.org, notmuch@freelists.org Subject: [Patch v2] build: add target to run cppcheck Date: Tue, 29 Aug 2017 08:35:26 -0300 Message-Id: <20170829113526.10435-1-david@tethera.net> X-Mailer: git-send-email 2.14.1 In-Reply-To: <87pobhl8wc.fsf@nikula.org> References: <87pobhl8wc.fsf@nikula.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Aug 2017 11:35:36 -0000 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. --- Two notable changes from the first version: 1) support parallel build, inspired by id:87pobhl8wc.fsf@nikula.org; 2) use the predefined 'gcc' template. It's still an optional target, as that felt most comfortable as a workflow to me. Makefile.local | 18 ++++++++++++++++++ configure | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/Makefile.local b/Makefile.local index af12ca7f..c6ad0047 100644 --- a/Makefile.local +++ b/Makefile.local @@ -199,6 +199,14 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//')) @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); rm -rf .deps @@ -283,6 +291,16 @@ CLEAN := $(CLEAN) version.stamp notmuch-*.tar.gz.tmp 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) 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