github.com/btcsuite/btcd@v0.24.0/Makefile (about) 1 PKG := github.com/btcsuite/btcd 2 3 LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint 4 GOACC_PKG := github.com/ory/go-acc 5 GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports 6 7 GO_BIN := ${GOPATH}/bin 8 LINT_BIN := $(GO_BIN)/golangci-lint 9 GOACC_BIN := $(GO_BIN)/go-acc 10 11 LINT_COMMIT := v1.18.0 12 GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b 13 14 DEPGET := cd /tmp && go get -v 15 GOBUILD := go build -v 16 GOINSTALL := go install -v 17 DEV_TAGS := rpctest 18 GOTEST_DEV = go test -v -tags=$(DEV_TAGS) 19 GOTEST := go test -v 20 21 GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") 22 23 RM := rm -f 24 CP := cp 25 MAKE := make 26 XARGS := xargs -L 1 27 28 # Linting uses a lot of memory, so keep it under control by limiting the number 29 # of workers if requested. 30 ifneq ($(workers),) 31 LINT_WORKERS = --concurrency=$(workers) 32 endif 33 34 LINT = $(LINT_BIN) run -v $(LINT_WORKERS) 35 36 GREEN := "\\033[0;32m" 37 NC := "\\033[0m" 38 define print 39 echo $(GREEN)$1$(NC) 40 endef 41 42 default: build 43 44 all: build check 45 46 # ============ 47 # DEPENDENCIES 48 # ============ 49 50 $(LINT_BIN): 51 @$(call print, "Fetching linter") 52 $(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) 53 54 $(GOACC_BIN): 55 @$(call print, "Fetching go-acc") 56 $(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT) 57 58 goimports: 59 @$(call print, "Installing goimports.") 60 $(DEPGET) $(GOIMPORTS_PKG) 61 62 # ============ 63 # INSTALLATION 64 # ============ 65 66 build: 67 @$(call print, "Building all binaries") 68 $(GOBUILD) $(PKG) 69 $(GOBUILD) $(PKG)/cmd/btcctl 70 $(GOBUILD) $(PKG)/cmd/gencerts 71 $(GOBUILD) $(PKG)/cmd/findcheckpoint 72 $(GOBUILD) $(PKG)/cmd/addblock 73 74 install: 75 @$(call print, "Installing all binaries") 76 $(GOINSTALL) $(PKG) 77 $(GOINSTALL) $(PKG)/cmd/btcctl 78 $(GOINSTALL) $(PKG)/cmd/gencerts 79 $(GOINSTALL) $(PKG)/cmd/findcheckpoint 80 $(GOINSTALL) $(PKG)/cmd/addblock 81 82 release-install: 83 @$(call print, "Installing btcd and btcctl release binaries") 84 env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG) 85 env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG)/cmd/btcctl 86 87 # ======= 88 # TESTING 89 # ======= 90 91 check: unit 92 93 unit: 94 @$(call print, "Running unit tests.") 95 $(GOTEST_DEV) ./... -test.timeout=20m 96 cd btcec; $(GOTEST_DEV) ./... -test.timeout=20m 97 cd btcutil; $(GOTEST_DEV) ./... -test.timeout=20m 98 cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m 99 100 unit-cover: $(GOACC_BIN) 101 @$(call print, "Running unit coverage tests.") 102 $(GOACC_BIN) ./... 103 104 # We need to remove the /v2 pathing from the module to have it work 105 # nicely with the CI tool we use to render live code coverage. 106 cd btcec; $(GOACC_BIN) ./...; sed -i.bak 's/v2\///g' coverage.txt 107 108 cd btcutil; $(GOACC_BIN) ./... 109 110 cd btcutil/psbt; $(GOACC_BIN) ./... 111 112 unit-race: 113 @$(call print, "Running unit race tests.") 114 env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... 115 cd btcec; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... 116 cd btcutil; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... 117 cd btcutil/psbt; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... 118 119 # ========= 120 # UTILITIES 121 # ========= 122 123 fmt: goimports 124 @$(call print, "Fixing imports.") 125 goimports -w $(GOFILES_NOVENDOR) 126 @$(call print, "Formatting source.") 127 gofmt -l -w -s $(GOFILES_NOVENDOR) 128 129 lint: $(LINT_BIN) 130 @$(call print, "Linting source.") 131 $(LINT) 132 133 clean: 134 @$(call print, "Cleaning source.$(NC)") 135 $(RM) coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt 136 137 .PHONY: all \ 138 default \ 139 build \ 140 check \ 141 unit \ 142 unit-cover \ 143 unit-race \ 144 fmt \ 145 lint \ 146 clean