Fixing makefile

This commit is contained in:
Diogo Monica 2015-04-28 10:57:44 -07:00 committed by Nathan McCauley
parent faeed37c22
commit 01518934a8
4 changed files with 90 additions and 8 deletions

View File

@ -1,18 +1,35 @@
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
# Used to populate version variable in main package.
GO_LDFLAGS=-ldflags "-X `go list ./version`.Version `git describe --match 'v[0-9]*' --dirty='.m' --always`"
.PHONY: clean all fmt vet lint build test binaries
.DEFAULT: default
all: AUTHORS clean fmt vet fmt lint build test binaries
AUTHORS: .git/HEAD
git log --format='%aN <%aE>' | sort -fu > $@
# This only needs to be generated by hand when cutting full releases.
version/version.go:
./version/version.sh > $@
${PREFIX}/bin/vetinari-server: version/version.go $(shell find . -type f -name '*.go')
@echo "+ $@"
@go build -o $@ ${GO_LDFLAGS} ./cmd/vetinari-server
vet:
@echo "+ $@"
@go vet ./...
@test -z "$$(go tool vet -printf=false . 2>&1 | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" || \
echo "+ please format Go code with 'gofmt -s'"
@test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
lint:
@echo "+ $@"
@test -z "$$(golint ./... | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
@test -z "$$(golint ./... | grep -v .pb. | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
build:
@echo "+ $@"
@ -22,13 +39,19 @@ test:
@echo "+ $@"
@go test -test.short ./...
test-full:
test-full: vet lint
@echo "+ $@"
@go test ./...
@go test -v ./...
binaries: ${PREFIX}/bin/registry ${PREFIX}/bin/registry-api-descriptor-template ${PREFIX}/bin/dist
protos:
@protoc --go_out=plugins=grpc:. proto/*.proto
clean-protos:
@rm proto/*.pb.go
binaries: ${PREFIX}/bin/vetinari-server
@echo "+ $@"
clean:
@echo "+ $@"
@rm -rf "${PREFIX}/bin/registry" "${PREFIX}/bin/registry-api-descriptor-template"
@rm -rf "${PREFIX}/bin/vetinari-server"

26
version/print.go Normal file
View File

@ -0,0 +1,26 @@
package version
import (
"fmt"
"io"
"os"
)
// FprintVersion outputs the version string to the writer, in the following
// format, followed by a newline:
//
// <cmd> <project> <version>
//
// For example, a binary "registry" built from github.com/docker/distribution
// with version "v2.0" would print the following:
//
// registry github.com/docker/distribution v2.0
//
func FprintVersion(w io.Writer) {
fmt.Fprintln(w, os.Args[0], Package, Version)
}
// PrintVersion outputs the version information, from Fprint, to stdout.
func PrintVersion() {
FprintVersion(os.Stdout)
}

11
version/version.go Normal file
View File

@ -0,0 +1,11 @@
package version
// Package is the overall, canonical project import path under which the
// package was built.
var Package = "github.com/docker/vetinari"
// Version indicates which version of the binary is running. This is set to
// the latest release tag by hand, always suffixed by "+unknown". During
// build, it will be replaced by the actual version. The value here will be
// used if the registry is run after a go get based install.
var Version = "v0.0.1-alpha.1+unknown"

22
version/version.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# This bash script outputs the current, desired content of version.go, using
# git describe. For best effect, pipe this to the target file. Generally, this
# only needs to updated for releases. The actual value of will be replaced
# during build time if the makefile is used.
set -e
cat <<EOF
package version
// Package is the overall, canonical project import path under which the
// package was built.
var Package = "$(go list)"
// Version indicates which version of the binary is running. This is set to
// the latest release tag by hand, always suffixed by "+unknown". During
// build, it will be replaced by the actual version. The value here will be
// used if the registry is run after a go get based install.
var Version = "$(git describe --match 'v[0-9]*' --dirty='.m' --always)+unknown"
EOF