forked from gertd/go-pluralize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (122 loc) · 4.33 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
SHELL := $(shell which bash)
## BOF define block
BINARIES := pluralize
BINARY = $(word 1, $@)
PLATFORMS := windows linux darwin
PLATFORM = $(word 1, $@)
ROOT_DIR := $(shell git rev-parse --show-toplevel)
BIN_DIR := $(ROOT_DIR)/bin
REL_DIR := $(ROOT_DIR)/release
SRC_DIR := $(ROOT_DIR)/cmd
INC_DIR := $(ROOT_DIR)/include
TMP_DIR := $(ROOT_DIR)/tmp
VERSION :=`git describe --tags 2>/dev/null`
COMMIT :=`git rev-parse --short HEAD 2>/dev/null`
DATE :=`date "+%FT%T%z"`
LDBASE := github.com/gertd/go-pluralize/pkg/version
LDFLAGS := -ldflags "-w -s -X $(LDBASE).ver=${VERSION} -X $(LDBASE).date=${DATE} -X $(LDBASE).commit=${COMMIT}"
GOARCH ?= amd64
GOOS ?= $(shell go env GOOS)
LINTER := $(BIN_DIR)/golangci-lint
LINTVERSION:= v1.27.0
TESTRUNNER := $(BIN_DIR)/gotestsum
TESTVERSION:= v0.5.0
PROTOC := $(BIN_DIR)/protoc
PROTOCVER := 3.12.3
NO_COLOR :=\033[0m
OK_COLOR :=\033[32;01m
ERR_COLOR :=\033[31;01m
WARN_COLOR :=\033[36;01m
ATTN_COLOR :=\033[33;01m
## EOF define block
.PHONY: all
all: deps gen build test lint
deps:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@GO111MODULE=on go mod download
.PHONY: gen
gen: deps $(BIN_DIR)
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@go generate ./...
.PHONY: dobuild
dobuild:
@echo -e "$(ATTN_COLOR)==> $@ $(B) GOOS=$(P) GOARCH=$(GOARCH) VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) $(NO_COLOR)"
@GOOS=$(P) GOARCH=$(GOARCH) GO111MODULE=on go build $(LDFLAGS) -o $(T)/$(P)-$(GOARCH)/$(B)$(if $(findstring $(P),windows),".exe","") $(SRC_DIR)/$(B)
ifneq ($(P),windows)
@chmod +x $(T)/$(P)-$(GOARCH)/$(B)
endif
.PHONY: build
build: $(BIN_DIR) deps
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@for b in ${BINARIES}; \
do \
$(MAKE) dobuild B=$${b} P=${GOOS} T=${BIN_DIR}; \
done
.PHONY: doinstall
doinstall:
@echo -e "$(ATTN_COLOR)==> $@ $(B) GOOS=$(P) GOARCH=$(GOARCH) VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) $(NO_COLOR)"
@GOOS=$(P) GOARCH=$(GOARCH) GO111MODULE=on go install $(LDFLAGS) $(SRC_DIR)/$(B)
.PHONY: install
install:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@for b in ${BINARIES}; \
do \
$(MAKE) doinstall B=$${b} P=${GOOS}; \
done
.PHONY: dorelease
dorelease:
@echo -e "$(ATTN_COLOR)==> $@ build GOOS=$(P) GOARCH=$(GOARCH) VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) $(NO_COLOR)"
@GOOS=$(P) GOARCH=$(GOARCH) GO111MODULE=on go build $(LDFLAGS) -o $(T)/$(P)-$(GOARCH)/$(B)$(if $(findstring $(P),windows),".exe","") $(SRC_DIR)/$(B)
ifneq ($(P),windows)
@chmod +x $(T)/$(P)-$(GOARCH)/$(B)
endif
@echo -e "$(ATTN_COLOR)==> $@ zip $(B)-$(P)-$(GOARCH).zip $(NO_COLOR)"
@zip -j $(T)/$(P)-$(GOARCH)/$(B)-$(P)-$(GOARCH).zip $(T)/$(P)-$(GOARCH)/$(B)$(if $(findstring $(P),windows),".exe","") >/dev/null
.PHONY: release
release: $(REL_DIR)
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@for b in ${BINARIES}; \
do \
for p in ${PLATFORMS}; \
do \
$(MAKE) dorelease B=$${b} P=$${p} T=${REL_DIR}; \
done; \
done \
$(TESTRUNNER):
@echo -e "$(ATTN_COLOR)==> get $@ $(NO_COLOR)"
@GOBIN=$(BIN_DIR) go get -u gotest.tools/gotestsum
.PHONY: test
test: $(TESTRUNNER)
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@CGO_ENABLED=0 $(BIN_DIR)/gotestsum --format short-verbose -- -count=1 -v $(ROOT_DIR)/...
$(LINTER):
@echo -e "$(ATTN_COLOR)==> get $@ $(NO_COLOR)"
@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(LINTVERSION)
.PHONY: lint
lint: $(LINTER)
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@CGO_ENABLED=0 $(LINTER) run --enable-all
@echo -e "$(NO_COLOR)\c"
.PHONY: doclean
doclean:
@echo -e "$(ATTN_COLOR)==> $@ $(B) GOOS=$(P) $(NO_COLOR)"
@if [ -a $(GOPATH)/bin/$(B)$(if $(findstring $(P),windows),".exe","") ];\
then \
rm $(GOPATH)/bin/$(B)$(if $(findstring $(P),windows),".exe",""); \
fi
.PHONY: clean
clean:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@rm -rf $(BIN_DIR)
@rm -rf $(REL_DIR)
@go clean
@for b in ${BINARIES}; \
do \
$(MAKE) doclean B=$${b} P=${GOOS}; \
done
$(REL_DIR):
@echo -e "$(ATTN_COLOR)==> create REL_DIR $(REL_DIR) $(NO_COLOR)"
@mkdir -p $(REL_DIR)
$(BIN_DIR):
@echo -e "$(ATTN_COLOR)==> create BIN_DIR $(BIN_DIR) $(NO_COLOR)"
@mkdir -p $(BIN_DIR)