github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/tools/Makefile (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  BUF_VERSION = "0.30.0"
    47  BINARY_NAME = "buf"
    48  BIN = "/usr/local/bin"
    49  OS = $(shell uname -s)
    50  ARCH = $(shell uname -m)
    51  
    52  all: tools
    53  .PHONY: all
    54  
    55  tools: certstrap protobuf goodman
    56  .PHONY: tools
    57  
    58  check: check_tools
    59  .PHONY: check
    60  
    61  check_tools:
    62  	@# https://stackoverflow.com/a/25668869
    63  	@echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
    64          $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
    65  .PHONY: check_tools
    66  
    67  certstrap: $(CERTSTRAP)
    68  $(CERTSTRAP):
    69  	@echo "Get Certstrap"
    70  	@go get github.com/square/certstrap@v1.2.0
    71  .PHONY: certstrap
    72  
    73  protobuf: $(PROTOBUF)
    74  $(PROTOBUF):
    75  	@echo "Get GoGo Protobuf"
    76  	@go get github.com/gogo/protobuf/protoc-gen-gogofaster@v1.3.1
    77  .PHONY: protobuf
    78  
    79  buf:
    80  	@echo "Install Buf"
    81  	curl -sSL \
    82      "https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/$(BINARY_NAME)-$(OS)-$(ARCH)" \
    83      -o "${BIN}/${BINARY_NAME}" && \
    84    chmod +x "${BIN}/${BINARY_NAME}"
    85  .PHONY: buf
    86  
    87  goodman: $(GOODMAN)
    88  $(GOODMAN):
    89  	@echo "Get Goodman"
    90  	@go get github.com/snikch/goodman/cmd/goodman@10e37e294daa3c9a90abded60ff9924bafab3888
    91  .PHONY: goodman
    92  
    93  tools-clean:
    94  	rm -f $(CERTSTRAP) $(PROTOBUF) $(GOX) $(GOODMAN)
    95  	rm -f tools-stamp
    96  	rm -f "${BIN}/${BINARY_NAME}"
    97  .PHONY: tooks-clean