You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4 KiB

  1. ###
  2. # Find OS and Go environment
  3. # GO contains the Go binary
  4. # FS contains the OS file separator
  5. ###
  6. ifeq ($(OS),Windows_NT)
  7. GO := $(shell where go.exe 2> NUL)
  8. FS := "\\"
  9. else
  10. GO := $(shell command -v go 2> /dev/null)
  11. FS := "/"
  12. endif
  13. ifeq ($(GO),)
  14. $(error could not find go. Is it in PATH? $(GO))
  15. endif
  16. GOPATH ?= $(shell $(GO) env GOPATH)
  17. GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
  18. ###
  19. # Functions
  20. ###
  21. go_get = $(if $(findstring Windows_NT,$(OS)),\
  22. IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
  23. IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
  24. ,\
  25. mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
  26. (test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
  27. )\
  28. cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
  29. mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
  30. mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
  31. ###
  32. # Go tools
  33. ###
  34. TOOLS_DESTDIR ?= $(GOPATH)/bin
  35. CERTSTRAP = $(TOOLS_DESTDIR)/certstrap
  36. PROTOBUF = $(TOOLS_DESTDIR)/protoc
  37. GOODMAN = $(TOOLS_DESTDIR)/goodman
  38. BUF_VERSION = "0.30.0"
  39. BINARY_NAME = "buf"
  40. BIN = "/usr/local/bin"
  41. OS = $(shell uname -s)
  42. ARCH = $(shell uname -m)
  43. all: tools
  44. .PHONY: all
  45. tools: certstrap protobuf goodman
  46. .PHONY: tools
  47. check: check_tools
  48. .PHONY: check
  49. check_tools:
  50. @# https://stackoverflow.com/a/25668869
  51. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  52. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  53. .PHONY: check_tools
  54. certstrap: $(CERTSTRAP)
  55. $(CERTSTRAP):
  56. @echo "Get Certstrap"
  57. @go get github.com/square/certstrap@v1.2.0
  58. .PHONY: certstrap
  59. protobuf: $(PROTOBUF)
  60. $(PROTOBUF):
  61. @echo "Get GoGo Protobuf"
  62. @go get github.com/gogo/protobuf/protoc-gen-gogofaster@v1.3.1
  63. .PHONY: protobuf
  64. buf:
  65. @echo "Install Buf"
  66. curl -sSL \
  67. "https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/$(BINARY_NAME)-$(OS)-$(ARCH)" \
  68. -o "${BIN}/${BINARY_NAME}" && \
  69. chmod +x "${BIN}/${BINARY_NAME}"
  70. .PHONY: buf
  71. goodman: $(GOODMAN)
  72. $(GOODMAN):
  73. @echo "Get Goodman"
  74. @go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
  75. .PHONY: goodman
  76. tools-clean:
  77. rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
  78. rm -f tools-stamp
  79. rm -f "${BIN}/${BINARY_NAME}"
  80. .PHONY: tooks-clean