-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
127 lines (109 loc) · 4.38 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------------------------------
################################################################################
# Variables #
################################################################################
export GO111MODULE ?= on
export GOPROXY ?= https://proxy.golang.org
export GOSUMDB ?= sum.golang.org
GIT_COMMIT = $(shell git rev-list -1 HEAD)
GIT_VERSION = $(shell git describe --always --abbrev=7 --dirty)
CGO ?= 0
CLI_BINARY = dapr
ifdef REL_VERSION
CLI_VERSION := $(REL_VERSION)
else
CLI_VERSION := edge
endif
ifdef API_VERSION
RUNTIME_API_VERSION = $(API_VERSION)
else
RUNTIME_API_VERSION = 1.0
endif
LOCAL_ARCH := $(shell uname -m)
ifeq ($(LOCAL_ARCH),x86_64)
TARGET_ARCH_LOCAL = amd64
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
TARGET_ARCH_LOCAL = arm64
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
TARGET_ARCH_LOCAL = arm
else
TARGET_ARCH_LOCAL = amd64
endif
export GOARCH ?= $(TARGET_ARCH_LOCAL)
LOCAL_OS := $(shell uname)
ifeq ($(LOCAL_OS),Linux)
TARGET_OS_LOCAL = linux
GOLANGCI_LINT:=golangci-lint
export ARCHIVE_EXT = .tar.gz
else ifeq ($(LOCAL_OS),Darwin)
TARGET_OS_LOCAL = darwin
GOLANGCI_LINT:=golangci-lint
export ARCHIVE_EXT = .tar.gz
else
TARGET_OS_LOCAL ?= windows
BINARY_EXT_LOCAL = .exe
GOLANGCI_LINT:=golangci-lint.exe
export ARCHIVE_EXT = .zip
endif
export GOOS ?= $(TARGET_OS_LOCAL)
export BINARY_EXT ?= $(BINARY_EXT_LOCAL)
# Use the variable H to add a header (equivalent to =>) to informational output
H = $(shell printf "\033[34;1m=>\033[0m")
ifeq ($(origin DEBUG), undefined)
BUILDTYPE_DIR:=release
else ifeq ($(DEBUG),0)
BUILDTYPE_DIR:=release
else
BUILDTYPE_DIR:=debug
GCFLAGS:=-gcflags="all=-N -l"
$(info $(H) Build with debugger information)
endif
################################################################################
# Go build details #
################################################################################
BASE_PACKAGE_NAME := github.com/dapr/cli
OUT_DIR := ./dist
BINS_OUT_DIR := $(OUT_DIR)/$(GOOS)_$(GOARCH)/$(BUILDTYPE_DIR)
LDFLAGS := "-X main.version=$(CLI_VERSION) -X main.apiVersion=$(RUNTIME_API_VERSION)"
################################################################################
# Target: build #
################################################################################
.PHONY: build
build: $(CLI_BINARY)
$(CLI_BINARY):
CGO_ENABLED=$(CGO) GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GCFLAGS) -ldflags $(LDFLAGS) \
-o $(BINS_OUT_DIR)/$(CLI_BINARY)$(BINARY_EXT);
################################################################################
# Target: lint #
################################################################################
# Due to https://github.com/golangci/golangci-lint/issues/580, we need to add --fix for windows
.PHONY: lint
lint:
$(GOLANGCI_LINT) run --fix
################################################################################
# Target: archive #
################################################################################
ARCHIVE_OUT_DIR ?= $(BINS_OUT_DIR)
archive: archive-$(CLI_BINARY)$(ARCHIVE_EXT)
ifeq ($(GOOS),windows)
archive-$(CLI_BINARY).zip:
7z.exe a -tzip "$(ARCHIVE_OUT_DIR)\\$(CLI_BINARY)_$(GOOS)_$(GOARCH)$(ARCHIVE_EXT)" "$(BINS_OUT_DIR)\\$(CLI_BINARY)$(BINARY_EXT)"
else
archive-$(CLI_BINARY).tar.gz:
chmod +x $(BINS_OUT_DIR)/$(CLI_BINARY)$(BINARY_EXT)
tar czf "$(ARCHIVE_OUT_DIR)/$(CLI_BINARY)_$(GOOS)_$(GOARCH)$(ARCHIVE_EXT)" -C "$(BINS_OUT_DIR)" "$(CLI_BINARY)$(BINARY_EXT)"
endif
################################################################################
# Target: release #
################################################################################
.PHONY: release
release: build archive
################################################################################
# Tests #
################################################################################
.PHONY: test
test:
go test ./pkg/...