-
Notifications
You must be signed in to change notification settings - Fork 4
/
GNUmakefile
138 lines (118 loc) · 4.24 KB
/
GNUmakefile
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
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Robin Jarry
BUILDDIR ?= build
BUILDTYPE ?= debugoptimized
SANITIZE ?= none
V ?= 0
ifeq ($V,1)
ninja_opts = --verbose
Q =
else
Q = @
endif
.PHONY: all
all: $(BUILDDIR)/build.ninja
$Q ninja -C $(BUILDDIR) $(ninja_opts)
.PHONY: unit-tests
unit-tests: $(BUILDDIR)/build.ninja
$Q ninja -C $(BUILDDIR) test $(ninja_opts)
.PHONY: smoke-tests
smoke-tests: all
./smoke/run.sh $(BUILDDIR)
.PHONY: coverage
coverage: test
$Q mkdir -p $(BUILDDIR)/coverage
$Q gcovr --html-details $(BUILDDIR)/coverage/index.html --txt \
-e '.*_test.c' -ur . $(BUILDDIR)
@echo Coverage data is present in $(BUILDDIR)/coverage/index.html
.PHONY: all
clean:
$Q ninja -C $(BUILDDIR) clean $(ninja_opts)
.PHONY: install
install: $(BUILDDIR)/build.ninja
$Q meson install -C $(BUILDDIR) --skip-subprojects
meson_opts := --buildtype=$(BUILDTYPE) --werror --warnlevel=2 -Db_sanitize=$(SANITIZE)
meson_opts += $(MESON_EXTRA_OPTS)
$(BUILDDIR)/build.ninja:
meson setup $(BUILDDIR) $(meson_opts)
empty :=
space := $(empty) $(empty)
version := $(shell { git describe --long --abbrev=8 --dirty 2>/dev/null || \
sed -En 's/.* \|\| echo (v[0-9\.]+)\>.*/\1-'`date +%Y%m%d%H%M%S`.`hostname`'/p' meson.build; } | \
sed 's/^v//;s/-/ /')
debversion = $(subst $(space),+,$(version))
.PHONY: deb
deb:
$Q rm -f debian/changelog
dch --create --package grout --newversion '$(debversion)' -M Development snapshot.
dpkg-buildpackage -b
$Q arch=`dpkg-architecture -qDEB_HOST_ARCH` && \
mv -vf ../grout-dev_$(debversion)_all.deb grout-dev_all.deb && \
for name in grout grout-dbgsym; do \
mv -vf ../$${name}_$(debversion)_$$arch.deb \
$${name}_$$arch.deb || exit; \
done
rpmversion = $(firstword $(version))
rpmrelease = $(subst -,.,$(lastword $(version))).$(shell sed -nE 's/PLATFORM_ID="platform:(.*)"/\1/p' /etc/os-release)
.PHONY: rpm
rpm:
rpmbuild -bb --build-in-place -D 'version $(rpmversion)' -D 'release $(rpmrelease)' rpm/grout.spec
$Q arch=`rpm --eval '%{_arch}'` && \
version="$(rpmversion)-$(rpmrelease)" && \
mv -vf ~/rpmbuild/RPMS/noarch/grout-devel-$$version.noarch.rpm grout-devel.noarch.rpm && \
for name in grout grout-debuginfo grout-debugsource; do \
mv -vf ~/rpmbuild/RPMS/$$arch/$$name-$$version.$$arch.rpm \
$$name.$$arch.rpm || exit; \
done
c_src = git ls-files '*.[ch]' ':!:subprojects'
all_files = git ls-files ':!:subprojects'
licensed_files = git ls-files ':!:*.svg' ':!:LICENSE' ':!:*.md' ':!:*.asc' ':!:subprojects' ':!:debian' ':!:.*'
.PHONY: lint
lint:
@echo '[clang-format]'
$Q tmp=`mktemp` && trap "rm -f $$tmp" EXIT && $(c_src) > "$$tmp" && \
clang-format --files="$$tmp" --dry-run --Werror
@echo '[license-check]'
$Q ! $(licensed_files) | while read -r f; do \
if ! grep -qF 'SPDX-License-Identifier: BSD-3-Clause' $$f; then \
echo $$f; \
fi; \
if ! grep -q 'Copyright .* [0-9]\{4\} .*' $$f; then \
echo $$f; \
fi; \
done | LC_ALL=C sort -u | grep --color . || { \
echo 'error: files are missing license and/or copyright notice'; \
exit 1; \
}
@echo '[white-space]'
$Q $(all_files) | xargs devtools/check-whitespace
.PHONY: format
format:
@echo '[clang-format]'
$Q tmp=`mktemp` && trap "rm -f $$tmp" EXIT && $(c_src) > "$$tmp" && \
clang-format --files="$$tmp" -i --verbose
REVISION_RANGE ?= origin/main..
.PHONY: check-patches
check-patches:
$Q devtools/check-patches $(REVISION_RANGE)
.PHONY: git-config
git-config:
git config format.subjectPrefix "PATCH grout"
git config sendemail.to "[email protected]"
git config format.notes true
git config format.coverFromDescription subject
git config notes.rewriteRef refs/notes/commits
git config notes.rewriteMode concatenate
@mkdir -p .git/hooks
@rm -f .git/hooks/commit-msg*
ln -s ../../devtools/commit-msg .git/hooks/commit-msg
.PHONY: tag-release
tag-release:
@cur_version=`sed -En 's/.* \|\| echo v([0-9\.]+)\>.*$$/\1/p' meson.build` && \
next_version=`echo $$cur_version | awk -F. -v OFS=. '{$$(NF) += 1; print}'` && \
read -rp "next version ($$next_version)? " n && \
if [ -n "$$n" ]; then next_version="$$n"; fi && \
set -xe && \
sed -i "s/\<v$$cur_version\>/v$$next_version/" meson.build && \
git commit -sm "grout: release v$$next_version" -m "`devtools/git-stats v$$cur_version..`" meson.build && \
git tag -sm "v$$next_version" "v$$next_version"