3 # Copyright (C) Dean Camera, 2012.
5 # dean [at] fourwalledcubicle [dot] com
9 LUFA_BUILD_MODULES += CPPCHECK
10 LUFA_BUILD_TARGETS += cppcheck cppcheck-config
11 LUFA_BUILD_MANDATORY_VARS +=
12 LUFA_BUILD_OPTIONAL_VARS += CPPCHECK_PATH CPPCHECK_INCLUDES CPPCHECK_EXCLUDES CPPCHECK_MSG_TEMPLATE \
13 CPPCHECK_ENABLE CPPCHECK_SUPPRESS CPPCHECK_FAIL_ON_WARNING CPPCHECK_QUIET
15 # -----------------------------------------------------------------------------
16 # LUFA CPPCheck Buildsystem Makefile Module.
17 # -----------------------------------------------------------------------------
19 # Provides a set of targets to scan a project with the free "cppcheck" static
20 # analysis tool, to check for code errors at runtime (see http://cppcheck.sourceforge.net).
21 # -----------------------------------------------------------------------------
24 # cppcheck - Scan the project with CPPCheck
25 # cppcheck-config - Use CPPCheck to look for missing include files
27 # MANDATORY PARAMETERS:
31 # OPTIONAL PARAMETERS:
33 # CPPCHECK_PATH - Path of the files to statically analyze
34 # CPPCHECK_INCLUDES - Extra include paths to search for missing
36 # CPPCHECK_EXCLUDES - Source file paths to exclude checking (can be
37 # a path fragment if desired)
38 # CPPCHECK_MSG_TEMPLATE - Template for cppcheck error and warning output
39 # CPPCHECK_ENABLE - General cppcheck category checks to enable
40 # CPPCHECK_SUPPRESS - Specific cppcheck warnings to disable by ID
41 # CPPCHECK_FAIL_ON_WARNING - Set to Y to fail the build on cppcheck
42 # warnings, N to continue even if warnings occur
43 # CPPCHECK_QUIET - Enable cppcheck verbose or quiet output mode
45 # -----------------------------------------------------------------------------
47 # Default values of optionally user-supplied variables
51 CPPCHECK_MSG_TEMPLATE ?= {file}:{line}: {severity} ({id}): {message}
52 CPPCHECK_ENABLE ?= all
53 CPPCHECK_SUPPRESS ?= variableScope missingInclude
54 CPPCHECK_FAIL_ON_WARNING ?= Y
57 # Build a default argument list for cppcheck
58 CPPCHECK_OPTIONS := --template="$(CPPCHECK_MSG_TEMPLATE)" $(CPPCHECK_INCLUDES:%=-I%) $(CPPCHECK_EXCLUDES:%=-i%) --inline-suppr --force --std=c99
60 # Sanity check parameters and construct additional command line arguments to cppcheck
61 ifeq ($(CPPCHECK_PATH),)
62 $(error Makefile CPPCHECK_PATH option cannot be blank)
64 ifeq ($(CPPCHECK_FAIL_ON_WARNING), Y)
65 CPPCHECK_OPTIONS += --error-exitcode=1
66 else ifneq ($(CPPCHECK_FAIL_ON_WARNING), N)
67 $(error CPPCHECK_FAIL_ON_WARNING must be Y or N)
69 ifeq ($(CPPCHECK_QUIET), Y)
70 CPPCHECK_OPTIONS += --quiet
71 else ifneq ($(CPPCHECK_QUIET), N)
72 $(error CPPCHECK_QUIET must be Y or N)
76 MSG_CPPCHECK_CMD := ' [CPPCHECK]:'
79 @echo $(MSG_CPPCHECK_CMD) Checking cppcheck configuration for path \"$(CPPCHECK_PATH)\"
80 cppcheck $(CPPCHECK_OPTIONS) --check-config $(CPPCHECK_PATH)
83 @echo $(MSG_CPPCHECK_CMD) Performing cppcheck analysis on path \"$(CPPCHECK_PATH)\"
84 cppcheck $(CPPCHECK_OPTIONS) --enable=$(CPPCHECK_ENABLE) $(CPPCHECK_SUPPRESS:%=--suppress=%) $(CPPCHECK_PATH)