forked from icon-project/goloop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
211 lines (175 loc) · 6.18 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#-------------------------------------------------------------------------------
#
# Makefile for building target binaries.
#
# Configuration
BUILD_ROOT = $(abspath ./)
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
BUILD_PLATFORM=$(GOOS)-$(GOARCH)
BUILD_DIR = $(BUILD_ROOT)/build
CROSSBIN_ROOT=$(BUILD_DIR)/bin
ifeq ($(CROSS_COMPILE),TRUE)
BIN_DIR = $(CROSSBIN_ROOT)-$(BUILD_PLATFORM)
else
BIN_DIR = $(BUILD_ROOT)/bin
endif
GOBUILD = go build
GOBUILD_TAGS ?= rocksdb
GOBUILD_ENVS ?= $(GOBUILD_ENVS_$(shell go env GOOS))
GOBUILD_LDFLAGS =
GOBUILD_FLAGS = -tags "$(GOBUILD_TAGS)" -ldflags "$(GOBUILD_LDFLAGS)"
GOTEST = go test
GOTEST_FLAGS = -test.short
# Build flags
GL_VERSION ?= $(shell git describe --always --tags --dirty)
GL_TAG ?= latest
BUILD_INFO = $(GOOS)/$(GOARCH) tags($(GOBUILD_TAGS))-$(shell date '+%Y-%m-%d-%H:%M:%S')
#
# Build scripts for command binaries.
#
CMDS = $(patsubst cmd/%,%,$(wildcard cmd/*))
.PHONY: $(CMDS) $(addsuffix -linux,$(CMDS))
define CMD_template
$(BIN_DIR)/$(1) $(1) : GOBUILD_LDFLAGS+=$$($(1)_LDFLAGS)
$(BIN_DIR)/$(1) $(1) :
@ \
rm -f $(BIN_DIR)/$(1) ; \
echo "[#] go build ./cmd/$(1)"
$$(GOBUILD_ENVS) \
go build $$(GOBUILD_FLAGS) \
-o $(BIN_DIR)/$(1) ./cmd/$(1)
endef
$(foreach M,$(CMDS),$(eval $(call CMD_template,$(M))))
# Build flags for each command
gochain_LDFLAGS = -X 'main.version=$(GL_VERSION)' -X 'main.build=$(BUILD_INFO)'
BUILD_TARGETS += gochain
goloop_LDFLAGS = -X 'main.version=$(GL_VERSION)' -X 'main.build=$(BUILD_INFO)'
BUILD_TARGETS += goloop
linux : $(addsuffix -linux,$(BUILD_TARGETS))
%-linux:
@ \
GOOS=linux GOARCH=amd64 \
CROSS_COMPILE=TRUE \
$(MAKE) $(patsubst %-linux,%,$@)
BASE_IMAGE = goloop/base-all:$(GL_TAG)
BASE_PY_IMAGE = goloop/base-py:$(GL_TAG)
BASE_JAVA_IMAGE = goloop/base-java:$(GL_TAG)
BASE_DOCKER_DIR = $(BUILD_DIR)/base
ROCKSDBDEPS_IMAGE = goloop/rocksdb-deps:$(GL_TAG)
GODEPS_IMAGE = goloop/go-deps:$(GL_TAG)
PYDEPS_IMAGE = goloop/py-deps:$(GL_TAG)
JAVADEPS_IMAGE = goloop/java-deps:$(GL_TAG)
BUILDDEPS_IMAGE = goloop/build-deps:$(GL_TAG)
BUILDDEPS_DOCKER_DIR = $(BUILD_DIR)/builddpes
GOCHAIN_IMAGE = goloop/gochain:$(GL_TAG)
GOCHAIN_DOCKER_DIR = $(BUILD_DIR)/gochain
GOLOOP_IMAGE = goloop:$(GL_TAG)
GOLOOP_DOCKER_DIR = $(BUILD_DIR)/goloop
GOLOOP_PY_IMAGE = goloop-py:$(GL_TAG)
GOLOOP_PY_DOCKER_DIR = $(BUILD_DIR)/goloop-py
GOLOOP_JAVA_IMAGE = goloop-java:$(GL_TAG)
GOLOOP_JAVA_DOCKER_DIR = $(BUILD_DIR)/goloop-java
GOLOOP_WORK_DIR = /work
PYEE_DIST_DIR = $(BUILD_ROOT)/build/pyee/dist
$(PYEE_DIST_DIR):
@ mkdir -p $@
builddeps-%:
@ \
IMAGE_GO_DEPS=$(GODEPS_IMAGE) \
IMAGE_PY_DEPS=$(PYDEPS_IMAGE) \
IMAGE_JAVA_DEPS=$(JAVADEPS_IMAGE) \
IMAGE_ROCKSDB_DEPS=$(ROCKSDBDEPS_IMAGE) \
$(BUILD_ROOT)/docker/build-deps/update.sh \
$(patsubst builddeps-%,%,$@) \
goloop/$(patsubst builddeps-%,%,$@)-deps:$(GL_TAG) \
$(BUILD_ROOT) $(BUILDDEPS_DOCKER_DIR)
builddeps-build : builddeps-go builddeps-rocksdb
gorun-% : builddeps-build
@ \
docker run -t --rm \
-v $(BUILD_ROOT):$(GOLOOP_WORK_DIR) \
-w $(GOLOOP_WORK_DIR) \
-e "CROSS_COMPILE=TRUE" \
-e "GOBUILD_TAGS=$(GOBUILD_TAGS)" \
-e "GL_VERSION=$(GL_VERSION)" \
$(BUILDDEPS_IMAGE) \
make $(patsubst gorun-%,%,$@)
pyrun-% : builddeps-py | $(PYEE_DIST_DIR)
@ \
docker run -t --rm \
-v $(BUILD_ROOT):$(GOLOOP_WORK_DIR) \
-w $(GOLOOP_WORK_DIR) \
-e "GL_VERSION=$(GL_VERSION)" \
$(PYDEPS_IMAGE) \
make $(patsubst pyrun-%,%,$@)
pyexec:
@ \
echo "[#] Building Python executor" ; \
cd $(BUILD_ROOT)/pyee ; \
rm -rf build $(PYEE_DIST_DIR); \
pip3 install wheel ; \
python3 setup.py bdist_wheel -d $(PYEE_DIST_DIR) ; \
rm -rf pyexec.egg-info
javarun-% : builddeps-java
@ \
docker run -t --rm \
-v $(BUILD_ROOT):$(GOLOOP_WORK_DIR) \
-w $(GOLOOP_WORK_DIR)/javaee \
$(JAVADEPS_IMAGE) \
make $(patsubst javarun-%,%,$@)
base-image-%: builddeps-py builddeps-rocksdb
@ \
IMAGE_PY_DEPS=$(PYDEPS_IMAGE) \
IMAGE_ROCKSDB_DEPS=$(ROCKSDBDEPS_IMAGE) \
$(BUILD_ROOT)/docker/base/update.sh \
$(patsubst base-image-%,%,$@) \
goloop/base-$(patsubst base-image-%,%,$@):$(GL_TAG) \
$(BUILD_ROOT) $(BASE_DOCKER_DIR)-$(patsubst base-image-%,%,$@)
goloop-image: base-image-all pyrun-pyexec gorun-goloop javarun-javaexec
@ echo "[#] Building image $(GOLOOP_IMAGE) for $(GL_VERSION)"
@ rm -rf $(GOLOOP_DOCKER_DIR)
@ \
BIN_DIR=$(CROSSBIN_ROOT)-$$(docker inspect $(BASE_IMAGE) --format "{{.Os}}-{{.Architecture}}") \
IMAGE_BASE=$(BASE_IMAGE) \
GOLOOP_VERSION=$(GL_VERSION) \
GOBUILD_TAGS="$(GOBUILD_TAGS)" \
$(BUILD_ROOT)/docker/goloop/update.sh $(GOLOOP_IMAGE) $(BUILD_ROOT) $(GOLOOP_DOCKER_DIR)
goloop-py-image: base-image-py pyrun-pyexec gorun-goloop
@ echo "[#] Building image $(GOLOOP_PY_IMAGE) for $(GL_VERSION)"
@ rm -rf $(GOLOOP_PY_DOCKER_DIR)
@ \
BIN_DIR=$(CROSSBIN_ROOT)-$$(docker inspect $(BASE_PY_IMAGE) --format "{{.Os}}-{{.Architecture}}") \
IMAGE_BASE=$(BASE_PY_IMAGE) \
GOLOOP_VERSION=$(GL_VERSION) \
GOBUILD_TAGS="$(GOBUILD_TAGS)" \
$(BUILD_ROOT)/docker/goloop-py/update.sh \
$(GOLOOP_PY_IMAGE) $(BUILD_ROOT) $(GOLOOP_PY_DOCKER_DIR)
goloop-java-image: base-image-java gorun-goloop javarun-javaexec
@ echo "[#] Building image $(GOLOOP_JAVA_IMAGE) for $(GL_VERSION)"
@ rm -rf $(GOLOOP_JAVA_DOCKER_DIR)
@ \
BIN_DIR=$(CROSSBIN_ROOT)-$$(docker inspect $(BASE_JAVA_IMAGE) --format "{{.Os}}-{{.Architecture}}") \
IMAGE_BASE=$(BASE_JAVA_IMAGE) \
GOLOOP_VERSION=$(GL_VERSION) \
GOBUILD_TAGS="$(GOBUILD_TAGS)" \
$(BUILD_ROOT)/docker/goloop-java/update.sh \
$(GOLOOP_JAVA_IMAGE) $(BUILD_ROOT) $(GOLOOP_JAVA_DOCKER_DIR)
gochain-image: base-image-all pyrun-pyexec gorun-gochain javarun-javaexec
@ echo "[#] Building image $(GOCHAIN_IMAGE) for $(GL_VERSION)"
@ rm -rf $(GOCHAIN_DOCKER_DIR)
@ \
BIN_DIR=$(CROSSBIN_ROOT)-$$(docker inspect $(BASE_IMAGE) --format "{{.Os}}-{{.Architecture}}") \
IMAGE_BASE=$(BASE_IMAGE) \
GOCHAIN_VERSION=$(GL_VERSION) \
GOBUILD_TAGS="$(GOBUILD_TAGS)" \
$(BUILD_ROOT)/docker/gochain/update.sh $(GOCHAIN_IMAGE) $(BUILD_ROOT) $(GOCHAIN_DOCKER_DIR)
include icon/build.mk
.PHONY: test
test :
$(GOBUILD_ENVS) $(GOTEST) $(GOBUILD_FLAGS) ./... $(GOTEST_FLAGS)
test% : $(BIN_DIR)/gochain
@ cd testsuite ; ./gradlew $@
.DEFAULT_GOAL := all
all : $(BUILD_TARGETS)
-include local.mk