Skip to content

Commit cdf8374

Browse files
committed
Use Makefile.COMMON in node exporter.
1 parent 30cf7f8 commit cdf8374

File tree

2 files changed

+131
-67
lines changed

2 files changed

+131
-67
lines changed

Makefile

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,17 @@
1-
VERSION := 0.7.1
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.
213

3-
SRC := $(wildcard *.go)
14+
VERSION := 0.7.1
415
TARGET := node_exporter
516

6-
OS := $(subst Darwin,darwin,$(subst Linux,linux,$(subst FreeBSD,freebsd,$(shell uname))))
7-
ARCH := $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
8-
9-
# The release engineers apparently need to key their binary artifacts to the
10-
# Mac OS X release family.
11-
MAC_OS_X_VERSION ?= 10.8
12-
13-
GOOS ?= $(OS)
14-
GOARCH ?= $(ARCH)
15-
16-
ifeq ($(GOOS),darwin)
17-
RELEASE_SUFFIX ?= -osx$(MAC_OS_X_VERSION)
18-
else
19-
RELEASE_SUFFIX ?=
20-
endif
21-
22-
GO_VERSION ?= 1.4.1
23-
GOURL ?= https://golang.org/dl
24-
GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz
25-
GOROOT := $(CURDIR)/.deps/go
26-
GOPATH := $(CURDIR)/.deps/gopath
27-
GOCC := $(GOROOT)/bin/go
28-
GOLIB := $(GOROOT)/pkg/$(GOOS)_$(GOARCH)
29-
GO := GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC)
30-
31-
SUFFIX := $(GOOS)-$(GOARCH)
32-
BINARY := $(TARGET)
33-
ARCHIVE := $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
34-
SELFLINK := $(GOPATH)/src/github.com/prometheus/node_exporter
35-
36-
default: $(BINARY)
37-
38-
.deps/$(GOPKG):
39-
mkdir -p .deps
40-
curl -o .deps/$(GOPKG) -L $(GOURL)/$(GOPKG)
41-
42-
$(GOCC): .deps/$(GOPKG)
43-
tar -C .deps -xzf .deps/$(GOPKG)
44-
touch $@
45-
46-
$(SELFLINK):
47-
mkdir -p $(GOPATH)/src/github.com/prometheus
48-
ln -s $(CURDIR) $(SELFLINK)
49-
50-
dependencies: $(SRC) $(SELFLINK)
51-
$(GO) get -d
52-
53-
$(BINARY): $(GOCC) $(SRC) dependencies
54-
$(GO) build $(GOFLAGS) -o $@
55-
56-
$(ARCHIVE): $(BINARY)
57-
tar -czf $@ $<
58-
59-
release: REMOTE ?= $(error "can't release, REMOTE not set")
60-
release: REMOTE_DIR ?= $(error "can't release, REMOTE_DIR not set")
61-
release: $(ARCHIVE)
62-
scp $< $(REMOTE):$(REMOTE_DIR)/$(ARCHIVE)
63-
64-
test: $(GOCC) dependencies
65-
$(GO) test ./...
66-
67-
clean:
68-
rm -rf node_exporter .deps
69-
70-
.PHONY: clean default dependencies release test
17+
include Makefile.COMMON

Makefile.COMMON

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
# THE AUTHORITATIVE VERSION OF THIS MAKEFILE LIVES IN:
15+
#
16+
# https://github.com/prometheus/utils
17+
#
18+
# PLEASE MAKE ANY CHANGES THERE AND PROPAGATE THEM TO ALL PROMETHEUS
19+
# REPOSITORIES THAT ARE USING THIS MAKEFILE.
20+
#
21+
# This file provides common Makefile infrastructure for several Prometheus
22+
# components. This includes make tasks for downloading Go, setting up a
23+
# self-contained build environment, fetching Go dependencies, building
24+
# binaries, running tests, and doing release management. This file is intended
25+
# to be included from a project's Makefile, which needs to define the following
26+
# variables, at a minimum:
27+
#
28+
# * VERSION - The current version of the project in question.
29+
# * TARGET - The desired name of the built binary.
30+
#
31+
# Many of the variables defined below are defined conditionally (using '?'),
32+
# which allows the project's main Makefile to override any of these settings, if
33+
# needed. See also:
34+
#
35+
# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors.
36+
#
37+
# The including Makefile may define any number of extra targets that are
38+
# specific to that project.
39+
40+
VERSION ?= $(error VERSION not set in including Makefile)
41+
TARGET ?= $(error TARGET not set in including Makefile)
42+
43+
SRC ?= $(shell find . -type f -name "*.go" ! -path "./.build/*")
44+
GOOS := $(shell uname | tr A-Z a-z)
45+
GOARCH := $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
46+
47+
ifeq ($(GOOS),darwin)
48+
RELEASE_SUFFIX ?= -osx$(shell sw_vers -productVersion)
49+
endif
50+
51+
GO_VERSION ?= 1.4.2
52+
GOURL ?= https://golang.org/dl
53+
GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz
54+
GOPATH := $(CURDIR)/.build/gopath
55+
GOCC ?= $(GOROOT)/bin/go
56+
GO ?= GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC)
57+
GOFMT ?= $(GOROOT)/bin/gofmt
58+
59+
ifeq ($(shell type go >/dev/null && go version | sed 's/.*go\([0-9.]*\).*/\1/'), $(GO_VERSION))
60+
GOROOT := $(shell go env GOROOT)
61+
else
62+
GOROOT := $(CURDIR)/.build/go$(GO_VERSION)
63+
endif
64+
65+
# Never honor GOBIN, should it be set at all.
66+
unexport GOBIN
67+
68+
SUFFIX ?= $(GOOS)-$(GOARCH)
69+
BINARY ?= $(TARGET)
70+
ARCHIVE ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
71+
ROOTPKG ?= github.com/prometheus/$(TARGET)
72+
SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
73+
74+
default: $(BINARY)
75+
76+
$(GOCC):
77+
@echo Go version $(GO_VERSION) required but not found in PATH.
78+
@echo About to download and install go$(GO_VERSION) to $(GOROOT)
79+
@echo Abort now if you want to manually install it system-wide instead.
80+
@echo
81+
@sleep 5
82+
mkdir -p $(GOROOT)
83+
curl -L $(GOURL)/$(GOPKG) | tar -C $(GOROOT) --strip 1 -xz
84+
85+
$(SELFLINK):
86+
mkdir -p $(dir $@)
87+
ln -s $(CURDIR) $@
88+
89+
dependencies-stamp: $(GOCC) $(SRC) | $(SELFLINK)
90+
$(GO) get -d
91+
touch $@
92+
93+
$(BINARY): $(GOCC) $(SRC) dependencies-stamp Makefile Makefile.COMMON
94+
$(GO) build $(GOFLAGS) -o $@
95+
96+
.PHONY: archive
97+
archive: $(ARCHIVE)
98+
99+
$(ARCHIVE): $(BINARY)
100+
tar -czf $@ $<
101+
102+
.PHONY: tag
103+
tag:
104+
git tag $(VERSION)
105+
git push --tags
106+
107+
.PHONY: test
108+
test: $(GOCC) dependencies-stamp
109+
$(GO) test ./...
110+
111+
.PHONY: format
112+
format: $(GOCC)
113+
find . -iname '*.go' | egrep -v "^\./\.build|./generated|\./Godeps|\.(l|y)\.go" | xargs -n1 $(GOFMT) -w -s=true
114+
115+
.PHONY: clean
116+
clean:
117+
rm -rf $(BINARY) $(ARCHIVE) .build *-stamp

0 commit comments

Comments
 (0)