Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (156 loc) · 6.55 KB
/
Copy pathMakefile
File metadata and controls
184 lines (156 loc) · 6.55 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
BUILD_DIR := $(or $(BUILD_DIR),build)
BUILD_TYPE = $(or $(file < $(BUILD_DIR)/BUILD_TYPE),release-build)
all: build
.PHONY: all
build: $(BUILD_TYPE)
.PHONY: build
release-build:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && echo $@ > BUILD_TYPE && cmake -DCMAKE_BUILD_TYPE=Release $(shell pwd) && make -j $(shell nproc)
.PHONY: release-build
debug-build:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && echo $@ > BUILD_TYPE && cmake -DCMAKE_BUILD_TYPE=Debug -DAMON_ENABLE_TESTS=1 -DAMON_ENABLE_SANITIZERS=1 -DAMON_ENABLE_COVERAGE=0 $(shell pwd) && make -j $(shell nproc)
.PHONY: debug-build
debug-build-strict:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && echo $@ > BUILD_TYPE && env CFLAGS=-Werror CXXFLAGS=-Werror cmake -DCMAKE_BUILD_TYPE=Debug -DAMON_ENABLE_TESTS=1 -DAMON_ENABLE_SANITIZERS=1 -DAMON_ENABLE_COVERAGE=0 $(shell pwd) && make -j $(shell nproc)
.PHONY: debug-build-strict
test: $(if $(filter debug-build%,$(BUILD_TYPE)),$(BUILD_TYPE),debug-build)
cd build && make test
.PHONY: test
coverage-build:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && echo $@ > BUILD_TYPE && cmake -DCMAKE_BUILD_TYPE=Debug -DAMON_ENABLE_TESTS=1 -DAMON_ENABLE_SANITIZERS=1 -DAMON_ENABLE_COVERAGE=1 $(shell pwd) && make -j $(shell nproc)
.PHONY: coverage-build
coverage: coverage-build
find $(BUILD_DIR) -name '*.gcda' -delete
cd $(BUILD_DIR) && make test
mkdir -p $(BUILD_DIR)/coverage-html
uv tool run gcovr --root . $(BUILD_DIR) \
--filter 'lib/' \
--exclude 'lib/src/TestWithMain.cpp' \
--exclude-function '/.*_Test.*/' \
--cobertura $(BUILD_DIR)/coverage.xml \
--html-details $(BUILD_DIR)/coverage-html/index.html \
--txt
.PHONY: coverage
clean:
rm -rf $(BUILD_DIR)
.PHONY: clean
clean-build: clean build
.PHONY: clean-build
rpm:
@set -eu; \
topdir="$(abspath $(BUILD_DIR)/rpm)"; \
mkdir -p "$$topdir/BUILD" "$$topdir/BUILDROOT" "$$topdir/RPMS" \
"$$topdir/SOURCES" "$$topdir/SPECS" "$$topdir/SRPMS"; \
git_ref="$$(git describe --tags --always | tr -c '[:alnum:].\n' '.')"; \
if test -z "$$(git status --porcelain)"; then git_state=clean; else git_state=dirty; fi; \
printf '%s.%s\n' "$$git_ref" "$$git_state" \
> "$$topdir/SOURCES/adaptmon.git-version"; \
tar -C "$(CURDIR)" \
--exclude='./.git' \
--exclude='./$(BUILD_DIR)' \
--transform='s,^\.,adaptmon,' \
-czf "$$topdir/SOURCES/adaptmon.tar.gz" .; \
cp adaptmon.spec "$$topdir/SPECS/"; \
rpmbuild -ba \
--define "_topdir $$topdir" \
"$$topdir/SPECS/adaptmon.spec"; \
echo "RPMs written to $$topdir/RPMS"; \
echo "Source RPM written to $$topdir/SRPMS"
.PHONY: rpm
format:
find lib/ apps/ -type f -regex '.*\.\(cpp\|hpp\|c\|h\)' -print0 | xargs -0 clang-format --dry-run --Werror
.PHONY: format
format-fix:
find lib/ apps/ -type f -regex '.*\.\(cpp\|hpp\|c\|h\)' -print0 | xargs -0 clang-format -i --Werror
.PHONY: format-fix
compile-commands:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $(shell pwd)
.PHONY: compile-commands
tidy:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DAMON_ENABLE_TESTS=OFF $(shell pwd)
run-clang-tidy -p $(BUILD_DIR) -quiet -j $(shell nproc) -header-filter "$(shell pwd)/(apps|lib)" lib/ apps/
.PHONY: tidy
tidy-fix:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DAMON_ENABLE_TESTS=OFF $(shell pwd)
run-clang-tidy -p $(BUILD_DIR) -quiet -fix -j $(shell nproc) -header-filter "$(shell pwd)/(apps|lib)" lib/ apps/
.PHONY: tidy-fix
format-cmake:
tools/format-cmake --check
.PHONY: format-cmake
format-cmake-fix:
tools/format-cmake
.PHONY: format-cmake-fix
doxygen:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DAMON_ENABLE_DOXYGEN=On -DCMAKE_BUILD_TYPE=Debug $(shell pwd) && make doxygen
.PHONY: doxygen
doxygen-strict:
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DAMON_ENABLE_DOXYGEN=On -DCMAKE_BUILD_TYPE=Debug -DDOXYGEN_WARN_AS_ERROR=FAIL_ON_WARNINGS $(shell pwd) && make doxygen
.PHONY: doxygen-strict
editorconfig:
editorconfig-checker
.PHONY: editorconfig
dev-container:
docker build -f docker/Dockerfile.gitlab-ci -t adaptmon-dev-container \
--build-arg USERID=$(shell id -u) --build-arg GROUPID=$(shell id -g) \
--build-arg USER=$(shell whoami) --build-arg GROUP=$(shell getent group "$$(id -u)" | cut -d: -f1 ) \
--build-arg OS_DISTRO=$(or ${OS_DISTRO},oraclelinux) --build-arg OS_RELEASE=$(or ${OS_RELEASE},10) \
.
@echo "Hint:"
@echo " docker run --rm -it -v .:/adaptmon --workdir /adaptmon adaptmon-dev-container /bin/bash"
.PHONY: dev-docker
enter-dev-container: dev-container
docker run --rm -it -v .:/adaptmon --workdir /adaptmon adaptmon-dev-container /bin/bash
.PHONY: enter-dev-container
commitlint:
if [ -n "$${CI_MERGE_REQUEST_DIFF_BASE_SHA}" ] && [ -n "${CI_COMMIT_SHA}" ]; then \
BASE="$${CI_MERGE_REQUEST_DIFF_BASE_SHA}"; \
HEAD="$${CI_COMMIT_SHA}"; \
else \
BASE="$$(git log --pretty=format:"%H%d" | grep -E "^\w+ " | tail -n+2 | head -n1 | cut -d" " -f1)"; \
HEAD="$$(git rev-parse HEAD)"; \
fi; \
docker run --rm -v .:/w --workdir /w --entrypoint /bin/sh registry.hub.docker.com/commitlint/commitlint:latest -c \
"git config --global --add safe.directory /w && commitlint --from=$$BASE --to=$$HEAD"
.PHONY: commitlint
atomic-commits:
if [ -n "$${CI_MERGE_REQUEST_DIFF_BASE_SHA}" ] && [ -n "${CI_COMMIT_SHA}" ]; then \
BASE="$${CI_MERGE_REQUEST_DIFF_BASE_SHA}"; \
HEAD="$${CI_COMMIT_SHA}"; \
else \
BASE="$$(git log --pretty=format:"%H%d" | grep -E "^\w+ " | tail -n+2 | head -n1 | cut -d" " -f1)"; \
HEAD="$$(git rev-parse HEAD)"; \
fi; \
branch="$$(git branch --show-current)"; \
git stash store "$$(git stash create)" && did_stash=1 && git reset --hard HEAD; \
git rev-list --reverse $${BASE}..$${HEAD} | xargs -I{} sh -c "set -e; echo; echo @@@@@@@@@@@@@@@@@@@@ {} @@@@@@@@@@@@@@@@@@@@; echo; git checkout {}; make; echo"; \
EC=$$?; \
if [ -n "$$branch" ]; then git checkout "$$branch"; fi; \
if [ -n "$$did_stash" ]; then git stash pop; fi; \
exit $${EC}
.PHONY: atomic-commits
pragma-once:
@tools/checks/check-pragma-once
.PHONY: pragma-once
custom-checks:
@rc=0; \
GREEN='\033[0;32m'; \
RED='\033[0;31m'; \
YELLOW='\033[1;33m'; \
NC='\033[0m'; \
for script in tools/checks/*; do \
if [ -x "$$script" ]; then \
printf "$${YELLOW}==> Running %s$${NC}\n" "$$script"; \
if "$$script"; then \
printf "$${GREEN}✔ PASS %s$${NC}\n\n" "$$script"; \
else \
printf "$${RED}✖ FAIL %s$${NC}\n\n" "$$script"; \
rc=1; \
fi; \
fi; \
done; \
exit $$rc
.PHONY: custom-checks
# don't be afraid to add Python tests for your applications to this target
pytest: build
cd apps/amon-anonymizer && uv run pytest -v
.PHONY: pytest