-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
99 lines (82 loc) · 2.96 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
EXTENSION ?=
DIST_DIR ?= dist/
GOOS ?= linux
GOARCH ?= x86_64
ARCH ?= $(GOARCH)
BUILDINFOSDET ?=
DOCKER_REPO := rpki/
STAYRTR_NAME := stayrtr
STAYRTR_VERSION := $(shell git describe --tags $(git rev-list --tags --max-count=1))
VERSION_PKG := $(shell echo $(STAYRTR_VERSION) | sed 's/^v//g')
LICENSE := BSD-3
URL := https://github.com/bgp/stayrtr
DESCRIPTION := StayRTR: a RPKI-to-Router server
BUILDINFOS := ($(shell date +%FT%T%z)$(BUILDINFOSDET))
LDFLAGS ?= '-X main.version=$(STAYRTR_VERSION) -X main.buildinfos=$(BUILDINFOS)'
RTRDUMP_NAME := rtrdump
RTRMON_NAME := rtrmon
SUFFIX ?= -$(STAYRTR_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)
OUTPUT_STAYRTR := $(DIST_DIR)stayrtr$(SUFFIX)
OUTPUT_RTRDUMP := $(DIST_DIR)rtrdump$(SUFFIX)
OUTPUT_RTRMON := $(DIST_DIR)rtrmon$(SUFFIX)
export CGO_ENABLED ?= 0
.PHONY: build-all
build-all: vet build-stayrtr build-rtrdump build-rtrmon
.PHONY: vet
vet:
go vet cmd/stayrtr/stayrtr.go
.PHONY: test
test:
go test -v github.com/bgp/stayrtr/lib
go test -v github.com/bgp/stayrtr/prefixfile
go test -v github.com/bgp/stayrtr/cmd/rtrmon
go test -v github.com/bgp/stayrtr/cmd/stayrtr
.PHONY: prepare
prepare:
mkdir -p $(DIST_DIR)
.PHONY: clean
clean:
rm -rf $(DIST_DIR)
.PHONY: build-stayrtr
build-stayrtr: prepare
go build -trimpath -ldflags $(LDFLAGS) -o $(OUTPUT_STAYRTR) cmd/stayrtr/stayrtr.go
.PHONY: build-rtrdump
build-rtrdump:
go build -trimpath -ldflags $(LDFLAGS) -o $(OUTPUT_RTRDUMP) cmd/rtrdump/rtrdump.go
.PHONY: build-rtrmon
build-rtrmon:
go build -trimpath -ldflags $(LDFLAGS) -o $(OUTPUT_RTRMON) cmd/rtrmon/rtrmon.go
.PHONY: docker
docker:
docker build -t $(DOCKER_REPO)$(STAYRTR_NAME) --target stayrtr .
docker build -t $(DOCKER_REPO)$(RTRDUMP_NAME) --target rtrdump .
docker build -t $(DOCKER_REPO)$(RTRMON_NAME) --target rtrmon .
.PHONY: package-deb-stayrtr
package-deb-stayrtr: prepare
fpm -s dir -t deb -n $(STAYRTR_NAME) -v $(VERSION_PKG) \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE)" \
--package $(DIST_DIR) \
--after-install package/after-install-debian.sh \
package/.keep=/usr/share/stayrtr/.keep \
$(OUTPUT_STAYRTR)=/usr/bin/stayrtr \
package/stayrtr.service=/lib/systemd/system/stayrtr.service \
package/stayrtr.env=/etc/default/stayrtr \
$(OUTPUT_RTRDUMP)=/usr/bin/rtrdump \
$(OUTPUT_RTRMON)=/usr/bin/rtrmon
.PHONY: package-rpm-stayrtr
package-rpm-stayrtr: prepare
fpm -s dir -t rpm -n $(STAYRTR_NAME) -v $(VERSION_PKG) \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE) "\
$(OUTPUT_STAYRTR)=/usr/bin/stayrtr \
package/.keep=/usr/share/stayrtr/.keep \
package/stayrtr.service=/lib/systemd/system/stayrtr.service \
package/stayrtr.env=/etc/default/stayrtr \
$(OUTPUT_RTRDUMP)=/usr/bin/rtrdump \
$(OUTPUT_RTRMON)=/usr/bin/rtrmon
mv *.rpm dist/ # It's unclear why we need to do this, but i assume it's a FPM bug.