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.

140 lines
3.9 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. BIN ?= /usr/local/bin
  35. UNAME_S ?= $(shell uname -s)
  36. UNAME_M ?= $(shell uname -m)
  37. TOOLS_DESTDIR ?= $(GOPATH)/bin
  38. BUF_VERSION ?= 0.7.0
  39. CERTSTRAP = $(TOOLS_DESTDIR)/certstrap
  40. PROTOBUF = $(TOOLS_DESTDIR)/protoc
  41. GOODMAN = $(TOOLS_DESTDIR)/goodman
  42. all: tools
  43. .PHONY: all
  44. tools: certstrap protobuf goodman
  45. .PHONY: tools
  46. check: check_tools
  47. .PHONY: check
  48. check_tools:
  49. @# https://stackoverflow.com/a/25668869
  50. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  51. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  52. .PHONY: check_tools
  53. certstrap: $(CERTSTRAP)
  54. $(CERTSTRAP):
  55. @echo "Get Certstrap"
  56. @go get github.com/square/certstrap@v1.2.0
  57. .PHONY: certstrap
  58. protobuf: $(PROTOBUF)
  59. $(PROTOBUF):
  60. @echo "Get GoGo Protobuf"
  61. @go get github.com/gogo/protobuf/protoc-gen-gogo@v1.3.1
  62. .PHONY: protobuf
  63. buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint
  64. @echo "Installing buf..."
  65. @curl -sSL \
  66. "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${UNAME_S}-${UNAME_M}" \
  67. -o "${BIN}/buf" && \
  68. chmod +x "${BIN}/buf"
  69. .PHONY: buf
  70. protoc-gen-buf-check-breaking:
  71. @echo "Installing protoc-gen-buf-check-breaking..."
  72. @curl -sSL \
  73. "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-breaking-${UNAME_S}-${UNAME_M}" \
  74. -o "${BIN}/protoc-gen-buf-check-breaking" && \
  75. chmod +x "${BIN}/protoc-gen-buf-check-breaking"
  76. protoc-gen-buf-check-lint:
  77. @echo "Installing protoc-gen-buf-check-lint..."
  78. @curl -sSL \
  79. "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-lint-${UNAME_S}-${UNAME_M}" \
  80. -o "${BIN}/protoc-gen-buf-check-lint" && \
  81. chmod +x "${BIN}/protoc-gen-buf-check-lint"
  82. .PHONY: protoc-gen-buf-check-lint
  83. goodman: $(GOODMAN)
  84. $(GOODMAN):
  85. @echo "Get Goodman"
  86. @go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
  87. .PHONY: goodman
  88. tools-clean:
  89. rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
  90. rm -f tools-stamp
  91. rm -rf /usr/local/include/google/protobuf
  92. rm -f /usr/local/bin/protoc
  93. .PHONY: tooks-clean
  94. ###
  95. # Non Go tools
  96. ###
  97. # Choose protobuf binary based on OS (only works for 64bit Linux and Mac).
  98. # NOTE: On Mac, installation via brew (brew install protoc) might be favorable.
  99. PROTOC_ZIP=""
  100. ifneq ($(OS),Windows_NT)
  101. UNAME_S := $(shell uname -s)
  102. ifeq ($(UNAME_S),Linux)
  103. PROTOC_ZIP="protoc-3.10.1-linux-x86_64.zip"
  104. endif
  105. ifeq ($(UNAME_S),Darwin)
  106. PROTOC_ZIP="protoc-3.10.1-osx-x86_64.zip"
  107. endif
  108. endif
  109. protoc:
  110. @echo "Get Protobuf"
  111. @echo "In case of any errors, please install directly from https://github.com/protocolbuffers/protobuf/releases"
  112. @curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/$(PROTOC_ZIP)
  113. @unzip -o $(PROTOC_ZIP) -d /usr/local bin/protoc
  114. @unzip -o $(PROTOC_ZIP) -d /usr/local 'include/*'
  115. @rm -f $(PROTOC_ZIP)
  116. .PHONY: protoc