|
| 1 | +# Makefile for building and linting Go project |
| 2 | + |
| 3 | +# Basic project settings |
| 4 | +BINARY_NAME=junction-jip-2 |
| 5 | +BUILD_DIR=./build |
| 6 | +SOURCE_DIR=./cmd/junctiond |
| 7 | +CHECKSUM_FILE=$(BUILD_DIR)/checksums.txt |
| 8 | + |
| 9 | +# Go commands |
| 10 | +GO_BUILD=go build |
| 11 | +GO_INSTALL=go install |
| 12 | +GO_CLEAN=go clean |
| 13 | +GO_TEST=go test |
| 14 | + |
| 15 | +# Versioning |
| 16 | +VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1`) |
| 17 | +COMMIT := $(shell git log -1 --format='%H') |
| 18 | +TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') |
| 19 | + |
| 20 | +# Build tags |
| 21 | +build_tags = netgo |
| 22 | +build_tags += $(BUILD_TAGS) |
| 23 | +build_tags := $(strip $(build_tags)) |
| 24 | + |
| 25 | +# Linker flags |
| 26 | +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=junction \ |
| 27 | + -X github.com/cosmos/cosmos-sdk/version.AppName=$(BINARY_NAME) \ |
| 28 | + -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ |
| 29 | + -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ |
| 30 | + -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)" \ |
| 31 | + -X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION) |
| 32 | + |
| 33 | +# Linter settings |
| 34 | +GOLINT=golangci-lint |
| 35 | +LINT_OPTIONS=--enable-all |
| 36 | +ifeq ($(VERSION),1.0.0) |
| 37 | + LINT_OPTIONS+=--disable=errcheck |
| 38 | +endif |
| 39 | + |
| 40 | +# Default target |
| 41 | +default: build |
| 42 | + |
| 43 | +# Build the project for the current architecture |
| 44 | +build: go.sum |
| 45 | + @echo "Building $(BINARY_NAME) binary..." |
| 46 | + $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME) $(SOURCE_DIR) |
| 47 | + |
| 48 | +# Install the binary |
| 49 | +install: |
| 50 | + @echo "Installing $(BINARY_NAME) binary..." |
| 51 | + $(GO_INSTALL) -tags "$(build_tags)" -ldflags '$(ldflags)' $(SOURCE_DIR) |
| 52 | + |
| 53 | +# Run tests |
| 54 | +test: |
| 55 | + @echo "Running tests..." |
| 56 | + $(GO_TEST) ./... |
| 57 | + |
| 58 | +# Clean build artifacts |
| 59 | +clean: |
| 60 | + @echo "Cleaning up old versions..." |
| 61 | + $(GO_CLEAN) |
| 62 | + rm -f $(BUILD_DIR)/$(BINARY_NAME) $(CHECKSUM_FILE) |
| 63 | + |
| 64 | +# Lint the project |
| 65 | +lint: |
| 66 | + @echo "Running linter..." |
| 67 | + $(GOLINT) run $(LINT_OPTIONS) |
| 68 | + |
| 69 | +# Print system information |
| 70 | +print-system: |
| 71 | + @echo "System architecture: $(shell uname -s)/$(shell uname -m)" |
| 72 | + |
| 73 | +# Build the project for different architectures and generate checksums |
| 74 | +build-all: go.sum |
| 75 | + @echo "Building $(BINARY_NAME) for different architectures..." |
| 76 | + rm -f $(CHECKSUM_FILE) |
| 77 | + GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(SOURCE_DIR) |
| 78 | + @shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 >> $(CHECKSUM_FILE) |
| 79 | +# GOOS=linux GOARCH=arm64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(SOURCE_DIR) |
| 80 | +# @shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 >> $(CHECKSUM_FILE) |
| 81 | +# GOOS=darwin GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(SOURCE_DIR) |
| 82 | +# @shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 >> $(CHECKSUM_FILE) |
| 83 | +# GOOS=darwin GOARCH=arm64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(SOURCE_DIR) |
| 84 | +# @shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 >> $(CHECKSUM_FILE) |
| 85 | +# GOOS=windows GOARCH=amd64 $(GO_BUILD) -tags "$(build_tags)" -ldflags '$(ldflags)' -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(SOURCE_DIR) |
| 86 | +# @shasum -a 256 $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe >> $(CHECKSUM_FILE) |
| 87 | + |
| 88 | +.PHONY: default build install test clean lint print-system build-all |
0 commit comments