-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (89 loc) · 2.96 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
PROJ_NAME = bhlnames
VERSION = $(shell git describe --tags)
VER = $(shell git describe --tags --abbrev=0)
DATE = $(shell date -u '+%Y-%m-%d_%H:%M:%S%Z')
NO_C = CGO_ENABLED=0
FLAGS_SHARED = CGO_ENABLED=0 GOARCH=amd64
FLAGS_LINUX = $(FLAGS_SHARED) GOOS=linux
FLAGS_MAC = $(FLAGS_SHARED) GOOS=darwin
FLAGS_WIN = $(FLAGS_SHARED) GOOS=windows
FLAGS_LD = -ldflags "-X github.com/gnames/$(PROJ_NAME)/pkg.Build=${DATE} \
-X github.com/gnames/$(PROJ_NAME)/pkg.Version=${VERSION}"
FLAGS_REL = -trimpath -ldflags "-s -w -X github.com/gnames/$(PROJ_NAME)/pkg.Build=$(DATE)"
RELEASE_DIR = /tmp
TEST_OPTS = -p 1 -shuffle=on ./internal/ent/input ./internal/ent/score ./internal/io/dictio ./pkg ./pkg/config
GOCMD = go
GOTEST = $(GOCMD) test
GOVET = $(GOCMD) vet
GOBUILD = $(GOCMD) build $(FLAGS_LD)
GORELEASE = $(GOCMD) build $(FLAGS_REL)
GOINSTALL = $(GOCMD) install $(FLAGS_LD)
GOCLEAN = $(GOCMD) clean
GOGET = $(GOCMD) get
.PHONY: help build test deps tools release install openapi
all: install
## Test:
test: ## Run the tests of the project
$(GOTEST) $(TEST_OPTS);
@echo "Also start restful service and run tests with 'make testrest'"
testrest:
$(GOTEST) -p 1 -shuffle=on ./internal/io/restio
## Dependencies
deps: ## Download dependencies
$(GOCMD) mod download;
## Tools
tools: deps ## Install tools
@echo Installing tools from tools.go
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
## Build:
build: openapi ## Build binary
$(NO_C) $(GOBUILD) \
-o $(PROJ_NAME) \
.
## Build Release
buildrel: openapi ## Build binary without debug info and with hardcoded version
$(NO_C) $(GORELEASE) \
-o $(PROJ_NAME) \
.
## Release
release: openapi dockerhub ## Build and package binaries for release
$(GOCLEAN); \
$(FLAGS_LINUX) $(GORELEASE); \
tar zcvf /tmp/bhlnames-${VER}-linux.tar.gz bhlnames; \
$(GOCLEAN); \
$(FLAGS_MAC) $(GORELEASE); \
tar zcvf /tmp/bhlnames-${VER}-mac.tar.gz bhlnames; \
$(GOCLEAN); \
$(FLAGS_WIN) $(GORELEASE); \
zip -9 /tmp/bhlnames-$(VER)-win-64.zip bhlnames.exe; \
$(GOCLEAN);
## Install
install: openapi ## Build and install binary
$(NO_C) $(GOINSTALL);
## OpenAPI generation
openapi: ## Generate documentation for OpenAPI
swag init -g restio.go -d ./internal/io/restio --parseDependency --parseInternal
## Build docker image
dc: build
docker-compose build; \
docker: buildrel
docker buildx build -t gnames/$(PROJ_NAME):latest -t gnames/$(PROJ_NAME):$(VERSION) .; \
$(GOCLEAN);
dockerhub: docker
docker push gnames/$(PROJ_NAME); \
docker push gnames/$(PROJ_NAME):$(VERSION)
## Help:
help: ## Show this help
@echo ''
@echo 'Usage:'
@echo ' $(YELLOW)make${RESET} $(GREEN)<target>$(RESET)'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[0-9a-zA-Z_-]+:.*?##.*$$/) \
{printf " $(YELLOW)%-20s$(GREEN)%s$(RESET)\n", $$1, $$2} \
else if (/^## .*$$/) {printf " $(CYAN)%s$(RESET)\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
## Version
version: ## Display current version
@echo $(VERSION)