-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
169 lines (137 loc) · 4.34 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
GO_VERSION_REQUIRED:=1.13
# Inspired by github.com/influxdata/telegraf
ifeq ($(OS), Windows_NT)
VERSION := $(shell git describe --exact-match --tags 2>nil)
HOME := $(HOMEPATH)
CGO_ENABLED ?= 0
export CGO_ENABLED
else
VERSION := $(shell git describe --exact-match --tags 2>/dev/null)
endif
PREFIX := /usr/local
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git rev-parse --short HEAD)
GOFILES ?= $(shell git ls-files '*.go')
GOFMT ?= $(shell gofmt -l -s $(GOFILES))
BUILDFLAGS ?=
ifdef GOBIN
PATH := $(GOBIN):$(PATH)
else
PATH := $(subst :,/bin:,$(shell go env GOPATH))/bin:$(PATH)
endif
# --Inspired by https://github.com/istio/istio/blob/master/Makefile.core.mk
# Parse out the x.y or x.y.z version and output a single value x*10000+y*100+z (e.g., 1.9 is 10900)
# that allows the three components to be checked in a single comparison.
VER_TO_INT:=awk '{split(substr($$0, match ($$0, /[0-9\.]+/)), a, "."); print a[1]*10000+a[2]*100+a[3]}'
check-go-version:
@if test $(shell go version | $(VER_TO_INT) ) -lt \
$(shell echo "$(GO_VERSION_REQUIRED)" | $(VER_TO_INT) ); \
then printf "go version $(GO_VERSION_REQUIRED)+ required, found: "; go version; exit 1; fi
LDFLAGS := $(LDFLAGS) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)
ifdef VERSION
LDFLAGS += -X main.version=$(VERSION)
endif
.PHONY: all
all:
@$(MAKE) --no-print-directory deps
@$(MAKE) --no-print-directory hc2
.PHONY: deps
deps: check-go-version
go mod vendor
.PHONY: hc2
hc2:
go build -ldflags "$(LDFLAGS)" ./cmd/hc2UploadScene
go build -ldflags "$(LDFLAGS)" ./cmd/hc2DownloadScene
go build -ldflags "$(LDFLAGS)" ./cmd/hc2SceneInteract
go build -ldflags "$(LDFLAGS)" ./cmd/hc2Tools
.PHONY: go-install
go-install:
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/hc2UploadScene
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/hc2DownloadScene
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/hc2SceneInteract
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/hc2Tools
.PHONY: install
install: hc2
mkdir -p $(DESTDIR)$(PREFIX)/bin/
cp hc2UploadScene $(DESTDIR)$(PREFIX)/bin/
cp hc2DownloadScene $(DESTDIR)$(PREFIX)/bin/
cp hc2SceneInteract $(DESTDIR)$(PREFIX)/bin/
cp hc2Tools $(DESTDIR)$(PREFIX)/bin/
.PHONY: test
test:
go test -short ./...
.PHONY: fmt
fmt:
@gofmt -s -w $(GOFILES)
.PHONY: fmtcheck
fmtcheck:
@if [ ! -z "$(GOFMT)" ]; then \
echo "[ERROR] gofmt has found errors in the following files:" ; \
echo "$(GOFMT)" ; \
echo "" ;\
echo "Run make fmt to fix them." ; \
exit 1 ;\
fi
.PHONY: vet
vet:
@echo 'go vet $$(go list ./...)'
@go vet $$(go list ./...) ; if [ $$? -ne 0 ]; then \
echo ""; \
echo "go vet has found suspicious constructs. Please remediate any reported errors"; \
echo "to fix them before submitting code for review."; \
exit 1; \
fi
.PHONY: check
check: fmtcheck vet
.PHONY: test-all
test-all: fmtcheck vet
go test ./...
.PHONY: package
package:
./scripts/build.py --package --platform=all --arch=all
.PHONY: package-release
package-release:
./scripts/build.py --release --package --platform=all --arch=all
.PHONY: package-nightly
package-nightly:
./scripts/build.py --nightly --package --platform=all --arch=all
.PHONY: clean
clean:
rm -f $(GOPATH)/bin/hc2UploadScene
rm -f $(GOPATH)/bin/hc2UploadScene.exe
rm -f $(GOPATH)/bin/hc2DownloadScene
rm -f $(GOPATH)/bin/hc2DownloadScene.exe
rm -f $(GOPATH)/bin/hc2SceneInteract
rm -f $(GOPATH)/bin/hc2SceneInteract.exe
rm -f $(GOPATH)/bin/hc2Tools
rm -f $(GOPATH)/bin/hc2Tools.exe
rm -f ./hc2UploadScene
rm -f ./hc2DownloadScene
rm -f ./hc2SceneInteract
rm -f $(DESTDIR)$(PREFIX)/bin/hc2UploadScene
rm -f $(DESTDIR)$(PREFIX)/bin/hc2DownloadScene
rm -f $(DESTDIR)$(PREFIX)/bin/hc2SceneInteract
rm -f ./hc2Tools
.PHONY: docker-image
.PHONY: static
static:
@echo "Building static linux binary hc2UploadScene"
@CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" ./cmd/hc2UploadScene
@echo "Building static linux binary hc2DownloadScene"
@CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" ./cmd/hc2DownloadScene
@echo "Building static linux binary hc2SceneInteract"
@CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" ./cmd/hc2SceneInteract
@echo "Building static linux binary hc2Tools"
@CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" ./cmd/hcTools