github.com/Finschia/ostracon@v1.1.5/Makefile (about)

     1  PACKAGES=$(shell go list ./...)
     2  SRCPATH=$(shell pwd)
     3  OUTPUT?=build/ostracon
     4  
     5  INCLUDE = -I=${GOPATH}/src/github.com/Finschia/ostracon -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
     6  BUILD_TAGS ?= ostracon
     7  VERSION := $(shell git describe --always)
     8  LD_FLAGS = -X github.com/Finschia/ostracon/version.OCCoreSemVer=$(VERSION)
     9  BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
    10  HTTPS_GIT := https://github.com/Finschia/ostracon.git
    11  CGO_ENABLED ?= 0
    12  TARGET_OS ?= $(shell go env GOOS)
    13  TARGET_ARCH ?= $(shell go env GOARCH)
    14  
    15  # handle nostrip
    16  ifeq (,$(findstring nostrip,$(OSTRACON_BUILD_OPTIONS)))
    17    BUILD_FLAGS += -trimpath
    18    LD_FLAGS += -s -w
    19  endif
    20  
    21  # handle race
    22  ifeq (race,$(findstring race,$(OSTRACON_BUILD_OPTIONS)))
    23    BUILD_FLAGS += -race
    24  endif
    25  
    26  # handle cleveldb
    27  ifeq (cleveldb,$(findstring cleveldb,$(OSTRACON_BUILD_OPTIONS)))
    28    BUILD_TAGS += cleveldb
    29  endif
    30  
    31  # handle badgerdb
    32  ifeq (badgerdb,$(findstring badgerdb,$(OSTRACON_BUILD_OPTIONS)))
    33    BUILD_TAGS += badgerdb
    34  endif
    35  
    36  # handle rocksdb
    37  ifeq (rocksdb,$(findstring rocksdb,$(OSTRACON_BUILD_OPTIONS)))
    38    CGO_ENABLED=1
    39    BUILD_TAGS += rocksdb
    40  endif
    41  
    42  # handle boltdb
    43  ifeq (boltdb,$(findstring boltdb,$(OSTRACON_BUILD_OPTIONS)))
    44    BUILD_TAGS += boltdb
    45  endif
    46  
    47  # allow users to pass additional flags via the conventional LDFLAGS variable
    48  LD_FLAGS += $(LDFLAGS)
    49  
    50  all: build test install
    51  .PHONY: all
    52  
    53  include tests.mk
    54  
    55  ###############################################################################
    56  ###                                Build Ostracon                           ###
    57  ###############################################################################
    58  
    59  build:
    60  	CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -o $(OUTPUT) ./cmd/ostracon/
    61  .PHONY: build
    62  
    63  install:
    64  	CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" ./cmd/ostracon
    65  .PHONY: install
    66  
    67  ###############################################################################
    68  ###                                Mocks                                    ###
    69  ###############################################################################
    70  
    71  mockery:
    72  	go generate -run="./scripts/mockery_generate.sh" ./...
    73  .PHONY: mockery
    74  
    75  ###############################################################################
    76  ###                                Protobuf                                 ###
    77  ###############################################################################
    78  
    79  check-proto-deps:
    80  ifeq (,$(shell which protoc-gen-gogofaster))
    81  	@go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest
    82  endif
    83  .PHONY: check-proto-deps
    84  
    85  check-proto-format-deps:
    86  ifeq (,$(shell which clang-format))
    87  	$(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.")
    88  endif
    89  .PHONY: check-proto-format-deps
    90  
    91  proto-gen: check-proto-deps
    92  	@echo "Generating Protobuf files"
    93  	@go run github.com/bufbuild/buf/cmd/buf generate
    94  	@mv ./proto/ostracon/abci/types.pb.go ./abci/types/
    95  	@mv ./proto/ostracon/rpc/grpc/types.pb.go ./rpc/grpc/
    96  	@rm -rf ./proto/tendermint
    97  .PHONY: proto-gen
    98  
    99  # These targets are provided for convenience and are intended for local
   100  # execution only.
   101  proto-lint: check-proto-deps
   102  	@echo "Linting Protobuf files"
   103  	@go run github.com/bufbuild/buf/cmd/buf lint
   104  .PHONY: proto-lint
   105  
   106  proto-format: check-proto-format-deps
   107  	@echo "Formatting Protobuf files"
   108  	@find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \;
   109  .PHONY: proto-format
   110  
   111  proto-check-breaking: check-proto-deps
   112  	@echo "Checking for breaking changes in Protobuf files against local branch"
   113  	@echo "Note: This is only useful if your changes have not yet been committed."
   114  	@echo "      Otherwise read up on buf's \"breaking\" command usage:"
   115  	@echo "      https://docs.buf.build/breaking/usage"
   116  	@go run github.com/bufbuild/buf/cmd/buf breaking --against ".git"
   117  .PHONY: proto-check-breaking
   118  
   119  proto-check-breaking-ci:
   120  	@go run github.com/bufbuild/buf/cmd/buf breaking --against ".git"#branch=main
   121  .PHONY: proto-check-breaking-ci
   122  
   123  ###############################################################################
   124  ###                              Build ABCI                                 ###
   125  ###############################################################################
   126  
   127  build_abci:
   128  	@go build -mod=readonly -i ./abci/cmd/...
   129  .PHONY: build_abci
   130  
   131  install_abci:
   132  	@go install -mod=readonly ./abci/cmd/...
   133  .PHONY: install_abci
   134  
   135  ###############################################################################
   136  ###                              Distribution                               ###
   137  ###############################################################################
   138  
   139  ########################################
   140  ### Distribution
   141  
   142  # dist builds binaries for all platforms and packages them for distribution
   143  # TODO add abci to these scripts
   144  dist:
   145  	@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
   146  .PHONY: dist
   147  
   148  go-mod-cache: go.sum
   149  	@echo "--> Download go modules to local cache"
   150  	@go mod download
   151  .PHONY: go-mod-cache
   152  
   153  go.sum: go.mod
   154  	@echo "--> Ensure dependencies have not been modified"
   155  	@go mod verify
   156  	@go mod tidy
   157  
   158  draw_deps:
   159  	@# requires brew install graphviz or apt-get install graphviz
   160  	go get github.com/RobotsAndPencils/goviz
   161  	@goviz -i github.com/Finschia/ostracon/cmd/ostracon -d 3 | dot -Tpng -o dependency-graph.png
   162  .PHONY: draw_deps
   163  
   164  get_deps_bin_size:
   165  	@# Copy of build recipe with additional flags to perform binary size analysis
   166  	$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/ostracon/ 2>&1))
   167  	@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
   168  	@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
   169  .PHONY: get_deps_bin_size
   170  
   171  ###############################################################################
   172  ###                                  Libs                                   ###
   173  ###############################################################################
   174  
   175  # generates certificates for TLS testing in remotedb and RPC server
   176  gen_certs: clean_certs
   177  	certstrap init --common-name "finschia.org" --passphrase ""
   178  	certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
   179  	certstrap sign "server" --CA "finschia.org" --passphrase ""
   180  	mv out/server.crt rpc/jsonrpc/server/test.crt
   181  	mv out/server.key rpc/jsonrpc/server/test.key
   182  	rm -rf out
   183  .PHONY: gen_certs
   184  
   185  # deletes generated certificates
   186  clean_certs:
   187  	rm -f rpc/jsonrpc/server/test.crt
   188  	rm -f rpc/jsonrpc/server/test.key
   189  .PHONY: clean_certs
   190  
   191  ###############################################################################
   192  ###                  Formatting, linting, and vetting                       ###
   193  ###############################################################################
   194  
   195  format:
   196  	find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
   197  	find . -name '*.go' -type f -not -path "*.git*"  -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/Finschia/ostracon
   198  .PHONY: format
   199  
   200  lint:
   201  	@echo "--> Running linter"
   202  	@go run github.com/golangci/golangci-lint/cmd/golangci-lint run
   203  .PHONY: lint
   204  
   205  DESTINATION = ./index.html.md
   206  
   207  ###############################################################################
   208  ###                           Documentation                                 ###
   209  ###############################################################################
   210  
   211  BRANCH := $(shell git branch --show-current)
   212  BRANCH_URI := $(shell git branch --show-current | sed 's/[\#]/%23/g')
   213  build-docs:
   214  	@cd docs && \
   215  	npm install && \
   216  	VUEPRESS_BASE="/$(BRANCH_URI)/" npm run build && \
   217  	mkdir -p ~/output/$(BRANCH) && \
   218  	cp -r .vuepress/dist/* ~/output/$(BRANCH)/ && \
   219  	for f in `find . -name '*.png' | grep -v '/node_modules/'`; do if [ ! -e `dirname $$f` ]; then mkdir `dirname $$f`; fi; cp $$f ~/output/$(BRANCH)/`dirname $$f`; done && \
   220  	echo '<html><head><meta http-equiv="refresh" content="0;/$(BRANCH_URI)/index.html"/></head></html>' > ~/output/index.html
   221  .PHONY: build-docs
   222  
   223  sync-docs:
   224  	cd ~/output && \
   225  	echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \
   226  	echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \
   227  	aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \
   228  	aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
   229  .PHONY: sync-docs
   230  
   231  ###############################################################################
   232  ###                            Docker image                                 ###
   233  ###############################################################################
   234  
   235  # Build linux binary on other platforms
   236  # Should run from within a linux if CGO_ENABLED=1
   237  build-linux:
   238  	GOOS=linux GOARCH=$(TARGET_ARCH) $(MAKE) build
   239  .PHONY: build-linux
   240  
   241  build-linux-docker:
   242  	docker build --label=ostracon --tag="ostracon/ostracon" -f ./DOCKER/Dockerfile .
   243  .PHONY: build-linux-docker
   244  
   245  standalone-linux-docker:
   246  	docker run -it --rm -v "/tmp:/ostracon" -p 26656:26656 -p 26657:26657 -p 26660:26660  ostracon/ostracon
   247  .PHONY: standalone-linux-docker
   248  
   249  # XXX Warning: Not test yet
   250  # Runs `make build OSTRACON_BUILD_OPTIONS=cleveldb` from within an Amazon
   251  # Linux (v2)-based Docker build container in order to build an Amazon
   252  # Linux-compatible binary. Produces a compatible binary at ./build/ostracon
   253  build_c-amazonlinux:
   254  	$(MAKE) -C ./DOCKER build_amazonlinux_buildimage
   255  	docker run --rm -it -v `pwd`:/ostracon ostracon/ostracon:build_c-amazonlinux
   256  .PHONY: build_c-amazonlinux
   257  
   258  ###############################################################################
   259  ###                       Local testnet using docker                        ###
   260  ###############################################################################
   261  
   262  DOCKER_HOME = /go/src/github.com/Finschia/ostracon
   263  DOCKER_CMD = docker run --rm \
   264                          -v `pwd`:$(DOCKER_HOME) \
   265                          -w $(DOCKER_HOME)
   266  DOCKER_IMG = golang:1.20-alpine
   267  BUILD_CMD = apk add --update --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang libtool autoconf automake \
   268  	&& cd $(DOCKER_HOME) \
   269  	&& make build-linux
   270  
   271  # Login docker-container for confirmation building linux binary
   272  build-shell:
   273  	$(DOCKER_CMD) -it --entrypoint '' ${DOCKER_IMG} /bin/sh
   274  .PHONY: build-shell
   275  
   276  build-localnode:
   277  	$(DOCKER_CMD) ${DOCKER_IMG} /bin/sh -c "$(BUILD_CMD)"
   278  .PHONY: build-localnode
   279  
   280  build-localnode-docker: build-localnode
   281  	@cd networks/local && make
   282  .PHONY: build-localnode-docker
   283  
   284  # Run a 4-node testnet locally
   285  localnet-start: localnet-stop build-localnode-docker
   286  	@if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/ostracon:Z ostracon/localnode testnet --config /etc/ostracon/config-template.toml --o . --starting-ip-address 192.167.10.2; fi
   287  	docker-compose up
   288  .PHONY: localnet-start
   289  
   290  # Stop testnet
   291  localnet-stop:
   292  	docker-compose down
   293  .PHONY: localnet-stop