btcd/Makefile
Olaoluwa Osuntokun 3cacbd489e
build: adapt btcutil Makefile for usage in project
In this commit, we adapt the Makefile that was being used for the
btcutil project to work for btcd as well. The Makefile is pretty simple,
and is just a series of templated commands. Overtime, we can pull in
some of the `lnd` additions as well, which we use to handle our
reproducible build and verification system.
2022-01-10 18:45:03 -08:00

125 lines
2.8 KiB
Makefile

PKG := github.com/btcsuite/btcd
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
LINT_COMMIT := v1.18.0
GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b
DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
DEV_TAGS := rpctest
GOTEST := GO111MODULE=on go test -v -tags=$(DEV_TAGS)
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
LINT_WORKERS = --concurrency=$(workers)
endif
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef
default: build
all: build check
# ============
# DEPENDENCIES
# ============
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
goimports:
@$(call print, "Installing goimports.")
$(DEPGET) $(GOIMPORTS_PKG)
# ============
# INSTALLATION
# ============
build:
@$(call print, "Building all binaries")
$(GOBUILD) $(PKG)
$(GOBUILD) $(PKG)/cmd/btcctl
$(GOBUILD) $(PKG)/cmd/gencerts
$(GOBUILD) $(PKG)/cmd/findcheckpoint
$(GOBUILD) $(PKG)/cmd/addblock
# =======
# TESTING
# =======
check: unit
unit:
@$(call print, "Running unit tests.")
$(GOTEST) ./... -test.timeout=20m
cd btcutil; $(GOTEST) ./... -test.timeout=20m
cd btcutil/psbt; $(GOTEST) ./... -test.timeout=20m
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) ./...
cd btcutil; $(GOACC_BIN) ./...
cd btcutil/psbt; $(GOACC_BIN) ./...
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd btcutil; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd btcutil/psbt; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
# =========
# UTILITIES
# =========
fmt: goimports
@$(call print, "Fixing imports.")
goimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt
.PHONY: all \
default \
build \
check \
unit \
unit-cover \
unit-race \
fmt \
lint \
clean