-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
111 lines (87 loc) · 2.63 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
# gcoreclient Makefile
PWD := $(shell pwd)
BASE_DIR := $(shell basename $(PWD))
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
export GO111MODULE := on
TESTARGS_DEFAULT := -v -race
TESTARGS ?= $(TESTARGS_DEFAULT)
PKG := $(shell awk '/^module/ { print $$2 }' go.mod)
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
SOURCES := $(shell find $(DEST) -name '*.go' 2>/dev/null)
HAS_GOLANGCI := $(shell command -v golangci-lint;)
HAS_GOIMPORTS := $(shell command -v goimports;)
TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x
DIST_DIRS = find * -type d -exec
TEMP_DIR :=$(shell mktemp -d)
GOOS ?= $(shell go env GOOS)
VERSION ?= $(shell git describe --tags 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
GOARCH ?= $(shell go env GOARCH)
TAGS :=
LDFLAGS := "-w -s -X 'github.com/G-Core/gcorelabscloud-go/gcorecloud.AppVersion=${VERSION}' -X 'github.com/G-Core/gcorelabscloud-go/cmd.AppVersion=${VERSION}'"
CMD_PACKAGE := ./cmd/gcoreclient
BINARY := ./gcoreclient
# CTI targets
$(GOBIN):
echo "create gobin"
mkdir -p $(GOBIN)
work: $(GOBIN)
build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags $(LDFLAGS) \
-o $(BINARY) \
$(CMD_PACKAGE)
install:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go install \
-ldflags $(LDFLAGS) \
$(CMD_PACKAGE)
test: unit functional
check: work fmt vet goimports golangci
unit: work
go test -count=1 -v $(TESTARGS) ./...
functional:
@echo "$@ not yet implemented"
fmt:
go fmt ./...
goimports:
ifndef HAS_GOIMPORTS
echo "installing goimports"
GO111MODULE=off go get golang.org/x/tools/cmd/goimports
endif
goimports -d $(shell find . -iname "*.go")
vet:
go vet ./...
linters:
golangci-lint run ./...
cover: work
go test $(TESTARGS) -tags=unit -cover -coverpkg=./ ./...
prepare:
ifndef HAS_GOLANGCI
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
endif
echo "golangci-lint already installed"
ifndef HAS_GOIMPORTS
echo "installing goimports"
GO111MODULE=off go get golang.org/x/tools/cmd/goimports
endif
echo "goimports already installed"
env:
@echo "PWD: $(PWD)"
@echo "BASE_DIR: $(BASE_DIR)"
@echo "GOPATH: $(GOPATH)"
@echo "GOROOT: $(GOROOT)"
@echo "DEST: $(DEST)"
@echo "PKG: $(PKG)"
go version
go env
shell:
$(SHELL) -i
clean: work
rm -rf $(BINARY)
version:
@echo ${VERSION}
.PHONY: bindep install build cover work fmt functional test version clean prepare