11# !/usr/bin/make -f
22
3- BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
4- COMMIT := $(shell git log -1 --format='% H')
5- BUILD_DIR ?= $(CURDIR ) /build
6- DIST_DIR ?= $(CURDIR ) /dist
7- LEDGER_ENABLED ?= true
8- TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
9- DOCKER := $(shell which docker)
10- PROJECT_NAME := bitcanna
11- HTTPS_GIT := https://github.com/BitCannaGlobal/bcna.git
12-
13- # ##############################################################################
14- # # Version ##
15- # ##############################################################################
3+ BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
4+ COMMIT := $(shell git log -1 --format='% H')
5+ GO_VERSION := "1.23"
6+ BUILD_DIR ?= $(CURDIR ) /build
167
8+ # don't override user values
179ifeq (,$(VERSION ) )
18- VERSION := $(shell git describe --tags | sed 's/^v//' )
10+ VERSION := $(shell git describe --tags)
1911 # if VERSION is empty, then populate it with branch's name and raw commit hash
2012 ifeq (,$(VERSION))
2113 VERSION := $(BRANCH ) -$(COMMIT )
2214 endif
2315endif
2416
25- GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
26- GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
27- # ##############################################################################
28- # # Build ##
29- # ##############################################################################
17+ PACKAGES_SIMTEST =$(shell go list ./... | grep '/simulation')
18+ LEDGER_ENABLED ?= true
19+ SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
20+ TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') # grab everything after the space in "github.com/cometbft/cometbft v0.37.0"
21+ BUILDDIR ?= $(CURDIR ) /build
22+ DOCKER := $(shell which docker)
23+ DOCKER_BUF := $(DOCKER ) run --rm -v $(CURDIR ) :/workspace --workdir /workspace bufbuild/buf:1.7.0
3024
31- build_tags = netgo
25+ export GO111MODULE = on
3226
27+ # process build tags
28+
29+ build_tags = netgo
3330ifeq ($(LEDGER_ENABLED ) ,true)
3431 ifeq ($(OS),Windows_NT)
3532 GCCEXE = $(shell where gcc.exe 2> NUL)
@@ -53,94 +50,115 @@ ifeq ($(LEDGER_ENABLED),true)
5350 endif
5451endif
5552
53+ ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS ) ) )
54+ build_tags += gcc cleveldb
55+ endif
56+ build_tags += $(BUILD_TAGS )
57+ build_tags := $(strip $(build_tags ) )
58+
5659whitespace :=
5760whitespace += $(whitespace )
5861comma := ,
5962build_tags_comma_sep := $(subst $(whitespace ) ,$(comma ) ,$(build_tags ) )
6063
64+ # process linker flags
65+
6166ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=bcna \
6267 -X github.com/cosmos/cosmos-sdk/version.AppName=bcnad \
6368 -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION ) \
6469 -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT ) \
6570 -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep ) " \
6671 -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION )
6772
73+ ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS ) ) )
74+ ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
75+ endif
76+ ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS ) ) )
77+ ldflags += -w -s
78+ endif
79+ ifeq ($(LINK_STATICALLY ) ,true)
80+ ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
81+ endif
6882ldflags += $(LDFLAGS )
6983ldflags := $(strip $(ldflags ) )
7084
7185BUILD_FLAGS := -tags "$(build_tags ) " -ldflags '$(ldflags ) '
72-
73- check_version :
74- ifeq ($(shell expr $(GO_MINOR_VERSION ) \< 23) , 1)
75- @echo "ERROR: Go version 1.23 or newer is required for building BCNAD."
76- exit 1
86+ # check for nostrip option
87+ ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS ) ) )
88+ BUILD_FLAGS += -trimpath
7789endif
7890
91+ # $(info $$BUILD_FLAGS is [$(BUILD_FLAGS)])
92+
93+
94+ all : check-go-version install
7995
80- build : check_version go.sum
81- @echo " --> Building..."
82- go build -mod=readonly $(BUILD_FLAGS ) -o $(BUILD_DIR ) / ./...
96+ install : check-go-version go.sum
97+ go install -mod=readonly $(BUILD_FLAGS ) ./...
8398
84- install : check_version go.sum
85- @echo " --> Installing..."
86- go install -mod=readonly $(BUILD_FLAGS ) ./...
99+ build : check-go-version
100+ go build $(BUILD_FLAGS ) -o $(BUILD_DIR ) / ./...
87101
88- build-linux : check_version go.sum
89- LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE ) build
102+ BUILD_TARGETS := build install
90103
91- go-mod-cache : check_version go.sum
92- @echo " --> Download go modules to local cache"
93- @go mod download
104+ build-reproducible-all : build-reproducible-amd64 build-reproducible-arm64
94105
95- go.sum : check_version go.mod
96- @echo " --> Ensure dependencies have not been modified"
97- @go mod verify
106+ build-reproducible-amd64 :
107+ ARCH=x86_64 PLATFORM=linux/amd64 $(MAKE ) build-reproducible-generic
98108
99- go-mod-tidy :
100- @contrib/scripts/go-mod-tidy-all.sh
109+ build-reproducible-arm64 :
110+ ARCH=aarch64 PLATFORM=linux/arm64 $(MAKE ) build-reproducible-generic
111+
112+ build-reproducible-generic : go.sum
113+ $(DOCKER ) rm $(subst /,-,latest-build-$(PLATFORM ) ) || true
114+ DOCKER_BUILDKIT=1 $(DOCKER ) build -t latest-build-$(PLATFORM ) \
115+ --build-arg ARCH=$(ARCH ) \
116+ --build-arg GO_VERSION=$(GO_VERSION ) \
117+ --build-arg PLATFORM=$(PLATFORM ) \
118+ --build-arg VERSION=" $( VERSION) " \
119+ -f Dockerfile .
120+ mkdir -p build
121+ $(DOCKER ) create -ti --name $(subst /,-,latest-build-$(PLATFORM ) ) latest-build-$(PLATFORM ) bcnad
122+ $(DOCKER ) cp -a $(subst /,-,latest-build-$(PLATFORM ) ) :/usr/local/bin/bcnad $(BUILD_DIR ) /bcnad_$(subst /,_,$(PLATFORM ) )
123+ sha256sum $(BUILD_DIR ) /bcnad_$(subst /,_,$(PLATFORM ) ) >> $(BUILD_DIR ) /bcnad_sha256.txt
124+
125+ # Add check to make sure we are using the proper Go version before proceeding with anything
126+ check-go-version :
127+ @if ! go version | grep -q " go$( GO_VERSION) " ; then \
128+ echo " \033[0;31mERROR:\033[0m Go version $( GO_VERSION) is required for compiling BCNAD. It looks like you are using" " $( shell go version) \nThere are potential consensus-breaking changes that can occur when running binaries compiled with different versions of Go. Please download Go version $( GO_VERSION) and retry. Thank you!" ; \
129+ exit 1; \
130+ fi
101131
102132clean :
103133 @echo " --> Cleaning..."
104134 @rm -rf $(BUILD_DIR ) /** $(DIST_DIR ) /**
105135
106- .PHONY : install build build-linux clean
107-
108136# ##############################################################################
109- # # Protobuf ##
137+ # ## Protobuf # ##
110138# ##############################################################################
111139
112- DOCKER_BUF := $(DOCKER ) run --rm -v $(CURDIR ) :/workspace --workdir /workspace bufbuild/buf
113-
114- containerProtoVer =v0.2
115- containerProtoImage =tendermintdev/sdk-proto-gen:$(containerProtoVer )
116- containerProtoGen =$(PROJECT_NAME ) -proto-gen-$(containerProtoVer )
117- containerProtoFmt =$(PROJECT_NAME ) -proto-fmt-$(containerProtoVer )
118- containerProtoGenSwagger =$(PROJECT_NAME ) -proto-gen-swagger-$(containerProtoVer )
119-
120- proto-all : proto-format proto-lint proto-gen proto-swagger-gen
140+ containerProtoVer =0.13.0
141+ containerProtoImage =ghcr.io/cosmos/proto-builder:$(containerProtoVer )
121142
122143proto-gen :
123144 @echo " Generating Protobuf files"
124- @if docker ps -a --format ' {{.Names}}' | grep -Eq " ^${containerProtoGen} $$ " ; then docker start -a $(containerProtoGen ) ; else docker run --name $(containerProtoGen ) -v $(CURDIR ) :/workspace --workdir /workspace $(containerProtoImage ) \
125- sh ./scripts/protocgen.sh; fi
126-
127- proto-swagger-gen :
128- @echo " Generating Swagger of Protobuf"
129- @if docker ps -a --format ' {{.Names}}' | grep -Eq " ^${containerProtoGenSwagger} $$ " ; then docker start -a $(containerProtoGenSwagger ) ; else docker run --name $(containerProtoGenSwagger ) -v $(CURDIR ) :/workspace --workdir /workspace $(containerProtoImage ) \
130- sh ./scripts/protoc-swagger-gen.sh; fi
131-
132- proto-format :
133- @echo " Formatting Protobuf files"
134- @if docker ps -a --format ' {{.Names}}' | grep -Eq " ^${containerProtoFmt} $$ " ; then docker start -a $(containerProtoFmt ) ; else docker run --name $(containerProtoFmt ) -v $(CURDIR ) :/workspace --workdir /workspace tendermintdev/docker-build-proto \
135- find ./ -name " *.proto" -exec sh -c ' clang-format -style=file -i {}' \; ; fi
136-
137- proto-lint :
138- @echo " Linting Protobuf files"
139- @$(DOCKER_BUF ) lint --error-format=json
140-
141- proto-check-breaking :
142- @echo " Checking for breaking changes"
143- @$(DOCKER_BUF ) breaking --against $(HTTPS_GIT ) # branch=main
144-
145-
146- .PHONY : proto-all proto-gen proto-lint proto-check-breaking proto-format proto-swagger-gen
145+ @$(DOCKER ) run --rm -v $(CURDIR ) :/workspace --workdir /workspace $(containerProtoImage ) \
146+ sh ./scripts/protocgen.sh;
147+
148+ docs :
149+ @echo
150+ @echo " =========== Generate Message ============"
151+ @echo
152+ ./scripts/protoc-swagger-gen.sh
153+
154+ statik -src=docs/static -dest=docs -f -m
155+ @if [ -n "$(git status --porcelain)" ]; then \
156+ echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
157+ exit 1;\
158+ else \
159+ echo "\033[92mSwagger docs are in sync\033[0m";\
160+ fi
161+ @echo
162+ @echo "=========== Generate Complete ============"
163+ @echo
164+ .PHONY : docs
0 commit comments