telegraf/Makefile

100 lines
2.4 KiB
Makefile
Raw Normal View History

2017-08-03 18:54:05 +00:00
PREFIX := /usr/local
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)
GOFILES ?= $(shell git ls-files '*.go')
2018-02-01 23:05:39 +00:00
GOFMT ?= $(shell gofmt -l $(GOFILES))
ifdef GOBIN
PATH := $(GOBIN):$(PATH)
else
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
endif
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)
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 18:36:03 +00:00
gdm restore
2017-08-03 18:54:05 +00:00
telegraf:
go build -i -o $(TELEGRAF) -ldflags "$(LDFLAGS)" ./cmd/telegraf/telegraf.go
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
2017-08-03 18:54:05 +00:00
install: telegraf
mkdir -p $(DESTDIR)$(PREFIX)/bin/
cp $(TELEGRAF) $(DESTDIR)$(PREFIX)/bin/
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/...
go test ./plugins/inputs/win_services/...
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 ./...
package:
./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
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