Makefile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # set the shell to bash always
  2. SHELL := /usr/bin/env bash
  3. # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
  4. ifeq (,$(shell go env GOBIN))
  5. GOBIN=$(shell go env GOPATH)/bin
  6. else
  7. GOBIN=$(shell go env GOBIN)
  8. endif
  9. # check if there are any existing `git tag` values
  10. ifeq ($(shell git tag),)
  11. # no tags found - default to initial tag `v0.0.0`
  12. export VERSION := $(shell echo "v0.0.0-$$(git rev-list HEAD --count)-g$$(git describe --dirty --always)" | sed 's/-/./2' | sed 's/-/./2')
  13. else
  14. # use tags
  15. export VERSION := $(shell git describe --dirty --always --tags --exclude 'helm*' | sed 's/-/./2' | sed 's/-/./2')
  16. endif
  17. ## Location to install dependencies to
  18. LOCALBIN ?= $(shell pwd)/bin
  19. $(LOCALBIN):
  20. mkdir -p $(LOCALBIN)
  21. .PHONY: build
  22. build: ## Build binary for the specified arch
  23. go build -o '$(LOCALBIN)/esoctl' -trimpath -ldflags="-s -w -X 'main.version=$(VERSION)'" .
  24. .PHONY: binaries
  25. binaries: ## Build release binaries for all major OSs.
  26. @rm -fr dist
  27. @mkdir -p dist
  28. GOOS=linux GOARCH=amd64 go build -o dist/esoctl-linux-amd64 -trimpath -ldflags="-s -w -X 'main.version=$(VERSION)'" .
  29. GOOS=darwin GOARCH=amd64 go build -o dist/esoctl-darwin-amd64 -trimpath -ldflags="-s -w -X 'main.version=$(VERSION)'" .
  30. GOOS=windows GOARCH=amd64 go build -o dist/esoctl-windows-amd64.exe -trimpath -ldflags="-s -w -X 'main.version=$(VERSION)'" .