This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
golang.mk
77 lines (57 loc) · 1.58 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
# Source: https://github.com/rebuy-de/golang-template
# Version: 1.3.1
# Dependencies:
# * Glide
# * gocov (https://github.com/axw/gocov)
# * gocov-html (https://github.com/matm/gocov-html)
NAME=$(notdir $(PACKAGE))
BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' )
BUILD_DATE=$(shell date)
BUILD_HASH=$(shell git rev-parse HEAD)
BUILD_MACHINE=$(shell echo $$HOSTNAME)
BUILD_USER=$(shell whoami)
BUILD_FLAGS=-ldflags "\
-X '$(PACKAGE)/cmd.BuildVersion=$(BUILD_VERSION)' \
-X '$(PACKAGE)/cmd.BuildDate=$(BUILD_DATE)' \
-X '$(PACKAGE)/cmd.BuildHash=$(BUILD_HASH)' \
-X '$(PACKAGE)/cmd.BuildEnvironment=$(BUILD_USER)@$(BUILD_MACHINE)' \
"
GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOPKGS=$(shell go list ./...)
default: build
Gopkg.lock: Gopkg.toml
dep ensure
touch Gopkg.lock
vendor: Gopkg.lock Gopkg.toml
dep ensure
touch vendor
format:
gofmt -s -w $(GOFILES)
vet:
go vet $(GOPKGS)
lint:
$(foreach pkg,$(GOPKGS),golint $(pkg);)
test_gopath:
test $$(go list) = "$(PACKAGE)"
test_packages: vendor
go test $(GOPKGS)
test_format:
gofmt -l $(GOFILES)
test: test_gopath test_format vet lint test_packages
cov:
gocov test -v $(GOPKGS) \
| gocov-html > coverage.html
build: vendor
go build \
$(BUILD_FLAGS) \
-o $(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)
ln -sf $(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH) $(NAME)
xc:
GOOS=linux GOARCH=amd64 make build
GOOS=darwin GOARCH=amd64 make build
install: test
go install \
$(BUILD_FLAGS)
clean:
rm -f $(NAME)*
.PHONY: build install test