-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
50 lines (42 loc) · 1.35 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
NAME = wgcf-cli
MAIN = ./cmd/wgcf-cli
VERSION ?= v$(shell git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-\([^-]*\)-\([^-]*\)$$/.\1.\2/;s/-//')
export GOOS ?= $(shell go env GOOS)
export GOARCH ?= $(shell go env GOARCH)
export GOARM ?= $(shell go env GOARM)
export CGO_ENABLED ?= $(shell go env CGO_ENABLED)
BUILD_MODE = -buildmode=pie
ifeq ($(CGO_ENABLED),1)
LDFLAG_LINKMODE = -linkmode=external
else
LDFLAG_LINKMODE =
# armv7, riscv64, s390x, x86
ifeq ($(shell if [ "$(GOOS)" = "linux" ] && ([ "$(GOARCH)" = "386" ] || [ "$(GOARCH)" = "riscv64" ] || [ "$(GOARCH)" = "s390x" ] || ([ "$(GOARCH)" = "arm" ] && [ "$(GOARM)" = "7" ])); then echo true; fi) ,true)
BUILD_MODE = -buildmode=exe
endif
endif
TAGS ?=
LDFLAGS = -X github.com/ArchiveNetwork/wgcf-cli/constant.Version=$(VERSION) -s -w -buildid= $(LDFLAG_LINKMODE)
GOFLAGS ?= -trimpath $(BUILD_MODE) -tags=$(TAGS) -mod=readonly -modcacherw -v -ldflags "$(LDFLAGS)"
ifeq ($(shell if [ "$(GOOS)" = "windows" ]; then echo true; fi),true)
OUTPUT = $(NAME).exe
else
OUTPUT = $(NAME)
endif
ifdef completion
all: completion
else
all: $(NAME)
endif
.PHONY: clean completion
$(NAME): $(MAIN)
go build -o $(OUTPUT) \
$(GOFLAGS) \
$(MAIN)
clean:
go clean -v -i $(MAIN)
rm -f $(OUTPUT)
completion:
@$(MAKE) $(NAME) 2>&1 >/dev/null
@PATH=$(PATH):$(shell realpath ./)
@$(NAME) completion $(completion)