This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
81 lines (65 loc) · 2.31 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
BIN := tpm
PKG := github.com/nrocco/tpm
VERSION := $(shell git describe --tags --always --dirty)
COMMIT := $(shell git describe --always --dirty)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
PKG_LIST := $(shell go list ${PKG}/... | grep -v ${PKG}/vendor/)
GO_FILES := $(shell git ls-files '*.go')
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
LDFLAGS = "-d -s -w -X ${PKG}/cmd.version=${VERSION} -X ${PKG}/cmd.commit=${COMMIT} -X ${PKG}/cmd.buildDate=${DATE} -X ${PKG}/pkg/client.Version=${VERSION}"
BUILD_ARGS = -a -tags netgo -installsuffix netgo -ldflags $(LDFLAGS)
PREFIX = /usr
.DEFAULT_GOAL: build
build/${BIN}-$(GOOS)-$(GOARCH): $(GO_FILES)
mkdir -p build
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build ${BUILD_ARGS} -o $@ ${PKG}
.PHONY: deps
deps:
dep ensure
.PHONY: lint
lint:
golint -set_exit_status ${PKG_LIST}
.PHONY: vet
vet:
go vet -v ${PKG_LIST}
.PHONY: test
test:
go test -short ${PKG_LIST}
.PHONY: coverage
coverage:
mkdir -p coverage && rm -rf coverage/*
for package in ${PKG_LIST}; do go test -covermode=count -coverprofile "coverage/$${package##*/}.cov" "$$package"; done
echo mode: count > coverage/coverage.cov
tail -q -n +2 coverage/*.cov >> coverage/coverage.cov
go tool cover -func=coverage/coverage.cov
.PHONY: version
version:
@echo ${VERSION}
.PHONY: clean
clean:
rm -rf build
.PHONY: build
build: build/${BIN}-${GOOS}-${GOARCH}
.PHONY: build-all
build-all:
$(MAKE) build GOOS=linux GOARCH=amd64
$(MAKE) build GOOS=darwin GOARCH=amd64
.PHONY: releases
releases: build-all
mkdir -p "build/${BIN}-${VERSION}"
build/${BIN}-${GOOS}-${GOARCH} completion > "build/${BIN}-${VERSION}/completion.zsh"
mv build/${BIN}-linux-amd64 "build/${BIN}-${VERSION}/${BIN}"
tar czf "build/${BIN}-${VERSION}-linux-amd64.tar.gz" -C build/ "${BIN}-${VERSION}"
mv build/${BIN}-darwin-amd64 "build/${BIN}-${VERSION}/${BIN}"
tar czf "build/${BIN}-${VERSION}-darwin-amd64.tar.gz" -C build/ "${BIN}-${VERSION}"
rm -rf "build/${BIN}-${VERSION}"
.PHONY: install
install: build/$(BIN)-$(GOOS)-$(GOARCH)
mkdir -p "$(DESTDIR)$(PREFIX)/bin"
cp "$<" "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
build/${BIN}-${GOOS}-${GOARCH} completion > "$(DESTDIR)$(PREFIX)/share/zsh/site-functions/_$(BIN)"
.PHONY: uninstall
uninstall:
rm -f "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
rm -f "$(DESTDIR)$(PREFIX)/share/zsh/site-functions/_$(BIN)"