3 # Released into the public domain.
5 # dean [at] fourwalledcubicle [dot] com
6 # www.fourwalledcubicle.com
9 DMBS_BUILD_MODULES
+= CPPCHECK
10 DMBS_BUILD_TARGETS
+= cppcheck cppcheck-config
11 DMBS_BUILD_MANDATORY_VARS
+= SRC
12 DMBS_BUILD_OPTIONAL_VARS
+= CPPCHECK_INCLUDES CPPCHECK_EXCLUDES CPPCHECK_MSG_TEMPLATE CPPCHECK_ENABLE \
13 CPPCHECK_SUPPRESS CPPCHECK_FAIL_ON_WARNING CPPCHECK_QUIET CPPCHECK_FLAGS
14 DMBS_BUILD_PROVIDED_VARS
+=
15 DMBS_BUILD_PROVIDED_MACROS
+=
19 ERROR_IF_UNSET ?
= $(if
$(filter undefined
, $(origin $(strip $(1)))), $(error Makefile
$(strip $(1)) value not set
))
20 ERROR_IF_EMPTY ?
= $(if
$(strip $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option cannot be blank
))
21 ERROR_IF_NONBOOL ?
= $(if
$(filter Y N
, $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option must be Y or N
))
23 # Default values of optionally user-supplied variables
26 CPPCHECK_MSG_TEMPLATE ?
= {file
}:{line
}: {severity
} ({id
}): {message
}
27 CPPCHECK_ENABLE ?
= all
28 CPPCHECK_SUPPRESS ?
= variableScope missingInclude
29 CPPCHECK_FAIL_ON_WARNING ?
= Y
33 # Sanity check user supplied values
34 $(foreach MANDATORY_VAR
, $(DMBS_BUILD_MANDATORY_VARS
), $(call ERROR_IF_UNSET
, $(MANDATORY_VAR
)))
35 $(call ERROR_IF_EMPTY
, SRC
)
36 $(call ERROR_IF_EMPTY
, CPPCHECK_MSG_TEMPLATE
)
37 $(call ERROR_IF_EMPTY
, CPPCHECK_ENABLE
)
38 $(call ERROR_IF_NONBOOL
, CPPCHECK_FAIL_ON_WARNING
)
39 $(call ERROR_IF_NONBOOL
, CPPCHECK_QUIET
)
41 # Build a default argument list for cppcheck
42 BASE_CPPCHECK_FLAGS
:= --template
="$(CPPCHECK_MSG_TEMPLATE)" $(CPPCHECK_INCLUDES
:%=-I
%) $(CPPCHECK_EXCLUDES
:%=-i
%) --inline-suppr
--force --std
=c99
44 # Sanity check parameters and construct additional command line arguments to cppcheck
45 ifeq ($(CPPCHECK_FAIL_ON_WARNING
), Y
)
46 BASE_CPPCHECK_FLAGS
+= --error-exitcode
=1
48 ifeq ($(CPPCHECK_QUIET
), Y
)
49 BASE_CPPCHECK_FLAGS
+= --quiet
53 MSG_CPPCHECK_CMD
:= ' [CPPCHECK]:'
55 # Checks the CPPCheck configuration as used in the user project, to determine if any paths are missing or invalid
56 cppcheck-config
: $(MAKEFILE_LIST
)
57 @echo
$(MSG_CPPCHECK_CMD
) Checking cppcheck configuration
check on source files
58 cppcheck
$(BASE_CPPCHECK_FLAGS
) --check-config
$(CPPCHECK_FLAGS
) $(SRC
)
60 # Runs a static analysis using CPPCheck to determine if there are any issues
61 cppcheck
: $(MAKEFILE_LIST
)
62 @echo
$(MSG_CPPCHECK_CMD
) Performing static analysis on source files
63 cppcheck
$(BASE_CPPCHECK_FLAGS
) --enable
=$(CPPCHECK_ENABLE
) $(CPPCHECK_SUPPRESS
:%=--suppress
=%) $(CPPCHECK_FLAGS
) $(SRC
)
65 # Phony build targets for this module
66 .PHONY
: $(DMBS_BUILD_TARGETS
)