forked from Shopify/ghostferry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (52 loc) · 1.99 KB
/
Copy pathMakefile
File metadata and controls
65 lines (52 loc) · 1.99 KB
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
# Variables to be built into the binary
VERSION := 1.1.0
DATETIME := $(shell date -u +%Y%m%d%H%M%S)
ifndef IGNORE_DIRTY_TREE
DIRTY_TREE := $(shell git diff-index --quiet HEAD -- || echo '+dirty')
endif
COMMIT := $(addsuffix $(DIRTY_TREE),$(shell git rev-parse --short HEAD))
VERSION_STR := $(VERSION)+$(DATETIME)+$(COMMIT)
# Flags
LDFLAGS += -X github.com/Shopify/ghostferry.VersionString=$(VERSION_STR)
# Paths
GOBIN := $(GOPATH)/bin
BUILD_DIR := build
DEB_PREFIX := $(BUILD_DIR)/debian
SHARE_DIR := usr/share/ghostferry
BIN_DIR := usr/bin
# Targets
PROJECTS := copydb sharding
PROJECT_DEBS := $(foreach name,$(PROJECTS),$(name)-deb)
# Target specific variable, set proj to have a valid value.
PROJECT_PKG = ./$(proj)/cmd
PROJECT_BIN = ghostferry-$(proj)
BIN_TARGET = $(GOBIN)/$(PROJECT_BIN)
DEB_TARGET = $(BUILD_DIR)/$(PROJECT_BIN)_$(VERSION_STR).deb
.PHONY: test clean reset-deb-dir $(PROJECTS) $(PROJECT_DEBS)
.DEFAULT_GOAL := test
$(PROJECTS): $(GOBIN)
$(eval proj := $@)
go build -i -ldflags "$(LDFLAGS)" -o $(BIN_TARGET) $(PROJECT_PKG)
$(PROJECT_DEBS): LDFLAGS += -X github.com/Shopify/ghostferry.WebUiBasedir=/$(SHARE_DIR)
$(PROJECT_DEBS): reset-deb-dir
$(eval proj := $(subst -deb,,$@))
sed -e "s/{version}/$(VERSION_STR)/" $(proj)/debian/control > $(DEB_PREFIX)/DEBIAN/control
cp $(proj)/debian/copyright $(DEB_PREFIX)/DEBIAN/copyright
go build -ldflags "$(LDFLAGS)" -o $(DEB_PREFIX)/$(BIN_DIR)/$(PROJECT_BIN) $(PROJECT_PKG)
cp -ar webui $(DEB_PREFIX)/$(SHARE_DIR)
if [ -d $(proj)/debian/files ]; then cp -ar $(proj)/debian/files/* $(DEB_PREFIX)/; fi
dpkg-deb -b $(DEB_PREFIX) $(DEB_TARGET)
$(GOBIN):
mkdir -p $(GOBIN)
test:
@go version
go test ./test ./copydb/test ./sharding/test -p 1 -v
clean:
rm -rf build
$(eval proj := *)
rm -f $(BIN_TARGET)
reset-deb-dir:
rm -rf $(DEB_PREFIX)
mkdir -p $(DEB_PREFIX)/$(SHARE_DIR)
mkdir -p $(DEB_PREFIX)/$(BIN_DIR)
mkdir -p $(DEB_PREFIX)/DEBIAN