-
Notifications
You must be signed in to change notification settings - Fork 83
/
Makefile
170 lines (130 loc) · 3.79 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
BASE := rsprd.com/spread
DIR := $(GOPATH)/src/$(BASE)
CMD_NAME := spread
PROTO_DIR := proto
EXEC_PKG := $(BASE)/cmd/$(CMD_NAME)
PKGS := ./pkg/... ./cli/... ./cmd/...
# set spread version if not provided by environment
ifndef SPREAD_VERSION
SPREAD_VERSION := v0.0.0
endif
LIBGIT2_VERSION ?= v0.23.4
GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64
GO ?= go
GOX ?= gox
GOFMT ?= gofmt "-s"
GOLINT ?= golint
DOCKER ?= docker
PROTOC := protoc
GOFILES := find . -name '*.go' -not -path "./vendor/*"
VERSION_LDFLAG := -X main.Version=$(SPREAD_VERSION)
LIBGIT2_DIR := $(DIR)/vendor/libgit2
LIBGIT2_BUILD := $(LIBGIT2_DIR)/build
LIBGIT2_PKGCONFIG := $(LIBGIT2_BUILD)/libgit2.pc
LIBGIT2_CGOFLAG := -I$(LIBGIT2_DIR)/include
# Do not use sudo on OS X
ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SUDO :=
else
SUDO := sudo
endif
endif
GOBUILD_LDFLAGS ?= $(VERSION_LDFLAG)
GOBUILD_FLAGS ?= -i -v
GOTEST_FLAGS ?= -v
GOX_FLAGS ?= -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" -os="${GOX_OS}" -arch="${GOX_ARCH}"
CGO_ENV ?= CGO_CFLAGS="$(LIBGIT2_CGOFLAG)"
STATIC_LDFLAGS ?= -extldflags "-static" --s -w
GITLAB_CONTEXT ?= ./build/gitlab
LIBGIT2_URL ?= https://github.com/libgit2/libgit2/archive/$(LIBGIT2_VERSION).tar.gz
# image data
ORG ?= redspreadapps
NAME ?= gitlabci
TAG ?= latest
GITLAB_IMAGE_NAME = "$(ORG)/$(NAME):$(TAG)"
GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64
.PHONY: all
all: clean validate test
.PHONY: release
release: validate test crossbuild
.PHONY: test
test: unit integration
.PHONY: unit
unit: build
$(GO) test $(GOTEST_FLAGS) $(PKGS)
.PHONY: integration
integration: build
mkdir -p ./build
./test/mattermost-demo.sh
proto: pkg/spreadproto/*.pb.go
pkg/spreadproto/*.pb.go:$(PROTO_DIR)/*.proto
mkdir -p $$(dirname $@)
$(PROTOC) --go_out=plugins=grpc:$$(dirname $@) -I=$(PROTO_DIR) $^
.PHONY: validate
validate: lint checkgofmt vet
.PHONY: build
build: build/spread
build/spread:
$(CGO_ENV) $(GO) build $(GOBUILD_FLAGS) -ldflags "$(GOBUILD_LDFLAGS)" -o $@ $(EXEC_PKG)
build/spread-linux-static:
GOOS=linux $(GO) build -o $@ $(GOBUILD_FLAGS) -ldflags "$(GOBUILD_LDFLAGS) $(STATIC_LDFLAGS)" $(EXEC_PKG)
chmod +x $@
.PHONY: crossbuild
crossbuild: deps gox-setup
$(GOX) $(GOX_FLAGS) -gcflags="$(GOBUILD_FLAGS)" -ldflags="$(GOBUILD_LDFLAGS) $(STATIC_LDFLAGS)" $(EXEC_PKG)
.PHONY: build-gitlab
build-gitlab: build/spread-linux-static
rm -rf $(GITLAB_CONTEXT)
cp -r ./images/gitlabci $(GITLAB_CONTEXT)
cp ./build/spread-linux-static $(GITLAB_CONTEXT)
$(DOCKER) build $(DOCKER_OPTS) -t $(GITLAB_IMAGE_NAME) $(GITLAB_CONTEXT)
install-libgit2: build-libgit2
cd $(LIBGIT2_BUILD) && $(SUDO) make install
build-libgit2: $(LIBGIT2_PKGCONFIG)
$(LIBGIT2_PKGCONFIG): vendor/libgit2
./hack/build-libgit2.sh
vendor/libgit2: vendor/libgit2.tar.gz
mkdir -p $@
tar -zxf $< -C $@ --strip-components=1
vendor/libgit2.tar.gz:
curl -L -o $@ $(LIBGIT2_URL)
.PHONY: vet
vet:
$(GO) vet $(PKGS)
lint: .golint-install
for pkg in $(PKGS); do \
echo "Running golint on $$pkg:"; \
golint $$pkg; \
done;
.PHONY: checkgofmt
checkgofmt:
# get all go files and run go fmt on them
files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \
echo "Error: '$(GOFMT)' needs to be run on:"; \
echo "$${files}"; \
exit 1; \
fi;
.PHONY: deps
deps: .golint-install .gox-install
.golint-install:
$(GO) get -x github.com/golang/lint/golint > $@
PHONY: gox-setup
gox-setup: .gox-install
.gox-install:
$(GO) get -x github.com/mitchellh/gox > $@
.PHONY: clean
clean:
rm -vf .gox-* .golint-*
rm -rfv ./build
$(GO) clean $(PKGS) || true
.PHONY: godep
godep:
go get -u -v github.com/tools/godep
@echo "Recalculating godeps, removing Godeps and vendor if not canceled in 5 seconds"
@sleep 5
rm -rf Godeps vendor
GO15VENDOREXPERIMENT="1" godep save -v ./pkg/... ./cli/... ./cmd/...