github.com/fiagdao/tendermint@v0.32.11-0.20220824195748-2087fcc480c1/tools.mk (about)

     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  
    14  ifeq ($(GO),)
    15    $(error could not find go. Is it in PATH? $(GO))
    16  endif
    17  
    18  GOPATH ?= $(shell $(GO) env GOPATH)
    19  GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
    20  
    21  ###
    22  # Functions
    23  ###
    24  
    25  go_get = $(if $(findstring Windows_NT,$(OS)),\
    26  IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
    27  IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
    28  ,\
    29  mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
    30  (test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
    31  )\
    32  cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
    33  
    34  mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
    35  mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
    36  
    37  ###
    38  # Go tools
    39  ###
    40  
    41  TOOLS_DESTDIR  ?= $(GOPATH)/bin
    42  
    43  CERTSTRAP     = $(TOOLS_DESTDIR)/certstrap
    44  PROTOBUF     	= $(TOOLS_DESTDIR)/protoc
    45  GOODMAN 			= $(TOOLS_DESTDIR)/goodman
    46  
    47  all: tools
    48  .PHONY: all
    49  
    50  tools: certstrap protobuf goodman
    51  .PHONY: tools
    52  
    53  check: check_tools
    54  .PHONY: check
    55  
    56  check_tools:
    57  	@# https://stackoverflow.com/a/25668869
    58  	@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
    59          $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
    60  .PHONY: check_tools
    61  
    62  certstrap: $(CERTSTRAP)
    63  $(CERTSTRAP):
    64  	@echo "Get Certstrap"
    65  	@go get github.com/square/certstrap@v1.2.0
    66  .PHONY: certstrap
    67  
    68  protobuf: $(PROTOBUF)
    69  $(PROTOBUF):
    70  	@echo "Get GoGo Protobuf"
    71  	@go get github.com/gogo/protobuf/protoc-gen-gogo@v1.3.1
    72  .PHONY: protobuf
    73  
    74  goodman: $(GOODMAN)
    75  $(GOODMAN):
    76  	@echo "Get Goodman"
    77  	@go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
    78  .PHONY: goodman
    79  
    80  tools-clean:
    81  	rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
    82  	rm -f tools-stamp
    83  	rm -rf /usr/local/include/google/protobuf
    84  	rm -f /usr/local/bin/protoc
    85  .PHONY: tooks-clean
    86  
    87  ###
    88  # Non Go tools
    89  ###
    90  
    91  # Choose protobuf binary based on OS (only works for 64bit Linux and Mac).
    92  # NOTE: On Mac, installation via brew (brew install protoc) might be favorable.
    93  PROTOC_ZIP=""
    94  ifneq ($(OS),Windows_NT)
    95  		UNAME_S := $(shell uname -s)
    96  		ifeq ($(UNAME_S),Linux)
    97  			PROTOC_ZIP="protoc-3.10.1-linux-x86_64.zip"
    98  		endif
    99  		ifeq ($(UNAME_S),Darwin)
   100  			PROTOC_ZIP="protoc-3.10.1-osx-x86_64.zip"
   101  		endif
   102  endif
   103  
   104  protoc:
   105  	@echo "Get Protobuf"
   106  	@echo "In case of any errors, please install directly from https://github.com/protocolbuffers/protobuf/releases"
   107  	@curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/$(PROTOC_ZIP)
   108  	@unzip -o $(PROTOC_ZIP) -d /usr/local bin/protoc
   109  	@unzip -o $(PROTOC_ZIP) -d /usr/local 'include/*'
   110  	@rm -f $(PROTOC_ZIP)
   111  .PHONY: protoc