Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.

Commit 8e4cdef

Browse files
committed
Merge pull request #5 from prometheus/common-make
Use Makefile.COMMON in prometheus_cli.
2 parents b36c21d + 5f88bce commit 8e4cdef

File tree

2 files changed

+134
-63
lines changed

2 files changed

+134
-63
lines changed

Makefile

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,17 @@
1-
VERSION := 0.2.0
2-
3-
SRC := $(wildcard *.go)
4-
TARGET := prometheus_cli
5-
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-
GOOS ?= $(OS)
10-
GOARCH ?= $(ARCH)
11-
GOPKG := go1.3.$(OS)-$(ARCH).tar.gz
12-
GOROOT ?= $(CURDIR)/.deps/go
13-
GOPATH ?= $(CURDIR)/.deps/gopath
14-
GOCC := $(GOROOT)/bin/go
15-
GOLIB := $(GOROOT)/pkg/$(GOOS)_$(GOARCH)
16-
GO := GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC)
17-
18-
SUFFIX := $(GOOS)-$(GOARCH)
19-
BINARY := bin/$(TARGET)
20-
ARCHIVE := $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
21-
22-
default: build
23-
24-
build: $(BINARY)
25-
26-
.deps/$(GOPKG):
27-
mkdir -p .deps
28-
curl -L -o .deps/$(GOPKG) https://golang.org/dl/$(GOPKG)
29-
30-
$(GOCC): .deps/$(GOPKG)
31-
tar -C .deps -xzf .deps/$(GOPKG)
32-
touch $@
33-
34-
$(GOLIB):
35-
cd .deps/go/src && CGO_ENABLED=0 ./make.bash
36-
37-
dependencies: $(SRC)
38-
$(GO) get -d
39-
40-
$(BINARY): $(GOCC) $(GOLIB) $(SRC) dependencies
41-
$(GO) build -o $@
42-
43-
$(ARCHIVE): $(BINARY)
44-
tar -czf $@ bin/
45-
46-
upload: REMOTE ?= $(error "can't upload, REMOTE not set")
47-
upload: REMOTE_DIR ?= $(error "can't upload, REMOTE_DIR not set")
48-
upload: $(ARCHIVE)
49-
scp $(ARCHIVE) $(REMOTE):$(REMOTE_DIR)/$(ARCHIVE)
50-
51-
release: REMOTE ?= $(error "can't release, REMOTE not set")
52-
release: REMOTE_DIR ?= $(error "can't release, REMOTE_DIR not set")
53-
release:
54-
GOOS=linux REMOTE=$(REMOTE) REMOTE_DIR=$(REMOTE_DIR) $(MAKE) upload
55-
GOOS=darwin REMOTE=$(REMOTE) REMOTE_DIR=$(REMOTE_DIR) $(MAKE) upload
56-
57-
test:
58-
go test ./...
59-
60-
clean:
61-
rm -rf bin
62-
63-
.PHONY: test tag dependencies clean release upload
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+
VERSION := 0.3.0
15+
TARGET := prometheus_cli
16+
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)