-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
81 lines (67 loc) · 2.22 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
PROJ_NAME = gndiff
VERSION = $(shell git describe --tags)
VER = $(shell git describe --tags --abbrev=0)
DATE = $(shell date -u '+%Y-%m-%d_%H:%M:%S%Z')
FLAGS_INTEL64 = GOARCH=amd64
NO_C = CGO_ENABLED=0
FLAGS_LINUX = $(FLAGS_INTEL64) GOOS=linux
FLAGS_MAC = $(FLAGS_INTEL64) GOOS=darwin
FLAGS_MAC_ARM = $GOARCH=arm64 GOOS=darwin
FLAGS_WIN = $(FLAGS_INTEL64) 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)"
GOCMD = go
GOBUILD = $(GOCMD) build $(FLAGS_LD)
GORELEASE = $(GOCMD) build $(FLAGS_REL)
GOINSTALL = $(GOCMD) install $(FLAGS_LD)
GOCLEAN = $(GOCMD) clean
GOGET = $(GOCMD) get
RELEASE_DIR ?= "/tmp"
BUILD_DIR ?= "."
all: install
test: deps install
@echo Run tests
$(GOCMD) test -shuffle=on -count=1 -race -coverprofile=coverage.txt ./...
test-build: deps build
deps:
@echo Download go.mod dependencies
$(GOCMD) mod download;
tools: deps
@echo Installing tools from tools.go
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
build:
@echo Building
$(GOCLEAN); \
$(FLAGS_SHARED) $(NO_C) $(GOBUILD) -o $(BUILD_DIR)
buildrel:
@echo Building release binary
$(GOCLEAN); \
$(NO_C) $(GORELEASE) -o $(BUILD_DIR);
install:
$(GOCLEAN); \
$(FLAGS_SHARED) $(NO_C) $(GOINSTALL)
release: dockerhub
@echo Make release
$(GOCLEAN); \
$(FLAGS_LINUX) $(NO_C) $(GOBUILD); \
tar zcf $(RELEASE_DIR)/$(PROJ_NAME)-$(VER)-linux.tar.gz $(PROJ_NAME); \
$(GOCLEAN); \
$(FLAGS_MAC) $(NO_C) $(GOBUILD); \
tar zcf $(RELEASE_DIR)/$(PROJ_NAME)-$(VER)-mac.tar.gz $(PROJ_NAME); \
$(GOCLEAN); \
$(FLAGS_MAC_ARM) $(NO_C) $(GOBUILD); \
tar zcf $(RELEASE_DIR)/$(PROJ_NAME)-$(VER)-mac-arm64.tar.gz $(PROJ_NAME); \
$(GOCLEAN); \
$(FLAGS_WIN) $(NO_C) $(GOBUILD); \
zip -9 $(RELEASE_DIR)/$(PROJ_NAME)-$(VER)-win-64.zip $(PROJ_NAME).exe; \
$(GOCLEAN);
docker: buildrel
@echo Build Docker images
docker buildx build -t gnames/$(PROJ_NAME):latest -t gnames/$(PROJ_NAME):$(VERSION) .; \
$(GOCLEAN);
dockerhub: docker
@echo Push Docker images to DockerHub
docker push gnames/$(PROJ_NAME); \
docker push gnames/$(PROJ_NAME):$(VERSION)