From cbf5faaf8c23a4f3b5d5211b8d7ad84c097d0379 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 1 Feb 2015 02:30:41 +0100 Subject: [PATCH] Bring Makefiles into shape. This borrows a lot of the latest changes to the node_exporter Makefile, as well as some tricks from the Prometheus one. --- Makefile | 41 +++++++++++++++++++++++++++++++---------- Makefile.INCLUDE | 38 ++++++++++++++++++++++++++++++++------ web/Makefile | 16 +++++++++------- web/blob/Makefile | 25 ------------------------- 4 files changed, 72 insertions(+), 48 deletions(-) delete mode 100644 web/blob/Makefile diff --git a/Makefile b/Makefile index 73fb5037..14c25e3f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ -# -*- Mode: makefile -*- - -# Copyright 2013 Prometheus Team +# Copyright 2013 The Prometheus Authors # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -15,10 +13,22 @@ include Makefile.INCLUDE -all: build test +default: $(BINARY) -build: config web - $(GO) build $(BUILDFLAGS) +.deps/$(GOPKG): + mkdir -p .deps + curl -o .deps/$(GOPKG) -L $(GOURL)/$(GOPKG) + +$(GOCC): .deps/$(GOPKG) + tar -C .deps -xzf .deps/$(GOPKG) + touch $@ + +$(SELFLINK): + mkdir -p $(GOPATH)/src/github.com/prometheus + ln -s $(CURDIR) $(SELFLINK) + +dependencies: $(SELFLINK) web config + $(GO) get -d config: $(MAKE) -C config @@ -26,11 +36,22 @@ config: web: $(MAKE) -C web -test: build - $(GO) test -v ./... +$(BINARY): $(GOCC) dependencies + $(GO) build $(BUILDFLAGS) -o $@ + +$(ARCHIVE): $(BINARY) + tar -czf $@ $< + +release: REMOTE ?= $(error "can't release, REMOTE not set") +release: REMOTE_DIR ?= $(error "can't release, REMOTE_DIR not set") +release: $(ARCHIVE) + scp $< $(REMOTE):$(REMOTE_DIR)/$(ARCHIVE) + +test: $(GOCC) dependencies + $(GO) test ./... clean: $(MAKE) -C web clean - -rm alertmanager + -rm -rf alertmanager .deps -.PHONY: clean config web +.PHONY: clean config default dependencies release test web diff --git a/Makefile.INCLUDE b/Makefile.INCLUDE index 7b1374b9..6f8ae4bd 100644 --- a/Makefile.INCLUDE +++ b/Makefile.INCLUDE @@ -1,6 +1,4 @@ -# -*- Mode: makefile -*- - -# Copyright 2013 Prometheus Team +# Copyright 2013 The Prometheus Authors # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -13,11 +11,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -.SUFFIXES: +VERSION := 0.1.0 -GO := $(GOROOT)/bin/go +TARGET := alertmanager + +OS := $(subst Darwin,darwin,$(subst Linux,linux,$(shell uname))) +ARCH := $(subst x86_64,amd64,$(shell uname -m)) + +# The release engineers apparently need to key their binary artifacts to the +# Mac OS X release family. +MAC_OS_X_VERSION ?= 10.8 + +GOOS ?= $(OS) +GOARCH ?= $(ARCH) + +ifeq ($(GOOS),darwin) +RELEASE_SUFFIX ?= -osx$(MAC_OS_X_VERSION) +else +RELEASE_SUFFIX ?= +endif + +GO_VERSION ?= 1.4.1 +GOURL ?= https://golang.org/dl +GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz +GOROOT := $(PWD)/.deps/go +GOPATH := $(PWD)/.deps/gopath +GOCC := $(GOROOT)/bin/go +GO := GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC) GOFMT := $(GOROOT)/bin/gofmt -GO_VERSION := 1.1 + +SUFFIX := $(GOOS)-$(GOARCH) +BINARY := $(TARGET) +ARCHIVE := $(TARGET)-$(VERSION).$(SUFFIX).tar.gz +SELFLINK := $(GOPATH)/src/github.com/prometheus/alertmanager REV := $(shell git rev-parse --short HEAD) BRANCH := $(shell git rev-parse --abbrev-ref HEAD) diff --git a/web/Makefile b/web/Makefile index c0ed224d..d268b554 100644 --- a/web/Makefile +++ b/web/Makefile @@ -1,4 +1,4 @@ -# Copyright 2013 Prometheus Team +# Copyright 2013 The Prometheus Authors # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -11,14 +11,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -all: blob-stamp +include ../Makefile.INCLUDE -blob-stamp: templates/* - $(MAKE) -C blob - touch $@ +all: blob/files.go + +SUFFIXES: + +blob/files.go: $(shell find templates/ static/ -type f) + ./blob/embed-static.sh static templates | $(GOFMT) > $@ clean: - $(MAKE) -C blob clean - -rm -f *-stamp + -rm -f blob/files.go .PHONY: clean diff --git a/web/blob/Makefile b/web/blob/Makefile deleted file mode 100644 index 485d0e5f..00000000 --- a/web/blob/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2013 Prometheus Team -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -all: files.go - -SUFFIXES: - -files.go: $(shell find ../templates/ ../static/ -type f) - ./embed-static.sh ../static ../templates | gofmt > $@ - -clean: - -rm files.go - -rm -rf generated - -.PHONY: clean