GLIDE	:= $(shell which glide 2>/dev/null)
INSTALL_DIR ?= /usr/local/sbin
RELEASE_DIR ?= release
APP ?= $(shell basename `pwd`)

## Build binary
go/build: $(GO)
	$(call assert-set,GO)
	$(GO) build -o $(RELEASE_DIR)/$(APP)

## Build binary for all platforms
go/build-all: $(GO)
	$(call assert-set,GO)
ifeq ($(RELEASE_ARCH),)
	gox -output "${RELEASE_DIR}/${APP}_{{.OS}}_{{.Arch}}"
else
	gox -osarch="$(RELEASE_ARCH)" -output "${RELEASE_DIR}/${APP}_{{.OS}}_{{.Arch}}"
endif

## Install dependencies
go/deps: $(GLIDE)
	$(call assert-set,GLIDE)
	$(GLIDE) install --strip-vendor
	$(GLIDE) update  --strip-vendor

## Install dependencies for build
go/deps-build:
	$(call assert-set,GOPATH)
	mkdir -p  $(GOPATH)/bin
	which $(GLIDE) || (curl https://glide.sh/get | sh)

## Install development dependencies
go/deps-dev: $(GO)
	$(call assert-set,GO)
	$(GO) get -u -v golang.org/x/lint/golint
	$(GO) get -u -v github.com/mitchellh/gox

## Clean compiled binary
go/clean:
	rm -rf $(RELEASE_DIR)

## Clean compiled binary and dependency
go/clean-all: go/clean
	rm -rf vendor
	rm -rf glide.lock

## Install cli
go/install: $(APP) go/build
	cp $(RELEASE_DIR)/$(APP) $(INSTALL_DIR)
	chmod 555 $(INSTALL_DIR)/$(APP)
