Makefile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. VERSION ?= v0.0.0
  2. #VERSION ?= $(shell git describe --tags --abbrev=0 | sed 's/^v//')
  3. build: vendor clean test all ## Test and build binaries for local architecture
  4. first: tools
  5. .PHONY: clean
  6. clean: ## Remove build products from bin/ and release/
  7. rm -rf bin
  8. rm -rf release
  9. .PHONY: tools
  10. tools: ## Download and install all dev/code tools
  11. @echo "==> Installing dev tools"
  12. go get -u github.com/golang/dep/cmd/dep
  13. go get -u honnef.co/go/tools/cmd/staticcheck
  14. vendor: ## Install dependencies
  15. dep ensure -v -vendor-only
  16. .PHONY: deps
  17. deps: ## Update dependencies to latest version
  18. dep ensure -v
  19. .PHONY: test
  20. test: ## Ensure that code matches best practices
  21. staticcheck ./...
  22. .PHONY: help
  23. help: ## Display this help message
  24. @echo "GNU make(1) targets:"
  25. @grep -E '^[a-zA-Z_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
  26. .PHONY: docker_test
  27. docker_test: ## run a test build in docker
  28. docker/test.bash
  29. .PHONY: docker_release
  30. docker_release: ## Build all release binaries and checksums in docker
  31. docker/release.bash
  32. ################################
  33. # Dynamic Fanciness #
  34. # aka Why GNU make Is Required #
  35. ################################
  36. PLATFORMS := darwin-amd64 linux-amd64 solaris-amd64 freebsd-amd64 openbsd-amd64 linux-arm
  37. BINARIES := kosh
  38. RELEASE_BINARIES := kosh
  39. BINS := $(foreach bin,$(BINARIES),bin/$(bin))
  40. RELEASES := $(foreach bin,$(RELEASE_BINARIES),release/$(bin))
  41. GIT_REV := $(shell git describe --always --abbrev --dirty --long)
  42. LD_FLAGS := -ldflags="-X main.Version=$(VERSION) -X main.GitRev=$(GIT_REV)"
  43. BUILD := CGO_ENABLED=0 go build $(LD_FLAGS)
  44. ####
  45. all: $(BINS) ## Build all binaries
  46. .PHONY: release
  47. release: vendor test $(RELEASES) ## Build release binaries with checksums
  48. bin/%:
  49. @mkdir -p bin
  50. @echo "> Building bin/$(subst bin/,,$@)"
  51. @$(BUILD) -o bin/$(subst bin/,,$@) *.go
  52. os = $(firstword $(subst -, ,$1))
  53. arch = $(lastword $(subst -, ,$1))
  54. define release_me
  55. $(eval BIN:=$(subst release/,,$@))
  56. $(eval GOOS:=$(call os, $(platform)))
  57. $(eval GOARCH:=$(call arch, $(platform)))
  58. $(eval RPATH:=release/$(BIN)-$(GOOS)-$(GOARCH))
  59. @echo "> Building $(RPATH)"
  60. @GOOS=$(GOOS) GOARCH=$(GOARCH) $(BUILD) -o $(RPATH) *.go
  61. shasum -a 256 $(RPATH) > $(RPATH).sha256
  62. endef
  63. release/%:
  64. @mkdir -p release
  65. $(foreach platform,$(PLATFORMS),$(call release_me))