forked from jo-m/trainbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (120 loc) · 4.66 KB
/
Makefile
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
.PHONY: format lint test test_more bench check build_host 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:bullseye-20240701
# https://go.dev/dl/
GO_VERSION = 1.22.5
GO_ARCHIVE_SHA256 = 904b924d435eaea086515bc63235b192ea441bd8c9b198c507e85009e6e4c7f0
# https://github.com/dominikh/go-tools/releases
GO_STATICCHECK_VERSION = 2023.1.7
DEFAULT: format build_host build_arm64
format:
bash -c "shopt -s globstar; clang-format -i **/*.c **/*.h"
gofmt -w .
go mod tidy
lint:
bash -c "shopt -s globstar; clang-format --dry-run --Werror **/*.c **/*.h"
gofmt -l .; test -z "$$(gofmt -l .)"
go vet ./...
go run honnef.co/go/tools/cmd/staticcheck@$(GO_STATICCHECK_VERSION) -checks=all ./...
go run github.com/mgechev/revive@latest -set_exit_status ./...
go run github.com/securego/gosec/v2/cmd/gosec@latest -exclude G307 ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
test:
go test -v ./...
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
# unzip -d internal/pkg/stitch/testdata internal/pkg/stitch/testdata/more-testdata.zip
go test -v --tags=moretests -timeout=30m -run Test_AutoStitcher_Set ./...
bench:
go test -v -run=Nothing -bench=Benchmark_ ./...
check: lint test bench
build_host: export CGO_ENABLED=1
build_host: export CC=gcc
build_host:
mkdir -p build
go build -o build/trainbot ./cmd/trainbot
go build -o build/confighelper ./cmd/confighelper
go build -o build/pmatch ./examples/pmatch
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 -o build/trainbot-arm64 ./cmd/trainbot
go build -o build/confighelper-arm64 ./cmd/confighelper
go build -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_FLAGS += --build-arg GO_STATICCHECK_VERSION="$(GO_STATICCHECK_VERSION)"
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
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 -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 [email protected]
deploy_trainbot: docker_build
test -n "$(host)" # missing target host, usage: make deploy_trainbot host=TRAINBOT_DEPLOY_TARGET_SSH_HOST !
ssh $(host) mkdir -p trainbot/
scp env $(host):trainbot/
ssh $(host) mkdir -p .config/systemd/user/
scp trainbot.service $(host):.config/systemd/user/
ssh $(host) systemctl --user stop trainbot.service
scp build/trainbot-arm64 $(host):trainbot/
ssh $(host) loginctl enable-linger
ssh $(host) systemctl --user enable trainbot.service
ssh $(host) systemctl --user start trainbot.service
# Usage: make deploy_confighelper host=TRAINBOT_DEPLOY_TARGET_SSH_HOST
# Example: make deploy_confighelper [email protected]
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/
scp build/confighelper-arm64 $(host):trainbot/
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 '^$@$$'