Makefile RawHistoryFolder
1# Local and untagged builds report a development version. Release builds
2# are driven by GoReleaser, which injects the Git tag and build metadata.
3.DEFAULT_GOAL := help
4
5GO ?= go
6PKG ?= ./cmd/zut
7BINARY ?= zut
8BIN_DIR ?= bin
9DEV_VERSION ?= 0.0.0-dev
10VERSION ?= $(DEV_VERSION)
11GO_INSTALL_VERSION ?= latest
12GOLANGCI_LINT ?= golangci-lint
13GOLANGCI_LINT_VERSION ?= v2.12.2
14LDFLAGS := -s -w -X main.version=$(VERSION)
15
16.PHONY: help build install go-install test test-fast vet lint lint-install fmt-check fmt check run clean release
17
18help:
19 @printf '%s\n' \
20 'build build ./bin/zut' \
21 'install install the current checkout with go install' \
22 'go-install install a published module version (GO_INSTALL_VERSION=latest)' \
23 'test run all tests with the race detector' \
24 'test-fast run all tests without the race detector' \
25 'vet run go vet ./...' \
26 'lint run golangci-lint, vet, and verify gofmt' \
27 'lint-install install golangci-lint $(GOLANGCI_LINT_VERSION)' \
28 'fmt format Go source files' \
29 'check run test-fast and lint' \
30 'run build and run ./bin/zut (pass ARGS="...")' \
31 'clean remove build output' \
32 'release cross-build release binaries (set VERSION=...)'
33
34build:
35 @mkdir -p "$(BIN_DIR)"
36 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)" $(PKG)
37
38# Install the current checkout. With the default VERSION this is a dev build.
39install:
40 $(GO) install -trimpath -ldflags "$(LDFLAGS)" $(PKG)
41
42# Install a published/module version, rather than the current checkout.
43go-install:
44 $(GO) install github.com/bnema/zut/cmd/zut@$(GO_INSTALL_VERSION)
45
46test:
47 $(GO) test -race ./...
48
49test-fast:
50 $(GO) test ./...
51
52vet:
53 $(GO) vet ./...
54
55fmt-check:
56 @files="$$(gofmt -l . 2>&1)" || { printf '%s\n' "$$files" >&2; echo "gofmt failed" >&2; exit 1; }; \
57 if [ -n "$$files" ]; then printf '%s\n' "$$files" >&2; echo "gofmt issues" >&2; exit 1; fi
58
59lint: vet fmt-check
60 $(GOLANGCI_LINT) run ./...
61
62lint-install:
63 $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
64
65check: test-fast lint
66
67fmt:
68 gofmt -w .
69
70run: build
71 "$(BIN_DIR)/$(BINARY)" $(ARGS)
72
73clean:
74 rm -rf "$(BIN_DIR)"
75
76release:
77 @if [ "$(VERSION)" = "$(DEV_VERSION)" ] || [ "$(VERSION)" = "0.0.0" ] || printf '%s\n' "$(VERSION)" | grep -Eq '(^|[.-])[0-9]{14}-[A-Za-z0-9]+'; then \
78 echo "set VERSION to a release version, for example: make release VERSION=0.1.0" >&2; \
79 exit 1; \
80 fi
81 @mkdir -p "$(BIN_DIR)"
82 GOOS=linux GOARCH=amd64 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)-linux-amd64" $(PKG)
83 GOOS=linux GOARCH=arm64 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)-linux-arm64" $(PKG)
84 GOOS=darwin GOARCH=amd64 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)-darwin-amd64" $(PKG)
85 GOOS=darwin GOARCH=arm64 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)-darwin-arm64" $(PKG)
86 GOOS=windows GOARCH=amd64 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o "$(BIN_DIR)/$(BINARY)-windows-amd64.exe" $(PKG)