-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
50 lines (37 loc) · 1.11 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
VERSION_GO = version.go
MAIN_GO = cmd/main.go
_NAME = $(shell grep -o 'AppName string = "[^"]*"' $(VERSION_GO) | cut -d '"' -f2)
_VERSION = $(shell grep -oE 'Version string = "[0-9]+\.[0-9]+\.[0-9]+"' $(VERSION_GO) | cut -d '"' -f2)
_GOOS = darwin
_GOARCH = amd64
deps:
go mod download
pkg-build = GOOS=$(1) GOARCH=$(2) go build -o pkg/$(3)_$(1)_$(2)-$(_VERSION) $(4)
pkg-build-main = $(call pkg-build,$(1),$(2),$(_NAME),$(MAIN_GO))
zip = cp pkg/$(3)_$(1)_$(2)-$(_VERSION) pkg/$(3) && zip -j pkg/$(3)_$(1)_$(2)-$(_VERSION).zip pkg/$(3) && rm pkg/$(3)
zip-main = $(call zip,$(1),$(2),$(_NAME))
pre-pkg:
mkdir -p pkg
pkg-linux-amd64:
$(call pkg-build-main,linux,amd64)
$(call zip-main,linux,amd64)
pkg-darwin-amd64:
$(call pkg-build-main,darwin,amd64)
$(call zip-main,darwin,amd64)
.PHONY: build
build:
GOOS=$(_GOOS) GOARCH=$(_GOARCH) go build -trimpath -o $(_NAME) $(MAIN_GO)
.PHONY: test
test:
go test -v ./...
.PHONY: install
install: deps
go install
.PHONY: pkg
pkg: deps pre-pkg \
pkg-linux-amd64 \
pkg-darwin-amd64
.PHONY: clean
clean:
rm -f $(_NAME)
rm -f pkg/*