-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
118 lines (95 loc) · 3.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Setup name variables for the package/tool
NAME := regview
PKG := github.com/ricardobranco777/$(NAME)
CGO_ENABLED := 0
# Set the shell
SHELL := /bin/bash
# Set the build dir, where built cross-compiled binaries will be output
BUILDDIR := cross
# Set our default go compiler
GO := go
# List the GOOS and GOARCH to build
GOOSARCHES = $(shell cat .goosarch)
# Files generated by easyjson
EASYJSON = $(shell grep -rl "go:generate easyjson" oci | sed 's/\.go$$/_easyjson&/')
.PHONY: build
build: prebuild $(NAME) ## Builds a dynamic executable or package.
$(NAME): $(wildcard *.go) $(wildcard */*.go)
@echo "+ $@"
CGO_ENABLED=$(CGO_ENABLED) GOFLAGS=$(GOFLAGS) $(GO) build -o $(NAME) .
.PHONY: gen
gen:
@rm -f go.mod go.sum
@go mod init $(BIN)
@go mod tidy
@go get github.com/ricardobranco777/simplepki
.PHONY: all
all: clean build fmt test staticcheck vet install ## Runs a clean, build, fmt, test, staticcheck, vet and install.
.PHONY: fmt
fmt: prebuild ## Verifies all files have been `gofmt`ed.
@echo "+ $@"
@if [[ ! -z "$(shell gofmt -s -l . | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: test
test: prebuild ## Runs the go tests.
@echo "+ $@"
@$(GO) test -v $(shell $(GO) list ./...)
.PHONY: vet
vet: prebuild ## Verifies `go vet` passes.
@echo "+ $@"
@if [[ ! -z "$(shell $(GO) vet $(shell $(GO) list ./...) | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: staticcheck
staticcheck: prebuild ## Verifies `staticcheck` passes.
@go install honnef.co/go/tools/cmd/staticcheck@2023.1.6
@echo "+ $@"
@if [[ ! -z "$(shell staticcheck $(shell $(GO) list ./...) | tee /dev/stderr)" ]]; then \
exit 1; \
fi
.PHONY: cover
cover: prebuild ## Runs go test with coverage.
@echo "" > coverage.txt
@for d in $(shell $(GO) list ./...); do \
$(GO) test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done;
.PHONY: install
install: prebuild ## Installs the executable or package.
@echo "+ $@"
$(GO) install -a .
define buildpretty
mkdir -p $(BUILDDIR)/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=$(CGO_ENABLED) $(GO) build \
-a -o $(BUILDDIR)/$(1)/$(2)/$(NAME) .;
sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256;
endef
.PHONY: cross
cross: *.go prebuild ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary).
@echo "+ $@"
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))
define buildrelease
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=$(CGO_ENABLED) $(GO) build \
-a -o $(BUILDDIR)/$(NAME)-$(1)-$(2) .;
sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256;
endef
.PHONY: release
release: *.go prebuild ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH).
@echo "+ $@"
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))
.PHONY: clean
clean: ## Cleanup any build binaries or packages.
@echo "+ $@"
$(RM) $(NAME)
$(RM) -r $(BUILDDIR)
$(RM) $(EASYJSON)
$(RM) tests/certs/*
.PHONY: prebuild
prebuild: $(EASYJSON)
$(EASYJSON):
@go install github.com/mailru/easyjson/...@latest
@go generate -x ./...