Add Build System documentation to the library manual. Update CPPCHECK build system...
[pub/USBasp.git] / LUFA / Build / lufa.cppcheck.in
1 #
2 # LUFA Library
3 # Copyright (C) Dean Camera, 2012.
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
15 # -----------------------------------------------------------------------------
16 # LUFA CPPCheck Buildsystem Makefile Module.
17 # -----------------------------------------------------------------------------
18 # DESCRIPTION:
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 # -----------------------------------------------------------------------------
22 # TARGETS:
23 #
24 # cppcheck - Scan the project with CPPCheck
25 # cppcheck-config - Use CPPCheck to look for missing include files
26 #
27 # MANDATORY PARAMETERS:
28 #
29 # SRC - List of source files to statically analyze
30 #
31 # OPTIONAL PARAMETERS:
32 #
33 # CPPCHECK_INCLUDES - Extra include paths to search for missing
34 # header files
35 # CPPCHECK_EXCLUDES - Source file paths to exclude checking (can be
36 # a path fragment if desired)
37 # CPPCHECK_MSG_TEMPLATE - Template for cppcheck error and warning output
38 # CPPCHECK_ENABLE - General cppcheck category checks to enable
39 # CPPCHECK_SUPPRESS - Specific cppcheck warnings to disable by ID
40 # CPPCHECK_FAIL_ON_WARNING - Set to Y to fail the build on cppcheck
41 # warnings, N to continue even if warnings occur
42 # CPPCHECK_QUIET - Enable cppcheck verbose or quiet output mode
43 # CPPCHECK_FLAGS - Additional flags to pass to cppcheck
44 #
45 # -----------------------------------------------------------------------------
46
47 ERROR_IF_UNSET = $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
48 ERROR_IF_EMPTY = $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
49 ERROR_IF_NONBOOL = $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
50
51 # Default values of optionally user-supplied variables
52 CPPCHECK_INCLUDES ?=
53 CPPCHECK_EXCLUDES ?=
54 CPPCHECK_MSG_TEMPLATE ?= {file}:{line}: {severity} ({id}): {message}
55 CPPCHECK_ENABLE ?= all
56 CPPCHECK_SUPPRESS ?= variableScope missingInclude
57 CPPCHECK_FAIL_ON_WARNING ?= Y
58 CPPCHECK_QUIET ?= Y
59 CPPCHECK_FLAGS ?=
60
61 # Sanity check user supplied values
62 $(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
63 $(call ERROR_IF_EMPTY, SRC)
64 $(call ERROR_IF_EMPTY, CPPCHECK_MSG_TEMPLATE)
65 $(call ERROR_IF_EMPTY, CPPCHECK_ENABLE)
66 $(call ERROR_IF_NONBOOL, CPPCHECK_FAIL_ON_WARNING)
67 $(call ERROR_IF_NONBOOL, CPPCHECK_QUIET)
68
69 # Build a default argument list for cppcheck
70 BASE_CPPCHECK_FLAGS := --template="$(CPPCHECK_MSG_TEMPLATE)" $(CPPCHECK_INCLUDES:%=-I%) $(CPPCHECK_EXCLUDES:%=-i%) --inline-suppr --force --std=c99
71
72 # Sanity check parameters and construct additional command line arguments to cppcheck
73 ifeq ($(CPPCHECK_FAIL_ON_WARNING), Y)
74 BASE_CPPCHECK_FLAGS += --error-exitcode=1
75 endif
76 ifeq ($(CPPCHECK_QUIET), Y)
77 BASE_CPPCHECK_FLAGS += --quiet
78 endif
79
80 # Output Messages
81 MSG_CPPCHECK_CMD := ' [CPPCHECK]:'
82
83 cppcheck-config:
84 @echo $(MSG_CPPCHECK_CMD) Checking cppcheck configuration check on source files
85 cppcheck $(BASE_CPPCHECK_FLAGS) --check-config $(CPPCHECK_FLAGS) $(SRC)
86
87 cppcheck:
88 @echo $(MSG_CPPCHECK_CMD) Performing cppcheck analysis on source files
89 cppcheck $(BASE_CPPCHECK_FLAGS) --enable=$(CPPCHECK_ENABLE) $(CPPCHECK_SUPPRESS:%=--suppress=%) $(CPPCHECK_FLAGS) $(SRC)
90
91 # Phony build targets for this module
92 .PHONY: cppcheck-config cppcheck