Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
190 lines (154 loc) · 6.18 KB
/
Copy pathMakefile
File metadata and controls
190 lines (154 loc) · 6.18 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
.PHONY: format lint test test_vk test_more bench bench_vk check build_host build_host_vk build_arm64 docker_build docker_lint docker_test docker_test_more docker_bench clean run_confighelper run_camera run_videofile list
# https://hub.docker.com/_/debian
DOCKER_BASE_IMAGE = debian:bookworm-20260610
# https://go.dev/dl/
GO_VERSION = 1.26.4
GO_ARCHIVE_SHA256 = 1153d3d50e0ac764b447adfe05c2bcf08e889d42a02e0fe0259bd47f6733ad7f
DEFAULT: format build_host build_arm64
GO_BUILD_TAGS =
format:
bash -c "shopt -s globstar; clang-format -i **/*.c **/*.h **/*.comp"
gofmt -w .
go mod tidy
lint:
bash -c "shopt -s globstar; clang-format --dry-run --Werror **/*.c **/*.h **/*.comp"
gofmt -l .; test -z "$$(gofmt -l .)"
go vet ./...
go tool staticcheck -checks=all ./...
go tool revive -set_exit_status ./...
# G307: Poor file permissions used when creating a file with os.Create
# G115: Type conversion which leads to integer overflow
go tool gosec -exclude G307,G115 ./...
go tool govulncheck ./...
generate:
go generate --tags=$(GO_BUILD_TAGS) ./...
test: generate
go test -v --tags=$(GO_BUILD_TAGS) ./...
test_vk: GO_BUILD_TAGS = vk
test_vk: test
test_more: GO_BUILD_TAGS = moretests
test_more:
# This needs additional test data which is not committed to the repo.
# Instructions:
# curl -o internal/pkg/stitch/testdata/more-testdata.zip https://trains.jo-m.ch/testdata.zip
# (cd internal/pkg/stitch/testdata/ && sha256sum --check more-testdata.zip.sha256)
# unzip -d internal/pkg/stitch/testdata internal/pkg/stitch/testdata/more-testdata.zip
go test -v --tags=$(GO_BUILD_TAGS) -timeout=30m -run Test_AutoStitcher_Set ./...
bench:
go test -v --tags=$(GO_BUILD_TAGS) -run=Nothing -bench=Benchmark_ ./...
bench_vk: GO_BUILD_TAGS = vk
bench_vk: bench
check: lint test bench
build_host: export CGO_ENABLED=1
build_host: export CC=gcc
build_host:
mkdir -p build
go build --tags=$(GO_BUILD_TAGS) -o build/trainbot ./cmd/trainbot
go build --tags=$(GO_BUILD_TAGS) -o build/confighelper ./cmd/confighelper
go build --tags=$(GO_BUILD_TAGS) -o build/pmatch ./examples/pmatch
build_host_vk: GO_BUILD_TAGS = vk
build_host_vk: generate build_host
build_host_vk:
go build --tags=$(GO_BUILD_TAGS) -o build/pmatchVk ./examples/pmatchVk
TRAINBOT_AARCH_CROSS ?= aarch64-linux-gnu-gcc
build_arm64: export CGO_ENABLED=1
build_arm64: export CC=$(TRAINBOT_AARCH_CROSS)
build_arm64: export GOOS=linux
build_arm64: export GOARCH=arm64
build_arm64: export GOARM=7
build_arm64:
mkdir -p build
go build --tags=$(GO_BUILD_TAGS) -o build/trainbot-arm64 ./cmd/trainbot
go build --tags=$(GO_BUILD_TAGS) -o build/confighelper-arm64 ./cmd/confighelper
go build --tags=$(GO_BUILD_TAGS) -o build/pmatch-arm64 ./examples/pmatch
DOCKER_FLAGS = $(DOCKER_CLI_FLAGS)
DOCKER_FLAGS += --build-arg DOCKER_BASE_IMAGE="$(DOCKER_BASE_IMAGE)"
DOCKER_FLAGS += --build-arg GO_VERSION="$(GO_VERSION)"
DOCKER_FLAGS += --build-arg GO_ARCHIVE_SHA256="$(GO_ARCHIVE_SHA256)"
docker_image:
docker buildx build $(DOCKER_FLAGS) \
--target=source \
--load \
--tag trainbot-source:latest \
.
docker_build:
docker buildx build $(DOCKER_FLAGS) \
--target=export \
--output=build \
.
docker_lint:
docker buildx build $(DOCKER_FLAGS) \
--target=lint \
.
docker_test:
docker buildx build $(DOCKER_FLAGS) \
--target=test \
.
docker_test_more:
docker buildx build $(DOCKER_FLAGS) \
--target=test_more \
.
docker_bench:
docker buildx build $(DOCKER_FLAGS) \
--target=bench \
.
clean:
rm -rf build/
rm -f prof-*.gz
find . -name '*.spv' -delete
run_confighelper:
go run ./cmd/confighelper/ --input /dev/video2 --live-reload
run_camera:
go run ./cmd/trainbot \
--log-pretty \
\
--enable-upload=false \
--input /dev/video2 \
--camera-format-fourcc MJPG \
--camera-w 1920 --camera-h 1080 \
-X 1064 -Y 178 -W 366 -H 334
run_videofile:
go build --tags=$(GO_BUILD_TAGS) -o build/trainbot ./cmd/trainbot/
./build/trainbot \
--log-pretty \
--log-level=info \
\
--enable-upload=false \
--input="internal/pkg/stitch/testdata/set0/day.mp4" \
-X 0 -Y 0 -W 300 -H 300
# Usage: make deploy_trainbot host=$TRAINBOT_DEPLOY_TARGET_SSH_HOST
# Example: make deploy_trainbot host=pi@10.20.0.12
deploy_trainbot: rust_build_arm64
test -n "$(host)" # missing target host, usage: make deploy_trainbot host=TRAINBOT_DEPLOY_TARGET_SSH_HOST !
ssh $(host) mkdir -p trainbot/
rsync env $(host):trainbot/
ssh $(host) mkdir -p .config/systemd/user/
rsync trainbot.service $(host):.config/systemd/user/
rsync trainbot-rsync-uploader.service $(host):.config/systemd/user/
ssh $(host) systemctl --user stop trainbot.service
ssh $(host) systemctl --user stop trainbot-rsync-uploader.service
#ssh $(host) sudo apt-get install -y inotify-tools
rsync target/aarch64-unknown-linux-gnu/release/trainbot $(host):trainbot/trainbot-arm64
rsync ./rsync-uploader $(host):trainbot/
ssh $(host) loginctl enable-linger
ssh $(host) systemctl --user enable --now trainbot.service
ssh $(host) systemctl --user enable --now trainbot-rsync-uploader.service
# Usage: make deploy_confighelper host=TRAINBOT_DEPLOY_TARGET_SSH_HOST
# Example: make deploy_confighelper host=pi@10.20.0.12
deploy_confighelper: docker_build
test -n "$(host)" # missing target host, usage: make deploy_confighelper host=TRAINBOT_DEPLOY_TARGET_SSH_HOST !
ssh $(host) mkdir -p trainbot/
rsync build/confighelper-arm64 $(host):trainbot/
rust_check:
cargo test --release
cargo clippy
cargo clippy --tests
cargo fmt --check
rust_build_arm64:
rustup target add aarch64-unknown-linux-gnu
# target-cpu=generic seems same or slightly faster compared to cortex-a72
RUSTFLAGS='-C target-feature=+crt-static -C linker=aarch64-linux-gnu-gcc' cargo build --release --target=aarch64-unknown-linux-gnu
rust_perf:
samply record target/release/trainbot --input internal/pkg/stitch/testdata/set0/day.mp4 -X 0 -Y 0 -W 300 -H 300
list:
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'