forked from viamrobotics/rdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (106 loc) · 4.57 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
BIN_OUTPUT_PATH = bin/$(shell uname -s)-$(shell uname -m)
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
BUILD_CHANNEL ?= local
PATH_WITH_TOOLS="`pwd`/$(TOOL_BIN):`pwd`/node_modules/.bin:${PATH}"
GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
TAG_VERSION?=$(shell git tag --points-at | sort -Vr | head -n1)
DATE_COMPILED?=$(shell date +'%Y-%m-%d')
COMMON_LDFLAGS = -s -w -X 'go.viam.com/rdk/config.Version=${TAG_VERSION}' -X 'go.viam.com/rdk/config.GitRevision=${GIT_REVISION}' -X 'go.viam.com/rdk/config.DateCompiled=${DATE_COMPILED}'
LDFLAGS = -ldflags "-extld=$(shell pwd)/etc/ld_wrapper.sh $(COMMON_LDFLAGS)"
default: build lint server
setup:
bash etc/setup.sh
build: build-web build-go
build-go:
go build ./...
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
bin/$(GOOS)-$(GOARCH)/viam-cli:
go build $(LDFLAGS) -tags osusergo,netgo -o $@ ./cli/viam
.PHONY: cli
cli: bin/$(GOOS)-$(GOARCH)/viam-cli
.PHONY: cli-ci
cli-ci: bin/$(GOOS)-$(GOARCH)/viam-cli
if [ -n "$(CI_RELEASE)" ]; then \
mkdir -p bin/deploy-ci/; \
cp $< bin/deploy-ci/viam-cli-$(CI_RELEASE)-$(GOOS)-$(GOARCH)$(EXE_SUFFIX); \
fi
build-web: web/runtime-shared/static/control.js
# only generate static files when source has changed.
web/runtime-shared/static/control.js: web/frontend/src/*/* web/frontend/src/*/*/* web/frontend/src/*.* web/frontend/scripts/* web/frontend/*.*
rm -rf web/runtime-shared/static
npm ci --audit=false --prefix web/frontend
npm run build-prod --prefix web/frontend
tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
github.com/edaniels/golinters/cmd/combined \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/AlekSi/gocov-xml \
github.com/axw/gocov/gocov \
gotest.tools/gotestsum \
github.com/rhysd/actionlint/cmd/actionlint \
golang.org/x/tools/cmd/stringer
lint: lint-go lint-web
PATH=$(PATH_WITH_TOOLS) actionlint
generate-go: tool-install
PATH=$(PATH_WITH_TOOLS) go generate ./...
lint-go: tool-install
go mod tidy
export pkgs="`go list -f '{{.Dir}}' ./... | grep -v /proto/`" && echo "$$pkgs" | xargs go vet -vettool=$(TOOL_BIN)/combined
GOGC=50 $(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml
lint-web: check-web
npm run lint --prefix web/frontend
check-web: build-web
npm run check --prefix web/frontend
cover-only: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh cover
cover: test-go cover-only
test: test-go test-web
test-no-race: test-go-no-race test-web
test-go: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh race
test-go-no-race: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh
test-web:
npm run test:unit --prefix web/frontend
test-e2e:
go build $(LDFLAGS) -o bin/test-e2e/server web/cmd/server/main.go
./etc/e2e.sh -o 'run' $(E2E_ARGS)
open-cypress-ui:
go build $(LDFLAGS) -o bin/test-e2e/server web/cmd/server/main.go
./etc/e2e.sh -o 'open'
server: build-web
rm -f $(BIN_OUTPUT_PATH)/viam-server
go build $(LDFLAGS) -o $(BIN_OUTPUT_PATH)/viam-server web/cmd/server/main.go
server-static: build-web
rm -f $(BIN_OUTPUT_PATH)/viam-server
VIAM_STATIC_BUILD=1 GOFLAGS=$(GOFLAGS) go build $(LDFLAGS) -o $(BIN_OUTPUT_PATH)/viam-server web/cmd/server/main.go
full-static: build-web
mkdir -p bin/static
go build -tags no_cgo,osusergo,netgo -ldflags="-extldflags=-static $(COMMON_LDFLAGS)" -o bin/static/viam-server-$(shell go env GOARCH) ./web/cmd/server
server-static-compressed: server-static
upx --best --lzma $(BIN_OUTPUT_PATH)/viam-server
clean-all:
git clean -fxd
license-check:
license_finder --npm-options='--prefix web/frontend'
FFMPEG_ROOT ?= etc/FFmpeg
$(FFMPEG_ROOT):
cd etc && git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch release/6.1
# For ARM64 builds, use the image ghcr.io/viamrobotics/antique:arm64 for backward compatibility
FFMPEG_PREFIX ?= $(shell realpath .)/gostream/ffmpeg/$(shell uname -s)-$(shell uname -m)
# See compilation guide here https://trac.ffmpeg.org/wiki/CompilationGuide
FFMPEG_OPTS = --disable-programs --disable-doc --disable-everything --prefix=$(FFMPEG_PREFIX) --disable-autodetect --disable-x86asm
ifeq ($(shell uname -m),aarch64)
# We only support hardware encoding on a Raspberry Pi.
FFMPEG_OPTS += --enable-encoder=h264_v4l2m2m
FFMPEG_OPTS += --enable-v4l2-m2m
endif
ffmpeg: $(FFMPEG_ROOT)
cd $(FFMPEG_ROOT) && ($(MAKE) distclean || true)
cd $(FFMPEG_ROOT) && ./configure $(FFMPEG_OPTS)
cd $(FFMPEG_ROOT) && $(MAKE)
cd $(FFMPEG_ROOT) && $(MAKE) install
# Only keep archive files. Different architectures can share the same source files.
find $(FFMPEG_PREFIX)/* -type d ! -wholename $(FFMPEG_PREFIX)/lib | xargs rm -rf
include *.make