forked from icon-project/btp2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (62 loc) · 2.03 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
#-------------------------------------------------------------------------------
#
# Makefile for building target binaries.
#
# Configuration
BUILD_ROOT = $(abspath ./)
BIN_DIR = ./bin
LINUX_BIN_DIR = ./build/linux
GOBUILD = go build
GOBUILD_TAGS =
GOBUILD_ENVS = CGO_ENABLED=0
GOBUILD_LDFLAGS =
GOBUILD_FLAGS = -tags "$(GOBUILD_TAGS)" -ldflags "$(GOBUILD_LDFLAGS)"
GOBUILD_ENVS_LINUX = $(GOBUILD_ENVS) GOOS=linux GOARCH=amd64
GOTEST = go test
GOTEST_FLAGS = -test.short
# Build flags
GL_VERSION ?= $(shell git describe --always --tags --dirty)
GL_TAG ?= latest
BUILD_INFO = $(shell go env GOOS)/$(shell go env 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)
$(LINUX_BIN_DIR)/$(1) $(1)-linux : GOBUILD_LDFLAGS+=$$($(1)_LDFLAGS)
$(LINUX_BIN_DIR)/$(1) $(1)-linux :
@ \
rm -f $(LINUX_BIN_DIR)/$(1) ; \
echo "[#] go build ./cmd/$(1)"
$$(GOBUILD_ENVS_LINUX) \
go build $$(GOBUILD_FLAGS) \
-o $(LINUX_BIN_DIR)/$(1) ./cmd/$(1)
endef
$(foreach M,$(CMDS),$(eval $(call CMD_template,$(M))))
# Build flags for each command
relay_LDFLAGS = -X 'main.version=$(GL_VERSION)' -X 'main.build=$(BUILD_INFO)'
BUILD_TARGETS += relay
linux : $(addsuffix -linux,$(BUILD_TARGETS))
RELAY_IMAGE = relay:$(GL_TAG)
RELAY_DOCKER_DIR = $(BUILD_ROOT)/build/relay
relay-image: relay-linux
@ echo "[#] Building image $(RELAY_IMAGE) for $(GL_VERSION)"
@ rm -rf $(RELAY_DOCKER_DIR)
@ \
BIN_DIR=$(abspath $(LINUX_BIN_DIR)) \
BIN_VERSION=$(GL_VERSION) \
BUILD_TAGS="$(GOBUILD_TAGS)" \
$(BUILD_ROOT)/docker/relay/build.sh $(RELAY_IMAGE) $(BUILD_ROOT) $(RELAY_DOCKER_DIR)
test :
$(GOBUILD_ENVS) $(GOTEST) $(GOBUILD_FLAGS) ./... $(GOTEST_FLAGS)
.DEFAULT_GOAL := all
all : $(BUILD_TARGETS)