-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
76 lines (61 loc) · 2.12 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
GO=go
GOARCH ?= amd64
GOFMT=gofmt
DELETE=rm
BINARY=pryrite
OS_BINARY=$(BINARY)
BIN_DIR=bin
BUILD_BINARY=$(BIN_DIR)/$(BINARY)
# go source files, ignore vendor directory
SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
# current git version short-hash
VER := $(shell git rev-parse --short HEAD)
WATCH := (.go$$)
ifeq ($(GOOS),windows)
OS_BINARY := $(OS_BINARY).exe
BUILD_BINARY := $(BUILD_BINARY).exe
endif
word-dot = $(word $2,$(subst ., ,$1))
MAJMINPATVER := $(shell cat version.txt)
MAJMINVER := $(call word-dot,$(MAJMINPATVER),1).$(call word-dot,$(MAJMINPATVER),2)
PATVER := $(call word-dot,$(MAJMINPATVER),3)
info:
@echo " target ⾖ Description. "
@echo " ----------------------------------------------------------------- "
@echo
@echo " build generate a local build ⇨ $(BUILD_BINARY) "
@echo " clean clean up bin/ & go test cache "
@echo " fmt format go code files using go fmt "
@echo " release/darwin generate a darwin target build "
@echo " release/linux generate a linux target build "
@echo
@echo " ------------------------------------------------------------------"
rebuild: clean build
build: fmt
$(GO) build -o $(BUILD_BINARY) -v main.go
.PHONY: clean
clean:
$(DELETE) -rf bin/ public/ zips/
$(GO) clean -cache
.PHONY: fmt
fmt:
$(GOFMT) -l -w $(SRC)
release:
$(MAKE) release/linux GOARCH=amd64 & \
$(MAKE) release/linux GOARCH=arm64 & \
$(MAKE) release/linux GOARCH=arm & \
$(MAKE) release/darwin & \
wait
bindir = bin/$(subst release/,,$1)-$(GOARCH)
release/%: fmt
@echo "build GOOS: $(subst release/,,$@) & GOARCH: $(GOARCH)"
GOOS=$(subst release/,,$@) GOARCH=$(GOARCH) $(GO) build -ldflags="-s -w" -o $(call bindir,$@)/$(OS_BINARY) -v main.go
mkdir -p zips
zip -j zips/$(BINARY)-$(subst release/,,$@)-$(GOARCH).zip README.md $(call bindir,$@)/*
.PHONY: test
test: build
$(GO) test -race ./...
.PHONY: test
coverage: build
$(GO) test -covermode=atomic --race -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out