|
1 |
| - |
2 |
| -COVERDIR = .coverage |
3 |
| -TOOLDIR = tools |
4 |
| -BINDIR = bin |
5 |
| -RELEASEDIR = release |
6 |
| - |
7 |
| -DIRS = $(BINDIR) $(RELEASEDIR) |
8 |
| - |
9 |
| -GO_SRC := $(shell find . -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' ! -path 'bin/*' ! -path 'release/*' ) |
10 |
| -GO_DIRS := $(shell find . -type d -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' ! -path 'bin/*' ! -path 'release/*' ) |
11 |
| -GO_PKGS := $(shell go list ./... | grep -v '/vendor/') |
12 |
| - |
13 |
| -CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest |
14 |
| -BINARY := $(shell basename $(shell pwd)) |
15 |
| -VERSION ?= $(shell git describe --dirty 2>/dev/null) |
16 |
| -VERSION_SHORT ?= $(shell git describe --abbrev=0 2>/dev/null) |
17 |
| - |
18 |
| -ifeq ($(VERSION),) |
19 |
| -VERSION := v0.0.0 |
20 |
| -endif |
21 |
| - |
22 |
| -ifeq ($(VERSION_SHORT),) |
23 |
| -VERSION_SHORT := v0.0.0 |
24 |
| -endif |
25 |
| - |
26 |
| -# By default this list is filtered down to some common platforms. |
27 |
| -platforms := $(subst /,-,$(shell go tool dist list | grep -e linux -e windows -e darwin | grep -e 386 -e amd64)) |
28 |
| -PLATFORM_BINS_TMP := $(patsubst %,$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%/$(BINARY),$(platforms)) |
29 |
| -PLATFORM_BINS := $(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY),$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY).exe,$(PLATFORM_BINS_TMP)) |
30 |
| -PLATFORM_DIRS := $(patsubst %,$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%,$(platforms)) |
31 |
| -PLATFORM_TARS := $(patsubst %,$(RELEASEDIR)/$(BINARY)_$(VERSION_SHORT)_%.tar.gz,$(platforms)) |
32 |
| - |
33 |
| -# These are evaluated on use, and so will have the correct values in the build |
34 |
| -# rule (https://vic.demuzere.be/articles/golang-makefile-crosscompile/) |
35 |
| -PLATFORMS_TEMP = $(subst /, ,$(subst -, ,$(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%,%,$@))) |
36 |
| -GOOS = $(word 1, $(PLATFORMS_TEMP)) |
37 |
| -GOARCH = $(word 2, $(PLATFORMS_TEMP)) |
38 |
| - |
39 |
| -CURRENT_PLATFORM_TMP := $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_$(shell go env GOOS)-$(shell go env GOARCH)/$(BINARY) |
40 |
| -CURRENT_PLATFORM := $(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY),$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY).exe,$(CURRENT_PLATFORM_TMP)) |
41 |
| - |
42 |
| -CONCURRENT_LINTERS ?= |
43 |
| -ifeq ($(CONCURRENT_LINTERS),) |
44 |
| -CONCURRENT_LINTERS = $(shell gometalinter --help | grep -o 'concurrency=\w*' | cut -d= -f2 | cut -d' ' -f1) |
45 |
| -endif |
46 |
| - |
47 |
| -LINTER_DEADLINE ?= 30s |
48 |
| - |
49 |
| -$(shell mkdir -p $(DIRS)) |
50 |
| - |
51 |
| -export PATH := $(TOOLDIR)/bin:$(PATH) |
52 |
| -SHELL := env PATH=$(PATH) /bin/bash |
53 |
| - |
54 |
| -all: style lint test binary |
55 |
| - |
56 |
| -binary: $(BINARY) |
57 |
| - |
58 |
| -$(BINARY): $(CURRENT_PLATFORM) |
59 |
| - ln -sf $< $@ |
60 |
| - |
61 |
| -$(PLATFORM_BINS): $(GO_SRC) |
62 |
| - CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -a \ |
63 |
| - -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" \ |
64 |
| - -o $@ . |
65 |
| - |
66 |
| -$(PLATFORM_DIRS): $(PLATFORM_BINS) |
67 |
| - |
68 |
| -$(PLATFORM_TARS): $(RELEASEDIR)/%.tar.gz : $(BINDIR)/% |
69 |
| - tar -czf $@ -C $(BINDIR) $$(basename $<) |
70 |
| - |
71 |
| -release-bin: $(PLATFORM_BINS) |
72 |
| - |
73 |
| -release: $(PLATFORM_TARS) |
74 |
| - |
75 |
| -# Take a go build and turn it into a minimal container |
76 |
| -docker: $(CURRENT_PLATFORM) |
77 |
| - docker build --build-arg=binary=$(CURRENT_PLATFORM) -t $(CONTAINER_NAME) . |
78 |
| - |
79 |
| -style: tools |
80 |
| - gometalinter --disable-all --enable=gofmt --vendor |
81 |
| - |
82 |
| -lint: tools |
83 |
| - @echo Using $(CONCURRENT_LINTERS) processes |
84 |
| - gometalinter -j $(CONCURRENT_LINTERS) --deadline=$(LINTER_DEADLINE) --disable=gotype --disable=gocyclo $(GO_DIRS) |
85 |
| - |
86 |
| -fmt: tools |
87 |
| - gofmt -s -w $(GO_SRC) |
88 |
| - |
89 |
| -postgres_exporter_integration_test: $(GO_SRC) |
90 |
| - CGO_ENABLED=0 go test -c -tags integration \ |
91 |
| - -a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" \ |
92 |
| - -o postgres_exporter_integration_test -cover -covermode count . |
93 |
| - |
94 |
| -test: tools |
95 |
| - @mkdir -p $(COVERDIR) |
96 |
| - @rm -f $(COVERDIR)/* |
97 |
| - for pkg in $(GO_PKGS) ; do \ |
98 |
| - go test -v -covermode count -coverprofile=$(COVERDIR)/$$(echo $$pkg | tr '/' '-').out $$pkg || exit 1 ; \ |
99 |
| - done |
100 |
| - gocovmerge $(shell find $(COVERDIR) -name '*.out') > cover.test.out |
101 |
| - |
102 |
| -test-integration: postgres_exporter postgres_exporter_integration_test |
103 |
| - tests/test-smoke "$(shell pwd)/postgres_exporter" "$(shell pwd)/postgres_exporter_integration_test_script $(shell pwd)/postgres_exporter_integration_test $(shell pwd)/cover.integration.out" |
104 |
| - |
105 |
| -cover.out: tools |
106 |
| - gocovmerge cover.*.out > cover.out |
107 |
| - |
108 |
| -clean: |
109 |
| - [ ! -z $(BINDIR) ] && [ -e $(BINDIR) ] && find $(BINDIR) -print -delete || /bin/true |
110 |
| - [ ! -z $(COVERDIR) ] && [ -e $(COVERDIR) ] && find $(COVERDIR) -print -delete || /bin/true |
111 |
| - [ ! -z $(RELEASEDIR) ] && [ -e $(RELEASEDIR) ] && find $(RELEASEDIR) -print -delete || /bin/true |
112 |
| - rm -f postgres_exporter postgres_exporter_integration_test |
113 |
| - |
114 |
| -tools: |
115 |
| - $(MAKE) -C $(TOOLDIR) |
116 |
| - |
117 |
| -.PHONY: tools style fmt test all release binary clean |
| 1 | +# Copyright 2015 The Prometheus Authors |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | + |
| 14 | +all: vet |
| 15 | + |
| 16 | +include Makefile.common |
| 17 | + |
| 18 | +DOCKER_IMAGE_NAME ?= postgres-exporter |
0 commit comments