-
Notifications
You must be signed in to change notification settings - Fork 0
/
golang.mk
96 lines (75 loc) · 2.35 KB
/
golang.mk
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
TARGET?="./cmd/gotpl-linter"
PACKAGE=$(shell GOPATH= go list $(TARGET))
NAME=$(shell echo $(PACKAGE) | awk -F "/" '{print $$NF}')
BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' )
BUILD_DATE=$(shell LC_ALL=C date)
BUILD_HASH=$(shell git rev-parse HEAD)
#BUILD_XDST=$(NAME)
BUILD_XDST=main
BUILD_FLAGS=-ldflags "\
$(ADDITIONAL_LDFLAGS) -s -w \
-X '$(BUILD_XDST).BuildVersion=$(BUILD_VERSION)' \
-X '$(BUILD_XDST).BuildDate=$(BUILD_DATE)' \
-X '$(BUILD_XDST).BuildHash=$(BUILD_HASH)' \
"
GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GOPKGS=$(shell go list ./cmd/...)
OUTPUT_FILE=$(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOARM)$(shell go env GOEXE)
OUTPUT_LINK=$(NAME)$(shell go env GOEXE)
WINDOWS_ZIP=$(shell echo $(OUTPUT_FILE) | sed 's/\.exe/\.zip/')
default: build
vendor: go.mod go.sum
go mod vendor
touch vendor
format:
gofmt -s -w $(GOFILES)
vet: vendor
go vet $(GOPKGS)
lint:
$(foreach pkg,$(GOPKGS),golint $(pkg);)
test_packages: vendor
go test $(GOPKGS)
test_format:
gofmt -s -l $(GOFILES)
test: test_format vet lint test_packages
cov:
gocov test -v $(GOPKGS) \
| gocov-html > coverage.html
_build: vendor
mkdir -p dist
go build $(BUILD_FLAGS) -o dist/$(OUTPUT_FILE) $(TARGET);
build: _build
$(foreach TARGET,$(TARGETS),ln -sf $(OUTPUT_FILE) dist/$(OUTPUT_LINK);)
compress: _build
tar czf dist/$(OUTPUT_FILE).tar.gz -C dist $(OUTPUT_FILE)
rm -f dist/$(OUTPUT_FILE)
xc:
GOOS=linux GOARCH=amd64 make compress
GOOS=linux GOARCH=arm64 make compress
GOOS=linux GOARCH=arm GOARM=7 make compress
GOOS=darwin GOARCH=amd64 make compress
GOOS=darwin GOARCH=arm64 make compress
GOOS=windows GOARCH=amd64 make compress
xb:
GOOS=linux GOARCH=amd64 make build
GOOS=linux GOARCH=arm64 make build
GOOS=linux GOARCH=arm GOARM=7 make build
GOOS=darwin GOARCH=amd64 make build
GOOS=darwin GOARCH=arm64 make build
GOOS=windows GOARCH=amd64 make build
clean:
rm dist/ -rvf
rm mocks/ -rvf
.PHONY: docker-test
docker-test:
$(DOCKER) build -t gotpl_linter:test -f build/test/Dockerfile .
.PHONY: update-deps
update-deps:
@echo ">> updating Go dependencies"
@for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
go get $$m; \
done
go mod tidy
ifneq (,$(wildcard vendor))
go mod vendor
endif