forked from bobziuchkovski/cue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
130 lines (101 loc) · 2.98 KB
/
Makefile.common
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# http://stackoverflow.com/questions/322936/common-gnu-makefile-directory-path#comment11704496_324782
TOP := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
GOFMT=gofmt -w -s
GOSRCDIR=$(GOPATH)/src/$(PACKAGE)
GOPATHS=$(shell glide novendor | grep -v /main/)
GOFILES=$(shell git ls-files | grep '\.go$$')
MAINGO=$(wildcard main/*.go)
MAIN=$(patsubst main/%.go,%,$(MAINGO))
ifeq ($(GOTEST_TIMEOUT),)
GOTEST_TIMEOUT=60s
endif
ifeq ($(GOMETALINTER_OPTS),)
GOMETALINTER_OPTS=--enable-all --tests
endif
ifeq ($(GOMETALINTER_EXCLUDES),)
GOMETALINTER_EXCLUDES=\
--exclude "\.pb\.go:" \
--exclude "_fsm\.go:" \
--exclude "_easyjson\.go:" \
--exclude "_test\.go:.*\((lll|unparam|gocyclo)\)$$" \
--exclude "comment should be of the form.*\(golint\)$$" \
--exclude "should have comment or be unexported.*\(golint\)$$"
endif
CODE_VERSION=$(TRAVIS_COMMIT)
ifeq ($(CODE_VERSION),)
CODE_VERSION=$(shell git rev-parse --short HEAD)-dev
endif
CODE_BUILD=$(TRAVIS_REPO_SLUG)\#$(TRAVIS_JOB_NUMBER)
ifeq ($(CODE_BUILD),\#)
CODE_BUILD=$(PACKAGE)\#$(shell whoami)
endif
LDIMPORT=$(PACKAGE)/vendor/github.com/remerge/go-service
LDFLAGS=-X $(LDIMPORT).CodeVersion=$(CODE_VERSION) -X $(LDIMPORT).CodeBuild=$(CODE_BUILD)@$(shell date -u +%FT%TZ)
.PHONY: build run clean lint test bench fmt dep init up gen proto-dep proto release deploy
all: build
build: fmt
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go test -v -i
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go build -v -i -ldflags "$(LDFLAGS)" $(GOPATHS)
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go build -v -i -ldflags "$(LDFLAGS)" $(MAINGO)
run: build
./$(MAIN)
clean:
cd $(GOSRCDIR) && \
go clean -i -x
rm -f $(MAIN)
lint: build
cd $(GOSRCDIR) && \
gometalinter \
--vendor --vendored-linters \
--deadline=$(GOTEST_TIMEOUT) \
$(GOMETALINTER_OPTS) \
$(GOMETALINTER_EXCLUDES) \
-D test -D testify \
$(GOPATHS)
test:
cd $(GOSRCDIR) && \
go test -timeout $(GOTEST_TIMEOUT) -v $(GOPATHS)
bench: build
cd $(GOSRCDIR) && \
go test -bench=. -benchmem -cpu 32 $(GOPATHS)
escape: build
for pkg in $(GOPATHS); do \
cd $(GOSRCDIR) && \
CGO_ENABLED=0 \
go build -v -gcflags '-m -m -l -e' -ldflags "$(LDFLAGS)" $$pkg; \
done
fmt:
$(GOFMT) $(GOFILES)
dep:
go get -u github.com/Masterminds/glide
go get -u github.com/alecthomas/gometalinter
gometalinter --install --update
cd $(GOSRCDIR) && glide install
init:
cd $(GOSRCDIR) && \
glide init
up:
cd $(GOSRCDIR) && \
glide update
gen:
cd $(GOSRCDIR) && \
go generate $(GOPATHS)
$(GOFMT) $(GOFILES)
PROTOS=$(wildcard *.proto */*.proto)
PBGOS=$(patsubst %.proto,%.pb.go,$(PROTOS))
proto-dep:
go get -u github.com/gogo/protobuf/protoc-gen-gogofaster
proto: proto-dep $(PBGOS)
$(PBGOS): %.pb.go: %.proto
protoc --gogofaster_out=. -I=.:$(TOP)/vendor:$(GOPATH)/src $<
release:
git push origin master master:production
deploy:
/bin/bash -c 'cd ../chef.new && knife ssh roles:$(PROJECT) sudo chef-client'
/bin/bash -c 'cd ../chef && knife sudo -Q roles:$(PROJECT) chef-client'