# Go parameters
GOPATH=$(HOME)/go
#GOBIN=$(shell pwd)/bin
GOBIN=/usr/local/go/bin
GOCMD=$(GOBIN)/go
GOGET=$(GOCMD) get
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOCOVER=$(GOCMD) tool cover
COBERTURA=$(HOME)/go/bin/gocover-cobertura
GOLINT=$(GOBIN)/golint
GOVET=$(GOCMD) vet

# Project parameters
GONAME=kontor
GOFILE=cmd/kontor/main.go

#.PHONY: all deps clean clean-bin clean-doc

all: deps build

deps:
	$(GOGET) -u -v github.com/jstemmer/go-junit-report
	$(GOGET) -u -v github.com/tebeka/go2xunit
	$(GOGET) -u -v github.com/t-yuki/gocover-cobertura
	$(GOGET) -u -v github.com/spf13/cobra/cobra
	$(GOGET) -u -v github.com/inconshreveable/mousetrap
	$(GOGET) -u -v github.com/mitchellh/go-homedir
	$(GOGET) -u -v github.com/golang/protobuf/proto
	$(GOGET) -u -v github.com/gin-gonic/gin
	$(GOGET) -u -v github.com/gin-gonic/gin/binding
	$(GOGET) -u -v github.com/gin-gonic/gin/render
	$(GOGET) -u -v github.com/gin-contrib/sse
	$(GOGET) -u -v github.com/mattn/go-isatty
	$(GOGET) -u -v github.com/ugorji/go/codec
	$(GOGET) -u -v golang.org/x/crypto/bcrypt
	$(GOGET) -u -v golang.org/x/crypto/blowfish
	G$(GOGET) -u -v gopkg.in/yaml.v2
	$(GOGET) -u -v gopkg.in/mgo.v2
	$(GOGET) -u -v gopkg.in/mgo.v2/bson

build: bin/$(GONAME)

bin/$(GONAME): $(GOFILE)
	@echo "Building $(GOFILE) to ./bin"
	$(GOBUILD) -v -ldflags="-X main.version=$(shell git describe --always --long --dirty)" -o bin/$(GONAME) $(GOFILE)

install:
	@echo using $(GOPATH)
	$(GOCMD) install -v -ldflags="-X main.version=$(shell git describe --always --long --dirty)" ./...

test:
	$(GOTEST) -v ./...
	$(GOTEST) -coverprofile=cover.out ./...
	$(GOCOVER) -html=cover.out -o coverage.html
	$(COBERTURA) < cover.out > coverage.xml
	$(GOLINT) ./...
	$(GOVET) -v ./...

doc:
	cd docs; ./gradlew build

clean: clean-doc clean-bin


clean-doc:
	@echo "Cleaning Gradle build"
	cd docs; ./gradlew clean

clean-bin:
	@echo "Cleaning Go build"
	rm -rf bin/
