forked from rebuy-de/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
golang.mk
84 lines (63 loc) · 1.85 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
# Source: https://github.com/rebuy-de/golang-template
TARGETS?="."
PACKAGE=$(shell GOPATH= go list $(TARGET))
NAME=$(notdir $(PACKAGE))
BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' )
BUILD_DATE=$(shell LC_ALL=C date)
BUILD_HASH=$(shell git rev-parse HEAD)
BUILD_MACHINE=$(shell echo $$HOSTNAME)
BUILD_USER=$(shell whoami)
BUILD_ENVIRONMENT=$(BUILD_USER)@$(BUILD_MACHINE)
BUILD_XDST=$(PACKAGE)/cmd
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)' \
-X '$(BUILD_XDST).BuildEnvironment=$(BUILD_ENVIRONMENT)' \
"
GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GOPKGS=$(shell go list ./...)
OUTPUT_FILE=$(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOEXE)
OUTPUT_LINK=$(NAME)$(shell go env GOEXE)
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);)
go_generate:
rm -rvf mocks
go generate ./...
test_packages: vendor
go test $(GOPKGS)
test_format:
gofmt -s -l $(GOFILES)
test: test_format go_generate vet lint test_packages
cov: go_generate
gocov test -v $(GOPKGS) \
| gocov-html > coverage.html
_build: vendor
mkdir -p dist
$(foreach TARGET,$(TARGETS),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 dist/$(OUTPUT_FILE)
xc:
GOOS=linux GOARCH=amd64 make compress
GOOS=darwin GOARCH=amd64 make compress
install: vendor test
$(foreach TARGET,$(TARGETS),go install \
$(BUILD_FLAGS);)
clean:
rm dist/ -rvf
rm mocks/ -rvf