-
Notifications
You must be signed in to change notification settings - Fork 609
Expand file tree
/
Copy pathGNUmakefile
More file actions
101 lines (79 loc) · 2.6 KB
/
Copy pathGNUmakefile
File metadata and controls
101 lines (79 loc) · 2.6 KB
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
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -euc
.DEFAULT_GOAL := dev
VERSION := $(shell awk -F\" '/Version = "(.*)"/ { print $$2; exit }' version/version.go)
GITSHA:=$(shell git rev-parse HEAD)
GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
GIT_COMMIT_FLAG = $(GO_MODULE)/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)
GO_MODULE = github.com/hashicorp/serf
GO_LDFLAGS = -X $(GIT_COMMIT_FLAG)
GO_PKGS ?= $(shell go list ./...)
# ----------------------------------------------------------
# build and package for distribution
.PHONY: dev dist clean
# dev creates binaries for testing locally - these are put into ./bin
dev: GOOS=$(shell go env GOOS)
dev: GOARCH=$(shell go env GOARCH)
dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/serf
dev:
$(MAKE) --no-print-directory $(DEV_TARGET)
mkdir -p ./bin
cp $(DEV_TARGET) ./bin/serf
ALL_TARGETS = linux_amd64 \
linux_arm64 \
darwin_arm64 \
windows_amd64 \
freebsd_amd64 \
openbsd_amd64 \
solaris_amd64 \
illumos_amd64
# dist creates the binaries for distibution and bundles them into zip files
dist: $(foreach t,$(ALL_TARGETS),pkg/serf_$(t).zip)
pkg/serf_%.zip: pkg/%/serf
zip pkg/serf_$(VERSION)_$*.zip pkg/$*/*
pkg/%/serf: GO_OUT ?= $@
pkg/%/serf:
CGO_ENABLED=0 \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*)) \
go build -trimpath -ldflags "$(GO_LDFLAGS)" -o $(GO_OUT) ./cmd/serf
pkg/windows_%/serf: GO_OUT = $@.exe
clean:
rm -r pkg
rm -r bin
# ----------------------------------------------------------
# testing
.PHONY: test subnet cov testrace check lint copywriteheaders tidy
# test runs the test suite
test: subnet
go test ./...
# subnet sets up the require subnet for testing on darwin (osx) - you must run
# this before running other tests if you are on osx.
subnet:
@sh -c "'$(CURDIR)/scripts/setup_test_subnet.sh'"
# cov runs tests with a coverage profile
cov:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
# testrace runs the race checker
testrace: subnet vet
go test -race ./... $(TESTARGS)
# check runs all the linters and custom checks
check: lint tidy copywriteheaders
# lint covers go vet and go fmt
lint:
golangci-lint run
# make sure our copyright headers are correct
copywriteheaders:
copywrite headers --plan
# make sure go.mod/sum are up to date
tidy:
go mod tidy
@if (git status --porcelain | grep -Eq "go\.(mod|sum)"); then \
echo go.mod or go.sum needs updating; \
git --no-pager diff go.mod; \
git --no-pager diff go.sum; \
exit 1; fi