-
Notifications
You must be signed in to change notification settings - Fork 14
/
syntax.mk
128 lines (104 loc) · 4.1 KB
/
syntax.mk
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
.PHONY: check-syntax-c check-syntax-cc check-syntax
CXX_EXT ?= cc
check-syntax: check-syntax-c check-syntax-cc $(EXTRA_CHECKS)
ifdef CHK_SOURCES
C_CHK_SOURCES = $(filter %.c,$(CHK_SOURCES))
CXX_CHK_SOURCES = $(filter %.$(CXX_EXT),$(CHK_SOURCES))
else
C_CHK_SOURCES = $(C_SRC)
CXX_CHK_SOURCES = $(CXX_SRC)
endif
check-syntax-c:
ifneq (,$(findstring .c,$(C_CHK_SOURCES)))
@echo SYNTAX_CHECK $(notdir $(C_CHK_SOURCES))
$(Q)$(CC) -fsyntax-only $(CFLAGS) $(C_CHK_SOURCES)
endif
ifneq (,$(findstring .c,$(C_TESTS_SRC)))
@echo SYNTAX_CHECK $(C_TESTS_SRC)
$(Q)$(CC) -fsyntax-only $(WARNFLAGS) $(INCLUDES) $(C_TESTS_SRC)
endif
check-syntax-cc:
ifneq (,$(findstring .$(CXX_EXT),$(CXX_CHK_SOURCES)))
@echo SYNTAX_CHECK $(notdir $(CXX_CHK_SOURCES))
$(Q)$(CXX) -fsyntax-only $(CXXFLAGS) $(CXX_CHK_SOURCES)
endif
ifneq (,$(findstring .$(CXX_EXT),$(CXX_TESTS_SRC)))
@echo SYNTAX_CHECK $(CXX_TESTS_SRC)
$(Q)$(CXX) -fsyntax-only $(CXXWARNFLAGS) $(INCLUDES) $(CXX_TESTS_SRC)
endif
.PHONY: lint lint-c lint-cc
lint: lint-c lint-cc
# Where does the compiler search for #includes?
COMPILER_INCLUDE_DIRS ?= $(shell echo | cpp -v |& perl -0pe "s/.*\#include.*search starts here:(.*)\#include.*search starts here:(.*)End of search list..*/\1 \2/gms; s/\n/ /gms")
CXX_INCLUDE_DIRS ?= $(COMPILER_INCLUDE_DIRS) $(shell $(CXX) -print-file-name=include)
CXX_INCLUDES ?= $(foreach include,$(CXX_INCLUDE_DIRS),-I$(include))
CC_INCLUDE_DIRS ?= $(COMPILER_INCLUDE_DIRS) $(shell $(CC) -print-file-name=include)
CC_INCLUDES ?= $(foreach include,$(CC_INCLUDE_DIRS),-I$(include))
# Google's C++ linter (not too bad for C either)
GOOGLE_CPPLINT ?= $(shell if [ `which cpplint.py 2>/dev/null` ]; then echo cpplint.py; elif [ `which cpplint 2>/dev/null` ]; then echo cpplint; fi;)
# cppcheck -- warning, this can be quite slow, so we don't include it
# by default!
CPPCHECK ?= $(shell if [ `which cppcheck 2>/dev/null` ]; then echo cppcheck; fi;)
CPPCHECK_FLAGS ?= --enable=all --std=c++11 --force
# The venerable splint. It's infuriating and fragile, so we don't
# include it by default
SPLINT ?= $(shell if [ `which splint 2>/dev/null` ]; then echo splint; fi;)
SPLINT_FLAGS ?= +posixlib -warnposix
# sparse
SPARSE ?= $(shell if [ `which cgcc 2>/dev/null` ]; then echo cgcc; fi;)
SPARSE_FLAGS ?= -Wsparse-all -Wno-declaration-after-statement -fsyntax-only
# Overload these to specify more built-in tests.
C_LINT_TARGETS ?= cpplint-c sparse
CXX_LINT_TARGETS ?= cpplint-cc
# Allow the user to tack on additional targets.
.PHONY: $(C_LINT_TARGETS) $(CXX_LINT_TARGETS) $(USER_C_LINT_TARGETS)
# Final configuration
lint-c: $(C_LINT_TARGETS) $(USER_C_LINT_TARGETS)
lint-cc: $(CXX_LINT_TARGETS) $(USER_CXX_LINT_TARGETS)
# C linting
ifneq (,$(findstring .c,$(C_CHK_SOURCES)))
cpplint-c:
ifneq (,$(GOOGLE_CPPLINT))
@echo CPPLINT $(notdir $(C_CHK_SOURCES))
$(Q)$(GOOGLE_CPPLINT) --filter=-readability/casting $(C_CHK_SOURCES) 2>&1 | perl -pe "s/^(.*\.c:\d+:)\s+(.*)$$/\1 warning: \2/"
else
@echo "'cpplint.py' not found on your $$PATH!"
endif
splint:
ifneq (,$(SPLINT))
@echo SPLINT $(notdir $(C_CHK_SOURCES))
$(Q)$(SPLINT) $(SPLINT_FLAGS) $(CC_INCLUDES) $(INCLUDES) $(C_CHK_SOURCES)
else
@echo "'splint' not found on your $$PATH!"
endif
sparse:
ifneq (,$(SPARSE))
ifdef SPARSE
ifneq (,$(C_OBJ))
# bit of a hack, this
@echo SPARSE \(CGCC\) $(notdir $(C_OBJ))
$(Q)$(MAKE) CC='$(SPARSE) $(SPARSE_FLAGS)' $(C_OBJ)
else
@echo "sparse (cgcc) is only for C (not C++) code!"
endif
else
@echo "'cgcc' not found on your $$PATH!"
endif
endif
endif # C_CHK_SOURCES
ifneq (,$(findstring .$(CXX_EXT),$(CXX_CHK_SOURCES)))
cpplint-cc:
ifneq (,$(GOOGLE_CPPLINT))
@echo CPPLINT $(notdir $(CXX_CHK_SOURCES))
$(Q)$(GOOGLE_CPPLINT) $(CXX_CHK_SOURCES) 2>&1 | perl -pe "s/^(.*\.$(CXX_EXT):\d+:)\s+(.*)$$/\1 warning: \2/"
else
@echo "'cpplint.py' not found on your $$PATH!"
endif
cppcheck:
ifneq (,$(CPPCHECK))
@echo CPPCHECK $(notdir $(CXX_CHK_SOURCES))
$(Q)$(CPPCHECK) $(CPPCHECK_FLAGS) $(CXX_INCLUDES) $(INCLUDES) $(CXX_CHK_SOURCES) 2>&1 >/dev/null | perl -pe "s/\[(\S+\.$(CXX_EXT)):(\d+)\]:/\1:\2: warning:/; s/^\(information\).*$$//"
else
@echo "'cppcheck' not found on your $$PATH!"
endif
endif # CXX_CHK_SOURCES