Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created May 19, 2015 12:50
Show Gist options
  • Save hagbarddenstore/b39624179080cc628c41 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/b39624179080cc628c41 to your computer and use it in GitHub Desktop.
A Makefile for Go projects
PREFIX?=$(shell pwd)
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
GO_LDFLAGS=-ldflags "-X `go list ./version`.Version $(VERSION)"
.PHONY: clean all fmt vet lint build test binaries
.DEFAULT: default
all: AUTHORS clean fmt vet fmt lint build test binaries
AUTHORS: .mailmap .git/HEAD
git log --format='%aN <%aE>' | sort -fu > $@
version/version.go:
./version/version.sh > $@
${PREFIX}/bin/server: version/version.go $(shell find . -type f -name '*.go')
@echo "+ $@"
@go build -o $@ ${GO_LDFLAGS} ./cmd/server
vet:
@echo "+ $@"
@go vet ./...
fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" || \
echo "+ please format Go code with 'gofmt -s'"
lint:
@echo "+ $@"
@test -z "$$(golint ./... | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
build:
@echo "+ $@"
@go build -v ${GO_LDFLAGS} ./...
test:
@echo "+ $@"
@go test -test.short ./...
test-full:
@echo "+ $@"
@go test ./...
binaries: ${PREFIX}/bin/server
@echo "+ $@"
clean:
@echo "+ $@"
@rm -rf "${PREFIX}/bin/server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment