github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/Makefile (about)

     1  #!/usr/bin/make -f
     2  
     3  PACKAGES=$(shell go list ./...)
     4  BUILDDIR ?= $(CURDIR)/build
     5  
     6  BUILD_TAGS?=tendermint
     7  
     8  # If building a release, please checkout the version tag to get the correct version setting
     9  ifneq ($(shell git symbolic-ref -q --short HEAD),)
    10  VERSION := unreleased-$(shell git symbolic-ref -q --short HEAD)-$(shell git rev-parse HEAD)
    11  else
    12  VERSION := $(shell git describe)
    13  endif
    14  
    15  LD_FLAGS = -X github.com/lazyledger/lazyledger-core/version.TMCoreSemVer=$(VERSION)
    16  BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
    17  HTTPS_GIT := https://github.com/lazyledger/lazyledger-core.git
    18  DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf
    19  CGO_ENABLED ?= 0
    20  
    21  # handle nostrip
    22  ifeq (,$(findstring nostrip,$(TENDERMINT_BUILD_OPTIONS)))
    23    BUILD_FLAGS += -trimpath
    24    LD_FLAGS += -s -w
    25  endif
    26  
    27  # handle race
    28  ifeq (race,$(findstring race,$(TENDERMINT_BUILD_OPTIONS)))
    29    CGO_ENABLED=1
    30    BUILD_FLAGS += -race
    31  endif
    32  
    33  # handle cleveldb
    34  ifeq (cleveldb,$(findstring cleveldb,$(TENDERMINT_BUILD_OPTIONS)))
    35    CGO_ENABLED=1
    36    BUILD_TAGS += cleveldb
    37  endif
    38  
    39  # handle badgerdb
    40  ifeq (badgerdb,$(findstring badgerdb,$(TENDERMINT_BUILD_OPTIONS)))
    41    BUILD_TAGS += badgerdb
    42  endif
    43  
    44  # handle rocksdb
    45  ifeq (rocksdb,$(findstring rocksdb,$(TENDERMINT_BUILD_OPTIONS)))
    46    CGO_ENABLED=1
    47    BUILD_TAGS += rocksdb
    48  endif
    49  
    50  # handle boltdb
    51  ifeq (boltdb,$(findstring boltdb,$(TENDERMINT_BUILD_OPTIONS)))
    52    BUILD_TAGS += boltdb
    53  endif
    54  
    55  # allow users to pass additional flags via the conventional LDFLAGS variable
    56  LD_FLAGS += $(LDFLAGS)
    57  
    58  all: check build test install
    59  .PHONY: all
    60  
    61  # The below include contains the tools.
    62  include tools/Makefile
    63  include test/Makefile
    64  
    65  ###############################################################################
    66  ###                                Build Tendermint                        ###
    67  ###############################################################################
    68  
    69  build: $(BUILDDIR)/
    70  	CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(BUILDDIR)/ ./cmd/tendermint/
    71  .PHONY: build
    72  
    73  install:
    74  	CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
    75  .PHONY: install
    76  
    77  $(BUILDDIR)/:
    78  	mkdir -p $@
    79  
    80  ###############################################################################
    81  ###                                Protobuf                                 ###
    82  ###############################################################################
    83  
    84  proto-all: proto-gen proto-lint proto-check-breaking
    85  .PHONY: proto-all
    86  
    87  proto-gen:
    88  	## If you get the following error,
    89  	## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
    90  	## See https://stackoverflow.com/a/25518702
    91  	## Note the $< here is substituted for the %.proto
    92  	## Note the $@ here is substituted for the %.pb.go
    93  	@sh scripts/protocgen.sh
    94  .PHONY: proto-gen
    95  
    96  proto-gen-docker:
    97  	@echo "Generating Protobuf files"
    98  	@docker run -v $(shell pwd):/workspace --workdir /workspace tendermintdev/docker-build-proto sh ./scripts/protocgen.sh
    99  .PHONY: proto-gen-docker
   100  
   101  proto-lint:
   102  	@$(DOCKER_BUF) check lint --error-format=json
   103  .PHONY: proto-lint
   104  
   105  proto-format:
   106  	@echo "Formatting Protobuf files"
   107  	docker run -v $(shell pwd):/workspace --workdir /workspace tendermintdev/docker-build-proto find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
   108  .PHONY: proto-format
   109  
   110  proto-check-breaking:
   111  	@$(DOCKER_BUF) check breaking --against-input .git#branch=master
   112  .PHONY: proto-check-breaking
   113  
   114  proto-check-breaking-ci:
   115  	@$(DOCKER_BUF) check breaking --against-input $(HTTPS_GIT)#branch=master
   116  .PHONY: proto-check-breaking-ci
   117  
   118  ###############################################################################
   119  ###                              Distribution                               ###
   120  ###############################################################################
   121  
   122  # dist builds binaries for all platforms and packages them for distribution
   123  # TODO add abci to these scripts
   124  dist:
   125  	@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
   126  .PHONY: dist
   127  
   128  go-mod-cache: go.sum
   129  	@echo "--> Download go modules to local cache"
   130  	@go mod download
   131  .PHONY: go-mod-cache
   132  
   133  go.sum: go.mod
   134  	@echo "--> Ensure dependencies have not been modified"
   135  	@go mod verify
   136  	@go mod tidy
   137  
   138  draw_deps:
   139  	@# requires brew install graphviz or apt-get install graphviz
   140  	go get github.com/RobotsAndPencils/goviz
   141  	@goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
   142  .PHONY: draw_deps
   143  
   144  get_deps_bin_size:
   145  	@# Copy of build recipe with additional flags to perform binary size analysis
   146  	$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(BUILDDIR)/ ./cmd/tendermint/ 2>&1))
   147  	@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
   148  	@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
   149  .PHONY: get_deps_bin_size
   150  
   151  ###############################################################################
   152  ###                                  Libs                                   ###
   153  ###############################################################################
   154  
   155  # generates certificates for TLS testing in remotedb and RPC server
   156  gen_certs: clean_certs
   157  	certstrap init --common-name "tendermint.com" --passphrase ""
   158  	certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
   159  	certstrap sign "server" --CA "tendermint.com" --passphrase ""
   160  	mv out/server.crt rpc/jsonrpc/server/test.crt
   161  	mv out/server.key rpc/jsonrpc/server/test.key
   162  	rm -rf out
   163  .PHONY: gen_certs
   164  
   165  # deletes generated certificates
   166  clean_certs:
   167  	rm -f rpc/jsonrpc/server/test.crt
   168  	rm -f rpc/jsonrpc/server/test.key
   169  .PHONY: clean_certs
   170  
   171  ###############################################################################
   172  ###                  Formatting, linting, and vetting                       ###
   173  ###############################################################################
   174  
   175  format:
   176  	find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
   177  	find . -name '*.go' -type f -not -path "*.git*"  -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/tendermint/tendermint
   178  .PHONY: format
   179  
   180  lint:
   181  	@echo "--> Running linter"
   182  	@golangci-lint run
   183  .PHONY: lint
   184  
   185  DESTINATION = ./index.html.md
   186  
   187  ###############################################################################
   188  ###                           Documentation                                 ###
   189  ###############################################################################
   190  # todo remove once tendermint.com DNS is solved
   191  build-docs:
   192  	@cd docs && \
   193  	while read -r branch path_prefix; do \
   194  		(git checkout $${branch} && npm install && VUEPRESS_BASE="/$${path_prefix}/" npm run build) ; \
   195  		mkdir -p ~/output/$${path_prefix} ; \
   196  		cp -r .vuepress/dist/* ~/output/$${path_prefix}/ ; \
   197  		cp ~/output/$${path_prefix}/index.html ~/output ; \
   198  	done < versions ;
   199  .PHONY: build-docs
   200  
   201  ###############################################################################
   202  ###                            Docker image                                 ###
   203  ###############################################################################
   204  
   205  build-docker: build-linux
   206  	cp $(BUILDDIR)/tendermint DOCKER/tendermint
   207  	docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
   208  	rm -rf DOCKER/tendermint
   209  .PHONY: build-docker
   210  
   211  ###############################################################################
   212  ###                       Local testnet using docker                        ###
   213  ###############################################################################
   214  
   215  # Build linux binary on other platforms
   216  build-linux: tools
   217  	GOOS=linux GOARCH=amd64 $(MAKE) build
   218  .PHONY: build-linux
   219  
   220  build-docker-localnode:
   221  	@cd networks/local && make
   222  .PHONY: build-docker-localnode
   223  
   224  # Runs `make build TENDERMINT_BUILD_OPTIONS=cleveldb` from within an Amazon
   225  # Linux (v2)-based Docker build container in order to build an Amazon
   226  # Linux-compatible binary. Produces a compatible binary at ./build/tendermint
   227  build_c-amazonlinux:
   228  	$(MAKE) -C ./DOCKER build_amazonlinux_buildimage
   229  	docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux
   230  .PHONY: build_c-amazonlinux
   231  
   232  # Run a 4-node testnet locally
   233  localnet-start: localnet-stop build-docker-localnode
   234  	@if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --config /etc/tendermint/config-template.toml --o . --starting-ip-address 192.167.10.2; fi
   235  	docker-compose up
   236  .PHONY: localnet-start
   237  
   238  # Stop testnet
   239  localnet-stop:
   240  	docker-compose down
   241  .PHONY: localnet-stop
   242  
   243  # Build hooks for dredd, to skip or add information on some steps
   244  build-contract-tests-hooks:
   245  ifeq ($(OS),Windows_NT)
   246  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests
   247  else
   248  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests
   249  endif
   250  .PHONY: build-contract-tests-hooks
   251  
   252  # Run a nodejs tool to test endpoints against a localnet
   253  # The command takes care of starting and stopping the network
   254  # prerequisits: build-contract-tests-hooks build-linux
   255  # the two build commands were not added to let this command run from generic containers or machines.
   256  # The binaries should be built beforehand
   257  contract-tests:
   258  	dredd
   259  .PHONY: contract-tests
   260  
   261  clean:
   262  	rm -rf $(CURDIR)/artifacts/ $(BUILDDIR)/
   263  
   264  build-reproducible:
   265  	docker rm latest-build || true
   266  	docker run --volume=$(CURDIR):/sources:ro \
   267  		--env TARGET_PLATFORMS='linux/amd64 linux/arm64 darwin/amd64 windows/amd64' \
   268  		--env APP=tendermint \
   269  		--env COMMIT=$(shell git rev-parse --short=8 HEAD) \
   270  		--env VERSION=$(shell git describe --tags) \
   271  		--name latest-build cosmossdk/rbuilder:latest
   272  	docker cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
   273  .PHONY: build-reproducible