forked from ovh/erlenmeyer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (60 loc) · 2.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
65
66
67
68
69
70
71
72
73
74
75
76
BUILD_DIR := build
VPATH := $(BUILD_DIR)
CC := go build -v -mod vendor
GITHASH := $(shell git rev-parse --short HEAD)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := $(shell git describe --tags --candidates 1 --match '*.*')
DATE := $(shell TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ UTC')
DFLAGS := -race
CFLAGS := -X 'github.com/ovh/erlenmeyer/cmd.githash=$(GITHASH)' \
-X 'github.com/ovh/erlenmeyer/cmd.date=$(DATE)' \
-X 'github.com/ovh/erlenmeyer/cmd.gitbranch=$(GITBRANCH)' \
-X 'github.com/ovh/erlenmeyer/cmd.version=$(VERSION)'
CROSS := GOOS=linux GOARCH=amd64
FORMAT_PATHS := ./cmd/ ./core ./middlewares ./proto erlenmeyer.go
LINT_PATHS := ./ ./cmd/... ./core/... ./middlewares/...
rwildcard := $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
BUILD_FILE := erlenmeyer_$(VERSION)
BUILD_DEST := $(BUILD_DIR)/$(BUILD_FILE)
.SECONDEXPANSION:
.PHONY: all
all: format lint dist
.PHONY: init
init:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.27.0
.PHONY: dep
dep:
go mod vendor -v
.PHONY: tidy
tidy:
go mod tidy -v
.PHONY: clean
clean:
rm -rf build
rm -rf vendor
.PHONY: lint
lint: init
golangci-lint run
.PHONY: format
format:
gofmt -w -s $(FORMAT_PATHS)
.PHONY: test
test: dep
go test -cover ./...
.PHONY: dev
dev: tidy format lint build
.PHONY: build
build: dep erlenmeyer.go $$(call rwildcard, ./cmd, *.go) $$(call rwildcard, ./core, *.go) $$(call rwildcard, ./proto, *.go) $$(call rwildcard, ./middlewares, *.go) $$(call rwildcard, *.go)
$(CC) $(DFLAGS) -ldflags "$(CFLAGS)" -o $(BUILD_DEST) erlenmeyer.go
rm -f $(BUILD_DIR)/erlenmeyer
ln -s $(BUILD_FILE) $(BUILD_DIR)/erlenmeyer
.PHONY: release
release: dep erlenmeyer.go $$(call rwildcard, ./cmd, *.go) $$(call rwildcard, ./core, *.go) $$(call rwildcard, ./proto, *.go) $$(call rwildcard, ./middlewares, *.go) $$(call rwildcard, *.go)
$(CC) -ldflags "-s -w $(CFLAGS)" -o $(BUILD_DEST) erlenmeyer.go
rm -f $(BUILD_DIR)/erlenmeyer
ln -s $(BUILD_FILE) $(BUILD_DIR)/erlenmeyer
.PHONY: dist
dist: dep erlenmeyer.go $$(call rwildcard, ./cmd, *.go) $$(call rwildcard, ./core, *.go) $$(call rwildcard, ./proto, *.go) $$(call rwildcard, ./middlewares, *.go) $$(call rwildcard, *.go)
$(CROSS) $(CC) -ldflags "-s -w $(CFLAGS)" -o $(BUILD_DEST) erlenmeyer.go
rm -f $(BUILD_DIR)/erlenmeyer
ln -s $(BUILD_FILE) $(BUILD_DIR)/erlenmeyer