-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
121 lines (96 loc) · 2.95 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
BUILD_REQUIRE_GO_MAJOR ?= 1
BUILD_REQUIRE_GO_MINOR ?= 20
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
BINARY_NAME=crowdsec-cloudflare-bouncer
TARBALL_NAME=$(BINARY_NAME).tgz
# Versioning information can be overridden in the environment
BUILD_VERSION?=$(shell git describe --tags)
BUILD_TIMESTAMP?=$(shell date +%F"_"%T)
BUILD_TAG?=$(shell git rev-parse HEAD)
LD_OPTS_VARS=\
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Tag=$(BUILD_TAG)'
export CGO_ENABLED=0
export LD_OPTS=-ldflags "-a -s -w -extldflags '-static' $(LD_OPTS_VARS)" \
-trimpath -tags netgo
.PHONY: all
all: build test
# same as "$(MAKE) -f debian/rules clean" but without the dependency on debhelper
.PHONY: clean-debian
clean-debian:
@$(RM) -r debian/$(BINARY_NAME)
@$(RM) -r debian/files
@$(RM) -r debian/.debhelper
@$(RM) -r debian/*.substvars
@$(RM) -r debian/*-stamp
.PHONY: clean-rpm
clean-rpm:
@$(RM) -r rpm/BUILD
@$(RM) -r rpm/BUILDROOT
@$(RM) -r rpm/RPMS
@$(RM) -r rpm/SOURCES/*.tar.gz
@$(RM) -r rpm/SRPMS
# Remove everything including all platform binaries and tarballs
.PHONY: clean
clean: clean-release-dir clean-debian clean-rpm
@$(RM) $(BINARY_NAME)
@$(RM) $(TARBALL_NAME)
@$(RM) -r $(BINARY_NAME)-* # platform binary name and leftover release dir
@$(RM) $(BINARY_NAME)-*.tgz # platform release file
#
# Build binaries
#
.PHONY: binary
binary: goversion
$(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME)
.PHONY: build-worker-js
build-worker-js:
@cd pkg/cf/worker && npm install && npm run build
.PHONY: build
build: clean build-worker-js binary
.PHONY: lint
lint:
golangci-lint run
.PHONY: test
test: goversion
@$(GOTEST) $(LD_OPTS) ./...
RELDIR = $(BINARY_NAME)-$(BUILD_VERSION)
.PHONY: vendor
vendor:
$(GOCMD) mod vendor
tar czf vendor.tgz vendor
.PHONY: vendor-remove
vendor-remove:
$(RM) -r vendor vendor.tgz
# Called during platform-all, to reuse the directory for other platforms
.PHONY: clean-release-dir
clean-release-dir:
@$(RM) -r $(RELDIR)
.PHONY: tarball
tarball: binary
@if [ -z $(BUILD_VERSION) ]; then BUILD_VERSION="local" ; fi
@if [ -d $(RELDIR) ]; then echo "$(RELDIR) already exists, please run 'make clean' and retry" ; exit 1 ; fi
@echo Building Release to dir $(RELDIR)
@mkdir -p $(RELDIR)/scripts
@cp $(BINARY_NAME) $(RELDIR)/
@cp -R ./config $(RELDIR)/
@cp ./scripts/install.sh $(RELDIR)/
@cp ./scripts/uninstall.sh $(RELDIR)/
@cp ./scripts/upgrade.sh $(RELDIR)/
@cp ./scripts/_bouncer.sh $(RELDIR)/scripts/
@chmod +x $(RELDIR)/install.sh
@chmod +x $(RELDIR)/uninstall.sh
@chmod +x $(RELDIR)/upgrade.sh
@tar cvzf $(TARBALL_NAME) $(RELDIR)
.PHONY: release
release: clean tarball
#
# Build binaries and release tarballs for all platforms
#
.PHONY: platform-all
platform-all: goversion clean
python3 .github/release.py run-build $(BINARY_NAME)
include mk/goversion.mk