-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
70 lines (49 loc) · 2.04 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
PROTOC ?= protoc
GO ?= go
GOFMT ?= gofmt
GODEP ?= godep
GOBINDATA ?= go-bindata
VERSION = $(shell git rev-parse --short HEAD)
PROD_PKG_PREFIX = easyagent/prod
OUT_DIR = build
PROTO_DIR = internal/proto
GOBUILD_OPTS = -ldflags "-s -X easyagent/internal.VERSION=$(VERSION)"
define BUILD_RELEASE_TARGET
$(eval os := $1)
$(eval arch := $2)
$(eval target := $3)
$(eval mode := $4)
@echo "Build $(mode)-version for $(target) $(os)-$(arch) ..."
$(eval output := $(if $(filter $(target),easy-agent-server),server,$(target)))
$(eval target_dir := $(OUT_DIR)/$(mode)/$(output)$(if $(filter $(mode),release),/$1-$2,))
@mkdir -p $(target_dir)
$(eval bin_name := $(target)$(if $(filter $(os),windows),.exe,))
$(if $(filter $(mode),release),
GOOS=$(os) GOARCH=$(arch) $(GO) build $(GOBUILD_OPTS) -o $(target_dir)/$(bin_name) $(PROD_PKG_PREFIX)/$(target),
$(GO) build $(GOBUILD_OPTS) -o $(target_dir)/$(bin_name) $(PROD_PKG_PREFIX)/$(target))
endef
asset: templates/*
@echo "Generating templates..."
$(GOBINDATA) -nocompress -o internal/server/asset/assets.go -pkg asset templates/
proto: $(PROTO_DIR)/*.proto
@echo "Generating protocol codes ..."
$(PROTOC) -I=$(PROTO_DIR) -I=$(GOPATH)/src/ -I=$(GOPATH)/src/github.com/gogo/protobuf/protobuf/ \
--gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,plugins=grpc:$(PROTO_DIR) $?
server-release:
$(call BUILD_RELEASE_TARGET,linux,amd64,easy-agent-server,release)
sidecar-release: ## build sidecar client
$(call BUILD_RELEASE_TARGET,linux,amd64,sidecar,release)
$(call BUILD_RELEASE_TARGET,windows,amd64,sidecar,release)
clean-release:
@rm -rf $(OUT_DIR)/release
release: clean-release proto server-release sidecar-release asset
server-debug:
$(call BUILD_RELEASE_TARGET,,,easy-agent-server,debug)
sidecar-debug:
$(call BUILD_RELEASE_TARGET,,,sidecar,debug)
clean-debug:
@rm -rf $(OUT_DIR)/debug
debug: clean-debug proto sidecar-debug server-debug asset
clean: clean-release clean-debug
all: debug release
.DEFAULT_GOAL := debug