-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (37 loc) · 1.52 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
VERSION ?= $(shell git describe --tags || echo "unknown")
NAME ?= jki
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT := $(shell git rev-parse HEAD)
GO_LDFLAGS ?= "-w -s -X github.com/iftechio/jki/pkg/info.BuildDate=$(BUILD_DATE) \
-X github.com/iftechio/jki/pkg/info.GitCommit=$(GIT_COMMIT) \
-X github.com/iftechio/jki/pkg/info.Version=$(VERSION)"
GOBUILD = CGO_ENABLED=0 go build -trimpath -ldflags $(GO_LDFLAGS)
.PHONY: all
all:
$(GOBUILD) -o "$(NAME)_$(VERSION)_$(OS)_$(ARCH)/$(NAME)"
@tar czf "$(NAME)_$(VERSION)_$(OS)_$(ARCH).tar.gz" "$(NAME)_$(VERSION)_$(OS)_$(ARCH)"
.PHONY: linux_amd64 linux_arm64 darwin_amd64 darwin_arm64 releases
linux_amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME)
tar czf "$(NAME)_$(VERSION)[email protected]" "$(NAME)_$(VERSION)_$@"
linux_arm64:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME)
tar czf "$(NAME)_$(VERSION)[email protected]" "$(NAME)_$(VERSION)_$@"
darwin_amd64:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME)
tar czf "$(NAME)_$(VERSION)[email protected]" "$(NAME)_$(VERSION)_$@"
darwin_arm64:
GOARCH=arm64 GOOS=darwin $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME)
tar czf "$(NAME)_$(VERSION)[email protected]" "$(NAME)_$(VERSION)_$@"
releases: linux_amd64 linux_arm64 darwin_amd64 darwin_arm64
.PHONY: install
install:
@go install -trimpath -ldflags $(GO_LDFLAGS)
.PHONY: debug
debug:
@go build -trimpath -ldflags $(GO_LDFLAGS) -o jki
.PHONY: clean
clean:
rm -rf jki_*