aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/Makefile
blob: bc4a60f61db78dead6eb7518f96f4bea9d98ae19 (plain) (blame)
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
119
120
121
122
123
124
125
# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# The version to release. Defaults to the current tag or revision.
# Use env VERSION=X.Y.Z make ... to override
VERSION ?= $(shell git describe --tags --exact-match 2> /dev/null | sed "s/^v//")
DEVEL_VERSION := $(shell echo "0.0.0-`git rev-parse --short HEAD`")
ifeq ($(VERSION),)
	VERSION = $(DEVEL_VERSION)
endif

BIN ?= $(CURDIR)/bin
SHARE ?= $(CURDIR)/share
DIST ?= $(CURDIR)/dist

GO_FLAGS := -ldflags "-X github.com/vespa-engine/vespa/client/go/build.Version=$(VERSION)"
GIT_ROOT := $(shell git rev-parse --show-toplevel)
DIST_TARGETS := dist-mac dist-mac-arm64 dist-linux dist-linux-arm64 dist-win32 dist-win64

GOPROXY_OVERRIDE :=
ifndef GOPROXY
ifeq ($(shell go env GOPROXY),direct)
GOPROXY_OVERRIDE := GOPROXY=https://proxy.golang.org,direct
endif
endif

all: test checkfmt install

#
# Dist targets
#

# Bump the version of the vespa-cli formula and create a pull request to Homebrew repository.
#
# Example:
#
# $ git checkout vX.Y.Z
# $ make dist-homebrew
dist-homebrew: dist-version
	brew bump-formula-pr --version $(VERSION) vespa-cli

# Create a GitHub release draft for all platforms. Note that this only creates a
# draft, which is not publicly visible until it's explicitly published.
#
# Once the release has been created this prints an URL to the release draft.
#
# This requires the GitHub CLI to be installed: brew install gh
#
# Example:
#
# $ git checkout vX.Y.Z
# $ make dist-github
dist-github: dist
	gh release create v$(VERSION) --repo vespa-engine/vespa --notes-file $(CURDIR)/README.md --draft --title "Vespa CLI $(VERSION)" \
		$(DIST)/vespa-cli_$(VERSION)_sha256sums.txt \
		$(DIST)/vespa-cli_$(VERSION)_*.{zip,tar.gz}

#
# Cross-platform build targets
#

dist: $(DIST_TARGETS) dist-sha256sums

dist-mac: GOOS=darwin
dist-mac: GOARCH=amd64

dist-mac-arm64: GOOS=darwin
dist-mac-arm64: GOARCH=arm64

dist-linux: GOOS=linux
dist-linux: GOARCH=amd64

dist-linux-arm64: GOOS=linux
dist-linux-arm64: GOARCH=arm64

dist-win32: GOOS=windows
dist-win32: GOARCH=386

dist-win64: GOOS=windows
dist-win64: GOARCH=amd64

$(DIST_TARGETS): DIST_NAME=vespa-cli_$(VERSION)_$(GOOS)_$(GOARCH)
$(DIST_TARGETS): dist-version manpages
$(DIST_TARGETS):
	mkdir -p $(DIST)/$(DIST_NAME)/bin
	env GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOPROXY_OVERRIDE) go build -o $(DIST)/$(DIST_NAME)/bin $(GO_FLAGS) ./...
	cp -a $(GIT_ROOT)/LICENSE $(DIST)/$(DIST_NAME)
	if [ "$(GOOS)" = "windows" ]; then \
		cd $(DIST) && zip -r $(DIST)/$(DIST_NAME).zip $(DIST_NAME); \
	else \
		cp -a share $(DIST)/$(DIST_NAME); \
		tar -czvf $(DIST)/$(DIST_NAME).tar.gz -C $(DIST) $(DIST_NAME); \
	fi

dist-sha256sums:
	cd $(DIST) && sha256sum vespa-cli_$(VERSION)_*.{zip,tar.gz} > vespa-cli_$(VERSION)_sha256sums.txt

dist-version:
ifeq ($(VERSION),$(DEVEL_VERSION))
	$(error Invalid release version: $(VERSION). Try 'git checkout vX.Y.Z' or 'env VERSION=X.Y.Z make ...')
endif

install-all: all manpages

#
# Development targets
#

install:
	env GOBIN=$(BIN) $(GOPROXY_OVERRIDE) go install $(GO_FLAGS) ./...

manpages: install
	mkdir -p $(SHARE)/man/man1
	$(BIN)/vespa man $(SHARE)/man/man1

clean:
	rm -rf $(BIN) $(SHARE) $(DIST)

test:
	env $(GOPROXY_OVERRIDE) go test ./...

checkfmt:
	@bash -c "diff --line-format='%L' <(echo -n) <(gofmt -l .)" || { echo "one or more files need to be formatted: try make fmt to fix this automatically"; exit 1; }

fmt:
	gofmt -w .