2017-08-03 18:54:05 +00:00
|
|
|
PREFIX := /usr/local
|
2017-06-27 20:24:06 +00:00
|
|
|
VERSION := $(shell git describe --exact-match --tags 2>/dev/null)
|
|
|
|
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
COMMIT := $(shell git rev-parse --short HEAD)
|
2018-02-02 20:25:59 +00:00
|
|
|
GOFILES ?= $(shell git ls-files '*.go')
|
2018-02-01 23:05:39 +00:00
|
|
|
GOFMT ?= $(shell gofmt -l $(GOFILES))
|
|
|
|
|
2015-11-20 22:23:48 +00:00
|
|
|
ifdef GOBIN
|
|
|
|
PATH := $(GOBIN):$(PATH)
|
|
|
|
else
|
|
|
|
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
|
2015-09-10 17:01:08 +00:00
|
|
|
endif
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
TELEGRAF := telegraf$(shell go tool dist env | grep -q 'GOOS=.windows.' && echo .exe)
|
|
|
|
|
2017-08-10 23:33:31 +00:00
|
|
|
LDFLAGS := $(LDFLAGS) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)
|
2017-06-27 20:24:06 +00:00
|
|
|
ifdef VERSION
|
|
|
|
LDFLAGS += -X main.version=$(VERSION)
|
|
|
|
endif
|
|
|
|
|
2017-08-09 18:47:55 +00:00
|
|
|
all:
|
2018-02-01 23:05:39 +00:00
|
|
|
$(MAKE) fmtcheck
|
2017-08-09 18:47:55 +00:00
|
|
|
$(MAKE) deps
|
|
|
|
$(MAKE) telegraf
|
2017-08-03 18:54:05 +00:00
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
ci-test:
|
|
|
|
$(MAKE) deps
|
|
|
|
$(MAKE) fmtcheck
|
|
|
|
$(MAKE) vet
|
|
|
|
$(MAKE) test
|
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
deps:
|
2018-02-01 23:05:39 +00:00
|
|
|
go get -u github.com/golang/lint/golint
|
2017-08-03 18:54:05 +00:00
|
|
|
go get github.com/sparrc/gdm
|
2018-03-14 03:44:51 +00:00
|
|
|
gdm restore --parallel false
|
2017-08-03 18:54:05 +00:00
|
|
|
|
|
|
|
telegraf:
|
2017-08-21 21:44:53 +00:00
|
|
|
go build -i -o $(TELEGRAF) -ldflags "$(LDFLAGS)" ./cmd/telegraf/telegraf.go
|
2015-12-04 18:44:56 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
go-install:
|
2017-08-07 22:47:20 +00:00
|
|
|
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/telegraf
|
2016-01-29 18:02:54 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
install: telegraf
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin/
|
|
|
|
cp $(TELEGRAF) $(DESTDIR)$(PREFIX)/bin/
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
test:
|
|
|
|
go test -short ./...
|
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
fmt:
|
|
|
|
@gofmt -w $(GOFILES)
|
|
|
|
|
|
|
|
fmtcheck:
|
|
|
|
@echo '[INFO] running gofmt to identify incorrectly formatted code...'
|
|
|
|
@if [ ! -z $(GOFMT) ]; then \
|
|
|
|
echo "[ERROR] gofmt has found errors in the following files:" ; \
|
|
|
|
echo "$(GOFMT)" ; \
|
|
|
|
echo "" ;\
|
|
|
|
echo "Run make fmt to fix them." ; \
|
|
|
|
exit 1 ;\
|
|
|
|
fi
|
|
|
|
@echo '[INFO] done.'
|
|
|
|
|
|
|
|
lint:
|
|
|
|
golint ./...
|
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
test-windows:
|
|
|
|
go test ./plugins/inputs/ping/...
|
|
|
|
go test ./plugins/inputs/win_perf_counters/...
|
2017-08-07 21:36:15 +00:00
|
|
|
go test ./plugins/inputs/win_services/...
|
2018-02-01 23:14:27 +00:00
|
|
|
go test ./plugins/inputs/procstat/...
|
2017-08-03 18:54:05 +00:00
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
# vet runs the Go source code static analysis tool `vet` to find
|
|
|
|
# any common errors.
|
|
|
|
vet:
|
|
|
|
@echo 'go vet $$(go list ./...)'
|
|
|
|
@go vet $$(go list ./...) ; if [ $$? -eq 1 ]; then \
|
|
|
|
echo ""; \
|
|
|
|
echo "go vet has found suspicious constructs. Please remediate any reported errors"; \
|
|
|
|
echo "to fix them before submitting code for review."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
test-all: vet
|
2017-08-03 18:54:05 +00:00
|
|
|
go test ./...
|
2015-12-21 19:49:56 +00:00
|
|
|
|
2016-02-18 04:57:33 +00:00
|
|
|
package:
|
2017-09-22 23:49:28 +00:00
|
|
|
./scripts/build.py --package --platform=all --arch=all
|
2017-11-07 21:54:36 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
clean:
|
2018-02-01 23:05:39 +00:00
|
|
|
rm -f telegraf
|
|
|
|
rm -f telegraf.exe
|
2016-01-29 18:02:54 +00:00
|
|
|
|
2017-09-22 23:49:28 +00:00
|
|
|
docker-image:
|
|
|
|
./scripts/build.py --package --platform=linux --arch=amd64
|
|
|
|
cp build/telegraf*$(COMMIT)*.deb .
|
|
|
|
docker build -f scripts/dev.docker --build-arg "package=telegraf*$(COMMIT)*.deb" -t "telegraf-dev:$(COMMIT)" .
|
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
.PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck
|