-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.defs
More file actions
111 lines (85 loc) · 2.64 KB
/
Copy pathMakefile.defs
File metadata and controls
111 lines (85 loc) · 2.64 KB
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
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
RELATIVE_DIR := $(shell echo $(realpath .) | sed "s;$(ROOT_DIR)[/]*;;")
include $(ROOT_DIR)/Makefile.quiet
include $(ROOT_DIR)/Makefile.function
INSTALL = install
PREFIX?=/opt/kcrow
BINDIR?=$(PREFIX)/bin
BUILD_PLATFORMS ?= linux/amd64 linux/arm64
#----------image--------
CONTAINER_ENGINE ?= docker buildx
REGISTER ?= ghcr.io
GIT_REPO ?= kcrow-io/plugins
IMAGE_TAG ?=
CONTROLLER_IMAGE_NAME := ${REGISTER}/${GIT_REPO}
IMAGE_PLATFORMS ?= $(call join-with-comma,$(BUILD_PLATFORMS))
IMAGE ?= ${CONTROLLER_IMAGE_NAME}
ifeq ($(IMAGE_TAG),)
IMAGE_TAG := latest
endif
#-----------Golang-------
GO ?= go
GO_BUILD_FLAGS =
GO_TEST_FLAGS =
GO_CLEAN_FLAGS =
GO_BUILD_TIME = $(shell date "+%Y-%m-%d@%H:%M:%S")
GO_BUILD_LDFLAGS =
# go build/test -tags values
GO_TAGS_FLAGS = osusergo
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPROXY ?= $(shell go env GOPROXY)
# This is declared here as it is needed to change the covermode depending on if
# RACE is specified.
GOTEST_COVER_OPTS =
#strip binary
ifeq ($(NOSTRIP),)
# Note: these options will not remove annotations needed for stack
# traces, so panic backtraces will still be readable.
#
# -w: Omit the DWARF symbol table.
# -s: Omit the symbol table and debug information.
GO_BUILD_LDFLAGS += -s -w
endif
# Using go modules directly
GO_BUILD_FLAGS += -mod=mod
GO_TEST_FLAGS += -mod=mod
GO_CLEAN_FLAGS += -mod=mod
GO_BUILD = CGO_ENABLED=0 $(GO) build
# Currently crosscompiling only enabled for arm64 targets
CGO_CC =
ifeq ($(GOARCH),arm64)
CGO_CC = CC=aarch64-linux-gnu-gcc
endif
GO_BUILD_WITH_CGO = CGO_ENABLED=1 $(CGO_CC) $(GO) build
#data race and lock debug
ifeq ($(RACE),"1")
GO_BUILD_FLAGS += -race
GO_TEST_FLAGS += -race
GOTEST_COVER_OPTS += -covermode=atomic
# GO_BUILD becomes GO_BUILD_WITH_CGO as `-race` requires CGO
GO_BUILD = $(GO_BUILD_WITH_CGO)
ifeq ($(LOCKDEBUG),)
LOCKDEBUG=1
endif
else
GOTEST_COVER_OPTS += -covermode=count
endif
ifneq ($(LOCKDEBUG),)
GO_TAGS_FLAGS += lockdebug
endif
GO_BUILD_FLAGS += -ldflags '$(GO_BUILD_LDFLAGS) $(EXTRA_GO_BUILD_LDFLAGS)' -tags=$(call join-with-comma,$(GO_TAGS_FLAGS)) $(EXTRA_GO_BUILD_FLAGS)
GO_TEST_FLAGS += -tags=$(call join-with-comma,$(GO_TAGS_FLAGS))
#no optimize for binary
ifeq ($(NOOPT),1)
GO_BUILD_FLAGS += -gcflags="all=-N -l"
endif
GO_BUILD += $(GO_BUILD_FLAGS)
GO_BUILD_WITH_CGO += $(GO_BUILD_FLAGS)
GO_TEST = $(GO) test $(GO_TEST_FLAGS)
GO_CLEAN = $(GO) clean $(GO_CLEAN_FLAGS)
GO_VET = $(GO) vet
GO_LIST = $(GO) list
GO_MOD_TIDY = $(GO) mod tidy