-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (52 loc) · 2.35 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
PROJECT_NAME=dtx
BIN="bin"
SRC=$(shell find . -name "*.go")
TARGET?=github.com/rajrohanyadav/dtx
BINARY ?= ${PROJECT_NAME}
VERSION = 0.0.1
COMMIT = $(shell git rev-parse --short=7 HEAD)
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
LDFLAGS = -ldflags "-X main.VERSION=${VERSION} -X main.commit=${COMMIT} -X main.BRANCH=${BRANCH} -X main.BUILD_NUMBER=${BUILD_NUMBER}"
ifeq (, $(shell which golangci-lint))
$(warning "could not find golangci-lint in $(PATH), run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh")
endif
.PHONY: all build fmt vet lint test install_deps clean
default: all
all: vet fmt test build
build: clean windows darwin linux
linux: install_deps
$(info ******************** building for linux amd64 ********************)
@GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o $(BIN)/${BINARY}-linux-amd64 ${TARGET};
$(info ******************** building for linux arm64 ********************)
@GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o $(BIN)/${BINARY}-linux-arm64 ${TARGET};
darwin: install_deps
$(info ******************** building for darwin amd64 ********************)
@GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o $(BIN)/${BINARY}-darwin-amd64 ${TARGET};
$(info ******************** building for darwin arm64 ********************)
@GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o $(BIN)/${BINARY}-darwin-arm64 ${TARGET};
windows: install_deps
$(info ******************** building for windows ********************)
@GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o $(BIN)/${BINARY}-windows.exe ${TARGET};
fmt:
$(info ******************** checking formatting ********************)
go fmt $$(go list ./... | grep -v /vendor/);
goimports -local github.com/golangci/golangci-lint -w $$(find . -type f -iname \*.go)
lint:
$(info ******************** running lint tools ********************)
golangci-lint run -v
vet:
$(info ******************** vetting ********************)
go vet $$(go list ./... | grep -v /vendor/)
test: install_deps
$(info ******************** running tests ********************)
go clean -testcache
go test -v ./...
test-coverage:
$(info ******************** running tests with coverage ********************)
go clean -testcache
go test ./... -cover
install_deps:
$(info ******************** downloading dependencies ********************)
go get -v ./...
clean:
rm -rf $(BIN)