-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMakefile
75 lines (56 loc) · 1.77 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
#!/usr/bin/make -f
GOCMD = go
GOBUILD = $(GOCMD) build
GOMOD = $(GOCMD) mod
VERSION := $(shell echo $(shell git describe --always) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
BUILDDIR ?= $(CURDIR)/build
export GO111MODULE = on
build_tags = netgo
ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
UNIX=netcat
WINDOWS=netcat.exe
PACKAGENAME=main
### -X package.name
ldflags = -X $(PACKAGENAME).Name=$(UNIX) \
-X $(PACKAGENAME).Version=$(VERSION) \
-X $(PACKAGENAME).Commit=$(COMMIT) \
-X $(PACKAGENAME).BuildTags=$(build_tags_comma_sep) \
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags) -s -w'
GOMODCACHE := $(shell go env |grep GOMODCACHE|sed 's/GOMODCACHE=//'|tr -d '"')
BUILD_FLAGS += -gcflags='all=-trimpath=${PWD}' -asmflags='all=-trimpath=${PWD}'
BUILD_FLAGS += -gcflags='all=-trimpath=$(GOMODCACHE)' -asmflags='all=-trimpath=$(GOMODCACHE)'
# darwin amd64
build: gofmt clean go.sum
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/$(UNIX)
# linux amd64
build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build
# linux arm64
build-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) build
# windows
build-windows: gofmt clean go.sum
mkdir -p $(BUILDDIR)
GOOS=windows GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/$(WINDOWS)
install: go.sum
go install -mod=readonly -v $(BUILD_FLAGS)
install-debug: go.sum
go install -mod=readonly $(BUILD_FLAGS)
clean:
rm -rf build/
gofmt:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -w -s
go.sum: go.mod
@go mod verify
@go mod tidy
.PHONY: build