-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
84 lines (68 loc) · 2.57 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
BINARY_NAME := go-dnscollector
GO_VERSION := $(shell go env GOVERSION | sed -n 's/go\([0-9]\+\.[0-9]\+\).*/\1/p')
GO_LOGGER := 1.1.1
GO_POWERDNS_PROTOBUF := 1.3.0
GO_DNSTAP_PROTOBUF := 1.2.0
GO_FRAMESTREAM := 1.0.1
GO_CLIENTSYSLOG := 1.0.1
GO_TOPMAP := 1.0.2
GO_NETUTILS := 1.5.0
BUILD_TIME := $(shell LANG=en_US date +"%F_%T_%z")
COMMIT := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION ?= $(shell git describe --tags --abbrev=0 ${COMMIT} 2>/dev/null | cut -c2-)
VERSION := $(or $(VERSION),$(COMMIT))
LD_FLAGS ?=
LD_FLAGS += -s -w # disable debug informations
LD_FLAGS += -X github.com/prometheus/common/version.Version=$(VERSION)
LD_FLAGS += -X github.com/prometheus/common/version.Revision=$(COMMIT)
LD_FLAGS += -X github.com/prometheus/common/version.Branch=$(BRANCH)
LD_FLAGS += -X github.com/prometheus/common/version.BuildDate=$(BUILD_TIME)
ifndef $(GOPATH)
GOPATH=$(shell go env GOPATH)
export GOPATH
endif
.PHONY: all check-go dep lint build clean goversion
# This target depends on dep and build.
all: check-go dep build
check-go:
@command -v go > /dev/null 2>&1 || { echo >&2 "Go is not installed. Please install it before proceeding."; exit 1; }
# Displays the Go version.
goversion: check-go
@echo "Go version: $(GO_VERSION)"
# Installs project dependencies.
dep: goversion
@go get github.com/dmachard/go-logger@v$(GO_LOGGER)
@go get github.com/dmachard/go-powerdns-protobuf@v$(GO_POWERDNS_PROTOBUF)
@go get github.com/dmachard/go-dnstap-protobuf@v$(GO_DNSTAP_PROTOBUF)
@go get github.com/dmachard/go-framestream@v$(GO_FRAMESTREAM)
@go get github.com/dmachard/go-clientsyslog@v$(GO_CLIENTSYSLOG)
@go get github.com/dmachard/go-topmap@v$(GO_TOPMAP)
@go get github.com/dmachard/go-netutils@v$(GO_NETUTILS)
@go mod edit -go=$(GO_VERSION)
@go mod tidy
# Builds the project using go build.
build: check-go
CGO_ENABLED=0 go build -v -ldflags="$(LD_FLAGS)" -o ${BINARY_NAME} dnscollector.go
# Builds and runs the project.
run: build
./${BINARY_NAME}
# Builds and runs the project with the -v flag.
version: build
./${BINARY_NAME} -v
# Runs linters.
lint:
$(GOPATH)/bin/golangci-lint run --config=.golangci.yml ./...
# Runs various tests for different packages.
tests: check-go
@go test -race -cover -v
@go test ./pkgconfig/ -race -cover -v
@go test ./pkginit/ -race -cover -v
@go test ./netutils/ -race -cover -v
@go test ./telemetry/ -race -cover -v
@go test -timeout 90s ./transformers/ -race -cover -v
@go test -timeout 180s ./workers/ -race -cover -v
# Cleans the project using go clean.
clean: check-go
@go clean
@rm -f $(BINARY_NAME)