-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
64 lines (49 loc) · 2.09 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
ROOT_DIR := $(CURDIR)
BUILD_DIR := $(ROOT_DIR)/_output
BIN_DIR := $(BUILD_DIR)/bin
REPO_PREFIX := yunion.io/x/cloudmux
VERSION_PKG := yunion.io/x/pkg/util/version
output_dir:
@mkdir -p $(BUILD_DIR)
bin_dir: output_dir
@mkdir -p $(BUILD_DIR)/bin
prepare_dir: bin_dir
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git branch -r --contains | head -1 | sed -E -e "s%(HEAD ->|origin|upstream)/?%%g" | xargs)
GIT_VERSION := $(shell git describe --always --tags --abbrev=14 $(GIT_COMMIT)^{commit})
GIT_TREE_STATE := $(shell s=`git status --porcelain 2>/dev/null`; if [ -z "$$s" ]; then echo "clean"; else echo "dirty"; fi)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := "-w \
-X $(VERSION_PKG).gitVersion=$(GIT_VERSION) \
-X $(VERSION_PKG).gitCommit=$(GIT_COMMIT) \
-X $(VERSION_PKG).gitBranch=$(GIT_BRANCH) \
-X $(VERSION_PKG).buildDate=$(BUILD_DATE) \
-X $(VERSION_PKG).gitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PKG).gitMajor=0 \
-X $(VERSION_PKG).gitMinor=0"
ifneq ($(DLV),)
GO_BUILD_FLAGS += -gcflags "all=-N -l"
LDFLAGS = ""
endif
# GO_BUILD_FLAGS+=-mod vendor -ldflags $(LDFLAGS)
GO_BUILD_FLAGS+=-ldflags $(LDFLAGS)
GO_BUILD := go build $(GO_BUILD_FLAGS)
cmd/%: prepare_dir
$(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@
test:
go test -v $(GO_BUILD_FLAGS) ./...
fmt:
goimports -w -local "yunion.io/x/:yunion.io/x/onecloud:yunion.io/x/cloudmux" pkg cmd
GOPROXY ?= direct
mod:
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p'))
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod tidy
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod vendor
REGISTRY ?= "registry.cn-beijing.aliyuncs.com/yunionio"
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
image:
mkdir -p $(ROOT_DIR)/_output
DEBUG=$(DEBUG) ARCH=$(ARCH) TAG=$(VERSION) REGISTRY=$(REGISTRY) $(ROOT_DIR)/scripts/docker_push.sh $(filter-out $@,$(MAKECMDGOALS))
%:
@: