refactor: add make help command that describes goals

This commit is contained in:
Halimao 2024-01-22 16:23:43 +08:00
parent 17fdc5219b
commit 2a55ff4884

View File

@ -39,8 +39,10 @@ define print
echo $(GREEN)$1$(NC) echo $(GREEN)$1$(NC)
endef endef
#? default: Run `make build`
default: build default: build
#? all: Run `make build` and `make check`
all: build check all: build check
# ============ # ============
@ -55,6 +57,7 @@ $(GOACC_BIN):
@$(call print, "Fetching go-acc") @$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT) $(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
#? goimports: Install goimports
goimports: goimports:
@$(call print, "Installing goimports.") @$(call print, "Installing goimports.")
$(DEPGET) $(GOIMPORTS_PKG) $(DEPGET) $(GOIMPORTS_PKG)
@ -63,6 +66,7 @@ goimports:
# INSTALLATION # INSTALLATION
# ============ # ============
#? build: Build all binaries, place them in project directory
build: build:
@$(call print, "Building all binaries") @$(call print, "Building all binaries")
$(GOBUILD) $(PKG) $(GOBUILD) $(PKG)
@ -71,6 +75,7 @@ build:
$(GOBUILD) $(PKG)/cmd/findcheckpoint $(GOBUILD) $(PKG)/cmd/findcheckpoint
$(GOBUILD) $(PKG)/cmd/addblock $(GOBUILD) $(PKG)/cmd/addblock
#? install: Install all binaries, place them in $GOPATH/bin
install: install:
@$(call print, "Installing all binaries") @$(call print, "Installing all binaries")
$(GOINSTALL) $(PKG) $(GOINSTALL) $(PKG)
@ -79,6 +84,7 @@ install:
$(GOINSTALL) $(PKG)/cmd/findcheckpoint $(GOINSTALL) $(PKG)/cmd/findcheckpoint
$(GOINSTALL) $(PKG)/cmd/addblock $(GOINSTALL) $(PKG)/cmd/addblock
#? release-install: Install btcd and btcctl release binaries, place them in $GOPATH/bin
release-install: release-install:
@$(call print, "Installing btcd and btcctl release binaries") @$(call print, "Installing btcd and btcctl release binaries")
env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG) env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG)
@ -88,8 +94,10 @@ release-install:
# TESTING # TESTING
# ======= # =======
#? check: Run `make unit`
check: unit check: unit
#? unit: Run unit tests
unit: unit:
@$(call print, "Running unit tests.") @$(call print, "Running unit tests.")
$(GOTEST_DEV) ./... -test.timeout=20m $(GOTEST_DEV) ./... -test.timeout=20m
@ -97,6 +105,7 @@ unit:
cd btcutil; $(GOTEST_DEV) ./... -test.timeout=20m cd btcutil; $(GOTEST_DEV) ./... -test.timeout=20m
cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m
#? unit-cover: Run unit coverage tests
unit-cover: $(GOACC_BIN) unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.") @$(call print, "Running unit coverage tests.")
$(GOACC_BIN) ./... $(GOACC_BIN) ./...
@ -109,6 +118,7 @@ unit-cover: $(GOACC_BIN)
cd btcutil/psbt; $(GOACC_BIN) ./... cd btcutil/psbt; $(GOACC_BIN) ./...
#? unit-race: Run unit race tests
unit-race: unit-race:
@$(call print, "Running unit race tests.") @$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
@ -120,20 +130,24 @@ unit-race:
# UTILITIES # UTILITIES
# ========= # =========
#? fmt: Fix imports and formatting source
fmt: goimports fmt: goimports
@$(call print, "Fixing imports.") @$(call print, "Fixing imports.")
goimports -w $(GOFILES_NOVENDOR) goimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.") @$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR) gofmt -l -w -s $(GOFILES_NOVENDOR)
#? lint: Lint source
lint: $(LINT_BIN) lint: $(LINT_BIN)
@$(call print, "Linting source.") @$(call print, "Linting source.")
$(LINT) $(LINT)
#? clean: Clean source
clean: clean:
@$(call print, "Cleaning source.$(NC)") @$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt $(RM) coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt
#? tidy-module: Run 'go mod tidy' for all modules
tidy-module: tidy-module:
echo "Running 'go mod tidy' for all modules" echo "Running 'go mod tidy' for all modules"
scripts/tidy_modules.sh scripts/tidy_modules.sh
@ -148,3 +162,10 @@ tidy-module:
fmt \ fmt \
lint \ lint \
clean clean
#? help: Get more info on make commands
help: Makefile
@echo " Choose a command run in btcd:"
@sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /'
.PHONY: help