Skip to content

Commit

Permalink
Replace Makefile with simpler setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fabxc committed Sep 17, 2015
1 parent fd26b5b commit 5127963
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 200 deletions.
2 changes: 0 additions & 2 deletions .build/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions .build/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions .build/cache/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions .build/root/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion .build/root/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .build/root/include/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .build/root/lib/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .build/root/share/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ core
/promtool
benchmark.txt
/data
/.build

.#*
command-line-arguments.test
Expand Down
93 changes: 18 additions & 75 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2013 The Prometheus Authors
# Copyright 2015 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
Expand All @@ -11,86 +11,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

TEST_ARTIFACTS = prometheus prometheus.race search_index
GO := GO15VENDOREXPERIMENT=1 go
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

include Makefile.INCLUDE
all: format build test

all: binary test
test:
@echo ">> running tests"
@$(GO) test -short $(pkgs)

$(GOCC): $(BUILD_PATH)/cache/$(GOPKG)
tar -C $(BUILD_PATH)/root -xzf $<
touch $@
format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

advice: $(GOCC)
$(GO) vet ./...
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)

binary: build

build: dependencies $(GOPATH)
$(GO) build -o prometheus $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/prometheus
$(GO) build -o promtool $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/promtool
build:
@echo ">> building binaries"
@./scripts/build.sh

docker:
docker build -t prometheus:$(REV) .

tarball: $(ARCHIVE)

$(GOPATH):
mkdir -p $(GOPATH)
cp -a $(MAKEFILE_DIR)/vendor/ $(GOPATH)/src

$(ARCHIVE): build
mkdir -p $(ARCHIVEDIR)
cp -a prometheus promtool consoles console_libraries $(ARCHIVEDIR)
tar -czf $(ARCHIVE) $(ARCHIVEDIR)
rm -rf $(ARCHIVEDIR)

release: REMOTE ?= $(error "can't upload, REMOTE not set")
release: REMOTE_DIR ?= $(error "can't upload, REMOTE_DIR not set")
release: $(ARCHIVE)
scp $< $(REMOTE):$(REMOTE_DIR)/

tag:
git tag $(VERSION)
git push --tags

$(BUILD_PATH)/cache/$(GOPKG):
$(CURL) -o $@ -L $(GOURL)/$(GOPKG)

benchmark: dependencies
$(GO) test $(GO_TEST_FLAGS) -test.run='NONE' -test.bench='.*' -test.benchmem ./... | tee benchmark.txt

clean:
$(MAKE) -C $(BUILD_PATH) clean
rm -rf $(TEST_ARTIFACTS)
-rm $(ARCHIVE)
-find . -type f -name '*~' -exec rm '{}' ';'
-find . -type f -name '*#' -exec rm '{}' ';'
-find . -type f -name '.#*' -exec rm '{}' ';'

$(SELFLINK): $(GOPATH)
mkdir -p `dirname $@`
ln -s $(MAKEFILE_DIR) $@

dependencies: $(GOCC) | $(SELFLINK)

documentation: search_index
godoc -http=:6060 -index -index_files='search_index'

format: dependencies
find . -iname '*.go' | egrep -v "^\./(\.build|vendor)/" | xargs -n1 $(GOFMT) -w -s=true

race_condition_binary: build
$(GO) build -race -o prometheus.race $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/prometheus
$(GO) build -race -o promtool.race $(BUILDFLAGS) github.com/prometheus/prometheus/cmd/promtool

search_index:
godoc -index -write_index -index_files='search_index'

test: dependencies
$(GO) test $(GO_TEST_FLAGS) ./...
@docker build -t prometheus:$(shell git rev-parse --short HEAD) .

web: dependencies
$(MAKE) -C web

.PHONY: advice binary build clean dependencies documentation format race_condition_binary race_condition_run release run search_index tag tarball test
.PHONY: format build test vet docker
74 changes: 0 additions & 74 deletions Makefile.INCLUDE

This file was deleted.

46 changes: 46 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Copyright 2015 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
#
# 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.

set -e

repo_path="github.com/prometheus/prometheus"

version=$( cat version/VERSION )
revision=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' )
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )
host=$( hostname -f )
build_date=$( date +%Y%m%d-%H:%M:%S )

if [ "$(go env GOOS)" = "windows" ]; then
ext=".exe"
fi

ldflags="
-X ${repo_path}/version.Version=${version}
-X ${repo_path}/version.Revision=${revision}
-X ${repo_path}/version.Branch=${branch}
-X ${repo_path}/version.BuildUser=${USER}@${host}
-X ${repo_path}/version.BuildDate=${build_date}
-X ${repo_path}/version.GoVersion=${go_version}"

export GO15VENDOREXPERIMENT="1"

echo " > prometheus"
go build -ldflags "${ldflags}" -o prometheus${ext} ${repo_path}/cmd/prometheus

echo " > promtool"
go build -ldflags "${ldflags}" -o promtool${ext} ${repo_path}/cmd/promtool

exit 0

0 comments on commit 5127963

Please sign in to comment.