]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/LUFA/Build/lufa_cppcheck.mk
Merge commit 'f6d56675f9f981c5464f0ca7a1fbb0162154e8c5'
[tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / LUFA / Build / lufa_cppcheck.mk
1 #
2 # LUFA Library
3 # Copyright (C) Dean Camera, 2014.
4 #
5 # dean [at] fourwalledcubicle [dot] com
6 # www.lufa-lib.org
7 #
8
9 LUFA_BUILD_MODULES += CPPCHECK
10 LUFA_BUILD_TARGETS += cppcheck cppcheck-config
11 LUFA_BUILD_MANDATORY_VARS += SRC
12 LUFA_BUILD_OPTIONAL_VARS += CPPCHECK_INCLUDES CPPCHECK_EXCLUDES CPPCHECK_MSG_TEMPLATE CPPCHECK_ENABLE \
13 CPPCHECK_SUPPRESS CPPCHECK_FAIL_ON_WARNING CPPCHECK_QUIET CPPCHECK_FLAGS
14 LUFA_BUILD_PROVIDED_VARS +=
15 LUFA_BUILD_PROVIDED_MACROS +=
16
17 # -----------------------------------------------------------------------------
18 # LUFA CPPCheck Buildsystem Makefile Module.
19 # -----------------------------------------------------------------------------
20 # DESCRIPTION:
21 # Provides a set of targets to scan a project with the free "cppcheck" static
22 # analysis tool, to check for code errors at runtime
23 # (see http://cppcheck.sourceforge.net).
24 # -----------------------------------------------------------------------------
25 # TARGETS:
26 #
27 # cppcheck - Scan the project with CPPCheck
28 # cppcheck-config - Use CPPCheck to look for missing include files
29 #
30 # MANDATORY PARAMETERS:
31 #
32 # SRC - List of source files to statically analyze
33 #
34 # OPTIONAL PARAMETERS:
35 #
36 # CPPCHECK_INCLUDES - Extra include paths to search for missing
37 # header files
38 # CPPCHECK_EXCLUDES - Source file paths to exclude checking (can be
39 # a path fragment if desired)
40 # CPPCHECK_MSG_TEMPLATE - Template for cppcheck error and warning output
41 # CPPCHECK_ENABLE - General cppcheck category checks to enable
42 # CPPCHECK_SUPPRESS - Specific cppcheck warnings to disable by ID
43 # CPPCHECK_FAIL_ON_WARNING - Set to Y to fail the build on cppcheck
44 # warnings, N to continue even if warnings occur
45 # CPPCHECK_QUIET - Enable cppcheck verbose or quiet output mode
46 # CPPCHECK_FLAGS - Additional flags to pass to cppcheck
47 #
48 # PROVIDED VARIABLES:
49 #
50 # (None)
51 #
52 # PROVIDED MACROS:
53 #
54 # (None)
55 #
56 # -----------------------------------------------------------------------------
57
58 SHELL = /bin/sh
59
60 ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
61 ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
62 ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
63
64 # Default values of optionally user-supplied variables
65 CPPCHECK_INCLUDES ?=
66 CPPCHECK_EXCLUDES ?=
67 CPPCHECK_MSG_TEMPLATE ?= {file}:{line}: {severity} ({id}): {message}
68 CPPCHECK_ENABLE ?= all
69 CPPCHECK_SUPPRESS ?= variableScope missingInclude
70 CPPCHECK_FAIL_ON_WARNING ?= Y
71 CPPCHECK_QUIET ?= Y
72 CPPCHECK_FLAGS ?=
73
74 # Sanity check user supplied values
75 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
76 $(call ERROR_IF_EMPTY, SRC)
77 $(call ERROR_IF_EMPTY, CPPCHECK_MSG_TEMPLATE)
78 $(call ERROR_IF_EMPTY, CPPCHECK_ENABLE)
79 $(call ERROR_IF_NONBOOL, CPPCHECK_FAIL_ON_WARNING)
80 $(call ERROR_IF_NONBOOL, CPPCHECK_QUIET)
81
82 # Build a default argument list for cppcheck
83 BASE_CPPCHECK_FLAGS := --template="$(CPPCHECK_MSG_TEMPLATE)" $(CPPCHECK_INCLUDES:%=-I%) $(CPPCHECK_EXCLUDES:%=-i%) --inline-suppr --force --std=c99
84
85 # Sanity check parameters and construct additional command line arguments to cppcheck
86 ifeq ($(CPPCHECK_FAIL_ON_WARNING), Y)
87 BASE_CPPCHECK_FLAGS += --error-exitcode=1
88 endif
89 ifeq ($(CPPCHECK_QUIET), Y)
90 BASE_CPPCHECK_FLAGS += --quiet
91 endif
92
93 # Output Messages
94 MSG_CPPCHECK_CMD := ' [CPPCHECK]:'
95
96 # Checks the CPPCheck configuration as used in the user project, to determine if any paths are missing or invalid
97 cppcheck-config: $(MAKEFILE_LIST)
98 @echo $(MSG_CPPCHECK_CMD) Checking cppcheck configuration check on source files
99 cppcheck $(BASE_CPPCHECK_FLAGS) --check-config $(CPPCHECK_FLAGS) $(SRC)
100
101 # Runs a static analysis using CPPCheck to determine if there are any issues
102 cppcheck: $(MAKEFILE_LIST)
103 @echo $(MSG_CPPCHECK_CMD) Performing static analysis on source files
104 cppcheck $(BASE_CPPCHECK_FLAGS) --enable=$(CPPCHECK_ENABLE) $(CPPCHECK_SUPPRESS:%=--suppress=%) $(CPPCHECK_FLAGS) $(SRC)
105
106 # Phony build targets for this module
107 .PHONY: cppcheck-config cppcheck
Imprint / Impressum