forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppcheck.mk
More file actions
274 lines (249 loc) · 8.79 KB
/
cppcheck.mk
File metadata and controls
274 lines (249 loc) · 8.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#/
# @license Apache-2.0
#
# Copyright (c) 2021 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# VARIABLES #
# Define the file path for storing a list of package `include` paths:
cppcheck_include_paths := $(TMP_DIR)/__tmp_cppcheck_include_paths__.txt
# Define the path to a list of warnings to suppress:
CPPCHECK_SUPPRESSIONS_LIST ?= $(CONFIG_DIR)/cppcheck/suppressions.txt
# Define the path to a list of warnings to suppress for examples:
CPPCHECK_SUPPRESSIONS_LIST_EXAMPLES ?= $(CONFIG_DIR)/cppcheck/suppressions.examples.txt
# Define the path to a list of warnings to suppress for benchmarks:
CPPCHECK_SUPPRESSIONS_LIST_BENCHMARKS ?= $(CONFIG_DIR)/cppcheck/suppressions.benchmarks.txt
# Define the path to a list of warnings to suppress for test fixtures:
CPPCHECK_SUPPRESSIONS_LIST_TESTS_FIXTURES ?= $(CONFIG_DIR)/cppcheck/suppressions.tests_fixtures.txt
# Define the command-line options to use when invoking the cppcheck executable:
CPPCHECK_DEFAULT_FLAGS ?= \
--std=c99 \
--enable=warning,style,performance,portability,information,missingInclude \
--inconclusive \
--includes-file=$(cppcheck_include_paths) \
--language=c \
--error-exitcode=1 \
--inline-suppr \
--check-level=exhaustive \
--quiet
# Additional flags that a user can set:
CPPCHECK_FLAGS ?=
# RULES #
#/
# Checks whether [cppcheck][1] is installed.
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
#
# @example
# make check-cppcheck
#/
check-cppcheck:
ifeq (, $(shell command -v $(CPPCHECK) 2>/dev/null))
$(QUIET) echo ''
$(QUIET) echo 'cppcheck is not installed. Please install cppcheck and try again.'
$(QUIET) echo 'For install instructions, see http://cppcheck.sourceforge.net/'
$(QUIET) echo 'and the project development guide.'
$(QUIET) echo ''
$(QUIET) exit 1
else
$(QUIET) echo 'cppcheck is installed.'
$(QUIET) exit 0
endif
.PHONY: check-cppcheck
#/
# Generates a temporary file containing a list of package include paths.
#
# @private
#/
$(cppcheck_include_paths):
$(QUIET) $(MKDIR_RECURSIVE) $(TMP_DIR)
$(QUIET) $(MAKE) -f $(this_file) list-pkgs-includes > $(cppcheck_include_paths)
#/
# Lints C source files using [cppcheck][1].
#
# ## Notes
#
# - This rule is useful when wanting to glob for C source files (e.g., lint all C source files for a particular package).
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
# @param {string} [SOURCES_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error
#
# @example
# make cppcheck-src
#
# @example
# make cppcheck-src SOURCES_FILTER=".*/math/base/special/.*"
#/
cppcheck-src: cppcheck-clean $(cppcheck_include_paths)
ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_C_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST) $$file || exit 1; \
done
else
$(QUIET) $(FIND_C_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST) $$file || echo 'Linting failed.'; \
done
endif
.PHONY: cppcheck-src
#/
# Lints C examples files using [cppcheck][1].
#
# ## Notes
#
# - This rule is useful when wanting to glob for C examples files (e.g., lint all C examples files for a particular package).
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
# @param {string} [EXAMPLES_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error
#
# @example
# make cppcheck-examples
#
# @example
# make cppcheck-examples EXAMPLES_FILTER=".*/math/base/special/.*"
#/
cppcheck-examples: cppcheck-clean $(cppcheck_include_paths)
ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_C_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --enable=unusedFunction --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_EXAMPLES) $$file || exit 1; \
done
else
$(QUIET) $(FIND_C_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --enable=unusedFunction --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_EXAMPLES) $$file || echo 'Linting failed.'; \
done
endif
.PHONY: cppcheck-examples
#/
# Lints C benchmark files using [cppcheck][1].
#
# ## Notes
#
# - This rule is useful when wanting to glob for C benchmark files (e.g., lint all C benchmark files for a particular package).
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
# @param {string} [BENCHMARKS_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error
#
# @example
# make cppcheck-benchmarks
#
# @example
# make cppcheck-benchmarks BENCHMARKS_FILTER=".*/math/base/special/.*"
#/
cppcheck-benchmarks: cppcheck-clean $(cppcheck_include_paths)
ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_C_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_BENCHMARKS) $$file || exit 1; \
done
else
$(QUIET) $(FIND_C_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_BENCHMARKS) $$file || echo 'Linting failed.'; \
done
endif
.PHONY: cppcheck-benchmarks
#/
# Lints C test fixture files using [cppcheck][1].
#
# ## Notes
#
# - This rule is useful when wanting to glob for C test fixture files (e.g., lint all C test fixture files for a particular package).
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
# @param {string} [TESTS_FIXTURES_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error
#
# @example
# make cppcheck-tests-fixtures
#
# @example
# make cppcheck-tests-fixtures TESTS_FIXTURES_FILTER=".*/math/base/special/.*"
#/
cppcheck-tests-fixtures: cppcheck-clean $(cppcheck_include_paths)
ifeq ($(FAIL_FAST), true)
$(QUIET) $(FIND_C_TESTS_FIXTURES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_TESTS_FIXTURES) $$file || exit 1; \
done
else
$(QUIET) $(FIND_C_TESTS_FIXTURES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST_TESTS_FIXTURES) $$file || echo 'Linting failed.'; \
done
endif
.PHONY: cppcheck-tests-fixtures
#/
# Lints a specified list of C files using [cppcheck][1].
#
# ## Notes
#
# - This rule is useful when wanting to lint a list of C files generated by some other command (e.g., a list of changed C files obtained via `git diff`).
#
# [1]: http://cppcheck.sourceforge.net/
#
# @private
# @param {string} FILES - list of C file paths
# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error
#
# @example
# make cppcheck-files FILES='/foo/file.c /bar/file.c'
#/
cppcheck-files: cppcheck-clean $(cppcheck_include_paths)
ifeq ($(FAIL_FAST), true)
$(QUIET) for file in $(FILES); do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST) $$file || exit 1; \
done
else
$(QUIET) for file in $(FILES); do \
echo ''; \
echo "Linting file: $$file"; \
$(CPPCHECK) $(CPPCHECK_DEFAULT_FLAGS) $(CPPCHECK_FLAGS) --suppressions-list=$(CPPCHECK_SUPPRESSIONS_LIST) $$file || echo 'Linting failed.'; \
done
endif
.PHONY: cppcheck-files
#/
# Removes cppcheck temporary files.
#
# @example
# make cppcheck-clean
#/
cppcheck-clean:
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(cppcheck_include_paths)
.PHONY: cppcheck-clean