forked from userver-framework/userver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
167 lines (133 loc) · 5.11 KB
/
Makefile.common
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
USERVER_ROOTDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
# NOTE: use Makefile.local for customization
-include $(USERVER_ROOTDIR)/Makefile.local
include $(USERVER_ROOTDIR)/Makefile.variables
.PHONY: check-yandex-env
check-yandex-env:
@if ! `apt-key finger '7FCD11186050CD1A' 2>&1 | grep Yandex >/dev/null 2>&1` && ! `brew tap 2>/dev/null | grep 'yandex' >/dev/null` ; then \
echo "!!! This Makefile is only for use in the Yandex environment. Refer to the docs for setup and build instructions"; \
exit 1; \
fi
.DEFAULT_GOAL := all
.PHONY: all
all: build
.PHONY: init
init: cmake
.PHONY: cmake
cmake: $(BUILD_DIR)/Makefile
$(BUILD_DIR)/Makefile:
@echo "Makefile: CC = ${CC} CXX = ${CXX}"
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && \
cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $(CMAKE_OPTS_INTERNAL) $(CMAKE_DIR)
.PHONY: build
build: cmake
$(MAKE) -j$(NPROCS) -C $(BUILD_DIR) all
build-yandex-taxi-%: cmake
$(MAKE) -j$(NPROCS) -C $(BUILD_DIR) yandex-taxi-$*
ALL_SANITIZER_NAMES = addr ub
# Checks cmake cache for variable value, exits with non-zero code if not found.
# $(1) -- variable name
# $(2) -- values list
test-cmake-var-values = ( \
cd $(BUILD_DIR) 2>/dev/null \
&& cmake -N -L $(CMAKE_DIR) | grep '^$(1):.*=' | cut -d= -f2 \
$(foreach value,$(wordlist 2,$(words $(2)),$(2)),| grep $(value)) \
| grep -q $(firstword $(2)) \
)
# Checks cmake cache for variable value and reruns it when necessary.
# (Lists current cmake variable values and greps the required ones.
# If any of the values is not present, cmake is forcibly rerun.)
# $(1) -- variable name
# $(2) -- values list
ensure-cmake-var-values = \
$(call test-cmake-var-values,$(1),$(2)) \
|| $(eval CMAKE_OPTS_INTERNAL += -D$(1)="$(2)") $(MAKE) -B cmake
.PHONY: build-with-sanitizers
build-with-sanitizers:
$(call ensure-cmake-var-values,SANITIZE,$(ALL_SANITIZER_NAMES))
@$(MAKE) all
# The $* target might require a specific cmake invocation.
# Don't try to play with messy Makefile here, just ask the user
# to cleanup the build tree.
# Probably the user doesn't want to re-run cmake at all.
build-with-sanitizers-target-%:
@$(call test-cmake-var-values,SANITIZE,$(ALL_SANITIZER_NAMES)) || ( \
if [ -e "$(BUILD_DIR)" ]; then \
echo >&2 "\n\tError: cmake is not configured with -DUSERVER_SANITIZE. Please run 'make clean' and try again.\n"; \
exit 1; \
fi \
)
@$(eval CMAKE_OPTS_INTERNAL += -DUSERVER_SANITIZE="$(ALL_SANITIZER_NAMES)") \
$(MAKE) $*
.PHONY: clang-static-analyzer
clang-static-analyzer:
mkdir -p $(BUILD_CHECK_DIR)
cd $(BUILD_CHECK_DIR) && $(SCAN_BUILD) $(SCAN_BUILD_OPTS) cmake .. && $(SCAN_BUILD) $(SCAN_BUILD_OPTS) $(MAKE) -j$(NPROCS)
.PHONY: cppcheck
cppcheck: $(BUILD_DIR)/Makefile
cd $(BUILD_DIR) && $(MAKE) -j$(NPROCS) cppcheck
.PHONY: test
test: check-yandex-env
@$(MAKE) build
@cd $(BUILD_DIR) && ctest -V
.PHONY: utest
utest: check-yandex-env
@$(MAKE) build
@cd $(BUILD_DIR) && ctest -V -R '_unittest$$'
.PHONY: clang-tidy
clang-tidy: cmake
@tools/run-clang-tidy -clang-tidy-binary $(CLANG_TIDY_BINARY) -p $(BUILD_DIR) -q -j$(NPROCS)
.PHONY: teamcity-clang-tidy
teamcity-clang-tidy: cmake
@tools/run-clang-tidy -enable-teamcity -clang-tidy-binary $(CLANG_TIDY_BINARY) -p $(BUILD_DIR) -q -j$(NPROCS)
.PHONY: check-pep8
check-pep8:
@${PYTHON3_BIN_DIR}check-pep8 $(CMAKE_DIR)
.PHONY: smart-check-pep8
smart-check-pep8:
@${PYTHON3_BIN_DIR}check-pep8 --smart $(CMAKE_DIR)
.PHONY: teamcity-check-pep8
teamcity-check-pep8:
@${PYTHON3_BIN_DIR}check-pep8 --teamcity --jobs=$(TEAMCITY_LINT_JOBS_COUNT) -- $(CHANGED_DIRS) $(EXTRA_LINT_CHECK)
.PHONY: format
format: check-yandex-env
ifneq ($(shell which taxi-clang-format),)
@taxi-format .
else
$(error There is a new version of code-linters, please install: https://github.yandex-team.ru/taxi/code-linters#установка)
endif
.PHONY: smart-format
smart-format: check-yandex-env
ifneq ($(shell which taxi-clang-format),)
@taxi-format --smart .
else
$(error There is a new version of code-linters, please install: https://github.yandex-team.ru/taxi/code-linters#установка)
endif
.PHONY: teamcity-format
teamcity-format: check-yandex-env
@taxi-format --teamcity --jobs=$(TEAMCITY_LINT_JOBS_COUNT) -- $(CHANGED_DIRS) $(EXTRA_LINT_CHECK)
$(foreach fmt,$(FORMATTERS),taxi-$(fmt)): taxi-%:
@taxi-$* -- .
$(foreach fmt,$(FORMATTERS),smart-taxi-$(fmt)): smart-taxi-%:
@taxi-$* --smart -- .
.PHONY: clang-format
clang-format: check-yandex-env
ifneq ($(shell which taxi-clang-format),)
@taxi-clang-format .
else
$(error There is a new version of code-linters, please install: https://github.yandex-team.ru/taxi/code-linters#установка)
endif
.PHONY: smart-clang-format
smart-clang-format: check-yandex-env
ifneq ($(shell which taxi-clang-format),)
@taxi-clang-format --smart .
else
$(error There is a new version of code-linters, please install: https://github.yandex-team.ru/taxi/code-linters#установка)
endif
.PHONY: docs
docs: check-yandex-env
@(cat doxygen.conf || cat scripts/docs/doxygen.conf; echo OUTPUT_DIRECTORY=$(DOCS_DIR)) | doxygen -
.PHONY: clean-lto-cache
clean-lto-cache:
@rm -rf $(LTO_CACHE_FOLDER)