-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
64 lines (48 loc) · 1.38 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
# Build pd-server, pd-ctl, pd-recover
default: dev
# Development validation.
all: dev
dev: tidy fmt build
.PHONY: default all dev
#### Build ####
BUILD_FLAGS ?=
BUILD_TAGS ?=
DOCKER_IMG ?= pingcap/dwworker:latest
ROOT_PATH := $(shell pwd)
BUILD_OUTPUT := $(ROOT_PATH)/bin/tidb2dw
REPO := github.com/pingcap-inc/tidb2dw
_COMMIT := $(shell git describe --no-match --always --dirty)
_GITREF := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(if $(COMMIT),$(COMMIT),$(_COMMIT))
GITREF := $(if $(GITREF),$(GITREF),$(_GITREF))
LDFLAGS := -w -s
LDFLAGS += -X "$(REPO)/version.GitHash=$(COMMIT)"
LDFLAGS += -X "$(REPO)/version.GitRef=$(GITREF)"
LDFLAGS += $(EXTRA_LDFLAGS)
CGO_ENABLED ?= 0
ifeq ($(shell uname -s),Darwin)
CGO_ENABLED=1
endif
.PHONY: build
build:
@echo "Build using CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH)"
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags "$(BUILD_TAGS)" -o $(BUILD_OUTPUT) main.go
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: tiny
tidy:
go mod tidy
.PHONY: clean
clean:
rm -rf $(ROOT_PATH)/bin
.PHONY: docker-build
docker-build: export CGO_ENABLED=0
docker-build: export GOOS=linux
docker-build: export GOARCH=amd64
docker-build: BUILD_OUTPUT=$(ROOT_PATH)/bin/dwworker-linux-amd64
docker-build: build
docker build -t $(DOCKER_IMG) .
.PHONY: docker-push
docker-push:
docker push $(DOCKER_IMG)