-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
75 lines (62 loc) · 2.2 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
ROOT_PACKAGE := github.com/travis-ci/collectd-vsphere
MAIN_PACKAGE := $(ROOT_PACKAGE)/cmd/collectd-vsphere
VERSION_VAR := main.VersionString
VERSION_VALUE ?= $(shell git describe --always --dirty --tags 2>/dev/null)
REV_VAR := main.RevisionString
REV_VALUE ?= $(shell git rev-parse HEAD 2>/dev/null || echo "???")
REV_URL_VAR := main.RevisionURLString
REV_URL_VALUE ?= https://github.com/travis-ci/collectd-vsphere/tree/$(shell git rev-parse HEAD 2>/dev/null || echo "'???'")
GENERATED_VAR := main.GeneratedString
GENERATED_VALUE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%S%z')
COPYRIGHT_VAR := main.CopyrightString
COPYRIGHT_VALUE ?= $(shell grep -i ^copyright LICENSE | sed 's/^[Cc]opyright //')
DOCKER_IMAGE_REPO ?= travisci/collectd-vsphere
DOCKER_DEST ?= $(DOCKER_IMAGE_REPO):$(VERSION_VALUE)
DOCKER ?= docker
GOPATH := $(shell echo $${GOPATH%%:*})
GOBUILD_LDFLAGS ?= \
-X '$(VERSION_VAR)=$(VERSION_VALUE)' \
-X '$(REV_VAR)=$(REV_VALUE)' \
-X '$(REV_URL_VAR)=$(REV_URL_VALUE)' \
-X '$(GENERATED_VAR)=$(GENERATED_VALUE)' \
-X '$(COPYRIGHT_VAR)=$(COPYRIGHT_VALUE)'
.PHONY: all
all: clean test build
.PHONY: clean
clean:
$(RM) $(GOPATH)/bin/collectd-vsphere
$(RM) -rv ./build
find $(GOPATH)/pkg -wholename "*$(ROOT_PACKAGE)*.a" -delete
.PHONY: test
test:
go test $(GOBUILDFLAGS) -v -race -cover \
-coverpkg $(ROOT_PACKAGE) \
-coverprofile coverage.txt \
-covermode=atomic \
$(ROOT_PACKAGE)
.PHONY: build
build: deps
go install $(GOBUILDFLAGS) -ldflags "$(GOBUILD_LDFLAGS)" $(MAIN_PACKAGE)
.PHONY: crossbuild
crossbuild: deps
GOARCH=amd64 GOOS=darwin go build $(GOBUILDFLAGS) -o build/darwin/amd64/collectd-vsphere \
-ldflags "$(GOBUILD_LDFLAGS)" $(MAIN_PACKAGE)
GOARCH=amd64 GOOS=linux go build $(GOBUILDFLAGS) -o build/linux/amd64/collectd-vsphere \
-ldflags "$(GOBUILD_LDFLAGS)" $(MAIN_PACKAGE)
.PHONY: docker-build
docker-build:
$(DOCKER) build -t $(DOCKER_DEST) .
.PHONY: distclean
distclean:
$(RM) vendor/.deps-fetched
.PHONY: deps
deps: vendor/.deps-fetched
.PHONY: prereqs
prereqs:
go get -u github.com/FiloSottile/gvt
.PHONY: copyright
copyright:
sed -i "s/^Copyright.*Travis CI/Copyright © $(shell date +%Y) Travis CI/" LICENSE
vendor/.deps-fetched: vendor/manifest
gvt rebuild
touch $@