Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·219 lines (171 loc) · 7.49 KB
/
Copy pathMakefile
File metadata and controls
executable file
·219 lines (171 loc) · 7.49 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
#
# Makefile for all UNIX style platforms including Cygwin
#
# (C) 2009-2026, Kees Verruijt, Harlingen, The Netherlands
#
# $Id:$
#
# s. https://www.gnu.org/prep/standards/html_node/Directory-Variables.html#Directory-Variables
DESTDIR ?= ""
PREFIX ?= /usr/local
EXEC_PREFIX ?= $(PREFIX)
BINDIR=$(EXEC_PREFIX)/bin
DATAROOTDIR ?= $(PREFIX)/share
MANDIR= $(DATAROOTDIR)/man
PLATFORM ?= $(shell uname | tr '[A-Z]' '[a-z]')-$(shell uname -m)
SUBDIRS= actisense-serial analyzer nmea0183 ip group-function candump2analyzer socketcan-writer socketcan-serial ikonvert-serial maretron-ipg replay
BUILDDIR ?= ./rel/$(PLATFORM)
MKDIR = mkdir -p
export HELP2MAN=$(shell command -v help2man 2> /dev/null)
ROOT_UID=0
ROOT_GID=0
ROOT_MOD=0644
EXEC_MOD=0755
all: bin compile
@echo "The binaries are now built and are in $(BUILDDIR)"
@echo "Use 'make generated' to recreate generated XML, HTML, JSON and DBC files."
compile: bin
for dir in $(SUBDIRS); do $(MAKE) -C $$dir || exit 1; done
tests: compile
$(MAKE) -C analyzer tests
$(MAKE) -C actisense-serial/tests tests
$(MAKE) -C candump2analyzer/tests tests
# The Cargo workspace at the repo root (crates/*, keel/) is deliberately
# OPT-IN and is NOT a dependency of all/compile/tests: a plain `make` of the C
# tools must never invoke cargo, so C-only contributors and packagers need no
# Rust toolchain. Rust contributors just use
# cargo directly; these targets exist so `make` users have the same shortcuts.
CARGO ?= cargo
# The Rust schema tables are generated from database/ by keel and committed,
# so a `cargo build` alone will happily compile
# against a stale table after a database edit. Regenerate first.
#
# Deliberately NOT a dependency on `generated`: that additionally produces
# canboat.html/json via xsltproc, validates with xmllint, runs the C golden
# tests and builds the DBC exporter, so it needs xsltproc, libxml2-utils,
# python3 + venv and a C compiler. None of that is required to build the
# Rust side, and demanding it would make `make rust` unusable on a machine
# that only has a Rust toolchain.
#
# keel/keel is self-contained: it builds keel with cargo, or downloads a
# prebuilt binary when there is no toolchain. It writes only the artifacts
# whose content actually changed, so this does not disturb the C build.
.PHONY: keel-generate
keel-generate:
@keel/keel generate
rust: keel-generate
$(CARGO) build --release --workspace
rust-debug: keel-generate
$(CARGO) build --workspace
rust-tests: keel-generate
$(CARGO) test --workspace
rust-clippy:
$(CARGO) clippy --workspace --all-targets -- -D warnings
# The library feature sets a consumer can pick without the CLI, each of which
# must build warning-free on its own. The default (cli) build enables
# everything, so it cannot catch a `#[cfg(feature = …)]` gate that leaves
# a smaller set with a dangling `use` or an unreachable helper — only
# building the smaller sets does. `cli` alone is the binary without `mdns`.
# Kept in step with scripts/check-public-api.sh.
RUST_LIB_FEATURESETS = decode raw raw-usb io usb node bridge mdns json-input nmea0183,ais decode,io,node,bridge,nmea0183,ais,json-input cli
rust-features:
@for set in $(RUST_LIB_FEATURESETS); do \
echo "==> canboat --no-default-features --features $$set"; \
$(CARGO) clippy -p canboat --no-default-features --features $$set -- -D warnings || exit 1; \
done
rust-fmt:
$(CARGO) fmt --all
# The facade's public API against crates/doc/public-api/. Needs nightly and
# cargo-public-api; without them it says so and carries on, since CI's
# public-api job runs the same check.
rust-public-api:
@scripts/check-public-api.sh; status=$$?; \
if [ $$status -eq 127 ]; then \
echo "rust-public-api: SKIPPED (no nightly toolchain or cargo-public-api)"; \
elif [ $$status -ne 0 ]; then \
exit $$status; \
fi
# Everything worth having green before opening a PR that touches Rust.
rust-precommit: rust-fmt rust-clippy rust-features rust-tests rust-public-api
rust-clean:
$(CARGO) clean
# Regenerate FIRST, then test against the fresh output. keel (run inside
# `analyzer generated`) rewrites the C data tables and canboat.xml from the
# database; only afterwards do we rebuild the analyzer from those fresh
# headers and run the golden-file suite. Running tests before regeneration
# would validate the stale committed tables and never exercise the new output.
generated: markdown-docs
$(MAKE) -C analyzer generated
$(MAKE) tests
$(MAKE) -C dbc-exporter
# Run before opening a PR: regenerates the database, then reports how this
# change affects the public contract (breaking / minor / additive) and what
# conventional-commit level it needs. Advisory only; CI enforces the same
# check via tools/contract-pr.sh --gate.
pr: generated
@tools/contract-pr.sh
# The GitHub Pages site in docs/: doc/*.md (the guides; doc/c/ for the C
# programs, as docs/c/) and research/*.md (the explanation documents) ->
# docs/*.html, via a portable, dependency-free converter (Python 3 standard
# library only). docs/index.html, which links them all, is written by hand.
# doc/ and research/ share docs/, so a name may be in only one of them.
DOC_MD := $(wildcard doc/*.md doc/c/*.md)
RESEARCH_MD := $(wildcard research/*.md)
$(if $(filter $(notdir $(DOC_MD)),$(notdir $(RESEARCH_MD))),$(error doc/ and research/ both have $(filter $(notdir $(DOC_MD)),$(notdir $(RESEARCH_MD)))))
MARKDOWN_HTML := $(patsubst doc/%.md,docs/%.html,$(DOC_MD)) $(patsubst research/%.md,docs/%.html,$(RESEARCH_MD))
docs/%.html: doc/%.md tools/md2html.py
@mkdir -p $(dir $@)
python3 tools/md2html.py $< -o $@
docs/%.html: research/%.md tools/md2html.py
python3 tools/md2html.py $< -o $@
markdown-docs: $(MARKDOWN_HTML)
@echo "Markdown docs generated: $(MARKDOWN_HTML)"
research-docs: markdown-docs
# Builder image can be removed with `docker image rm canboat-builder`
docker-build: ## runs `make clean generated` in `ubuntu:22.04` Docker image
@docker build -t canboat-builder .
@docker run -it --rm -v $(shell pwd):/project canboat-builder clean generated
bin: $(BUILDDIR)
CYGWIN_DLL=$(BUILDDIR)/cygwin1.dll
$(CYGWIN_DLL): $(BUILDDIR)
cp /usr/bin/cygwin1.dll $(CYGWIN_DLL)
CYGWIN=$(findstring cygwin,$(PLATFORM))
ifneq (,$(CYGWIN))
bin: $(CYGWIN_DLL)
@echo "Building in $(BUILDDIR) for '$(CYGWIN)' with $(CYGWIN_DLL)"
else
bin:
@echo "Building in $(BUILDDIR)"
endif
$(BUILDDIR):
$(MKDIR) $(BUILDDIR)
man1: man/man1
man/man1:
$(MKDIR) man/man1
clean:
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean || exit 1; done
$(MAKE) -C dbc-exporter clean
-rm -R -f man $(BUILDDIR)
install: $(BUILDDIR)/analyzer $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
for i in $(BUILDDIR)/* util/*; do install -m $(EXEC_MOD) -b $$i $(DESTDIR)$(BINDIR) || exit 1; done
ifeq ($(notdir $(HELP2MAN)),help2man)
for i in man/man1/*; do echo $$i; install -m $(ROOT_MOD) $$i $(DESTDIR)$(MANDIR)/man1 || exit 1; done
endif
format:
for file in */*.c */*.h; do clang-format -i $$file; done
release:
$(MAKE) clean generated
git diff --exit-code
git tag v`sed -En 's/.*\ VERSION\ \"([0-9]+\.)([0-9]+\.)?([0-9]+)\"/\1\2\3/p' common/version.h`
git push --tags
copyright:
$(MAKE) clean
rm -rf rel/
./util/update-copyright.sh
aarch64-linux-musl:
./cross-compile.sh aarch64-linux-musl
.PHONY : $(SUBDIRS) clean install zip bin format man1 tests generated markdown-docs research-docs compile copyright aarch64-linux-musl openwrt pr rust rust-debug rust-tests rust-clippy rust-features rust-fmt rust-public-api rust-precommit rust-clean keel-generate
$(DESTDIR)$(BINDIR):
$(MKDIR) $(DESTDIR)$(BINDIR)
$(DESTDIR)$(MANDIR)/man1:
$(MKDIR) $(DESTDIR)$(MANDIR)/man1