Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create makefile #16

Open
diogomonica opened this issue May 10, 2016 · 2 comments
Open

Create makefile #16

diogomonica opened this issue May 10, 2016 · 2 comments

Comments

@diogomonica
Copy link
Owner

We should create a Makefile that allows someone to clone the repo and at least do # make binaries and # make test.

Something like:

# Root directory of the project (absolute path).
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Base path used to install.
DESTDIR=/usr/local

# Used to populate version variable in main package.
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)

# Project packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)

# Project binaries.
COMMANDS=actuary
BINARIES=$(addprefix bin/,$(COMMANDS))

GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"

.PHONY: clean all fmt vet build binaries test setup coverage ci check help
.DEFAULT: default

all: check build binaries test ## run fmt, vet, lint, build the binaries and run the tests

# This only needs to be generated by hand when cutting full releases.
version/version.go:
    ./version/version.sh > $@

setup: ## install dependencies
    @go get -u github.com/golang/lint/golint

# Depends on binaries because vet will silently fail if it can't load compiled
# imports
vet: binaries
    @test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | grep -v 'timestamp_test.go' | grep -v 'exit status 1' | tee /dev/stderr)"

lint: ## run go lint
    @test -z "$$(golint ./... | grep -v vendor/ | tee /dev/stderr)"

build: ## build the go packages
    @go build -i -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES}

test: ## run test
    @go test -parallel 8 -race -tags "${DOCKER_BUILDTAGS}" ${PACKAGES}

FORCE:

# Build a binary from a cmd.
bin/%: cmd/% FORCE
    @go build -i -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS}  ${GO_GCFLAGS} ./$<

binaries: $(BINARIES) ## build binaries

clean: ## clean up binaries
    @rm -f $(BINARIES)

install: $(BINARIES) ## install binaries
    @mkdir -p $(DESTDIR)/bin
    @install $(BINARIES) $(DESTDIR)/bin

uninstall:
    @rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES)))
@thanasisk
Copy link
Contributor

I think I can do this, any objections in having a go (no pun intended)?

@zuBux
Copy link
Collaborator

zuBux commented Jul 22, 2016

Sure! My relationship with Makefiles is practically non-existent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants