Debian Codegraph @

Makefile

raw
1 GO ?= go
2 DOCKER ?= docker
3 GOOS ?= $(shell $(GO) env GOOS)
4
5 MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
6 ROOT_DIR := $(shell dirname $(MAKEFILE))
7 SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)
8
9 BASH_SCRIPTS := $(ROOT_DIR)/bin/fzf-preview.sh \
10 $(ROOT_DIR)/bin/fzf-tmux \
11 $(ROOT_DIR)/install \
12 $(ROOT_DIR)/uninstall \
13 $(ROOT_DIR)/shell/common.sh \
14 $(ROOT_DIR)/shell/update.sh \
15 $(ROOT_DIR)/shell/completion.bash \
16 $(ROOT_DIR)/shell/key-bindings.bash
17
18 ifdef FZF_VERSION
19 VERSION := $(FZF_VERSION)
20 else
21 VERSION := $(shell git describe --abbrev=0 2> /dev/null | sed "s/^v//")
22 endif
23 ifeq ($(VERSION),)
24 $(error Not on git repository; cannot determine $$FZF_VERSION)
25 endif
26 VERSION_TRIM := $(shell echo $(VERSION) | sed "s/^v//; s/-.*//")
27 VERSION_REGEX := $(subst .,\.,$(VERSION_TRIM))
28
29 ifdef FZF_REVISION
30 REVISION := $(FZF_REVISION)
31 else
32 REVISION := $(shell git log -n 1 --pretty=format:%h --abbrev=8 -- $(SOURCES) 2> /dev/null)
33 endif
34 ifeq ($(REVISION),)
35 $(error Not on git repository; cannot determine $$FZF_REVISION)
36 endif
37 BUILD_FLAGS := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" -trimpath
38
39 BINARY32 := fzf-$(GOOS)_386
40 BINARY64 := fzf-$(GOOS)_amd64
41 BINARYS390 := fzf-$(GOOS)_s390x
42 BINARYARM5 := fzf-$(GOOS)_arm5
43 BINARYARM6 := fzf-$(GOOS)_arm6
44 BINARYARM7 := fzf-$(GOOS)_arm7
45 BINARYARM8 := fzf-$(GOOS)_arm8
46 BINARYPPC64LE := fzf-$(GOOS)_ppc64le
47 BINARYRISCV64 := fzf-$(GOOS)_riscv64
48 BINARYLOONG64 := fzf-$(GOOS)_loong64
49
50 # https://en.wikipedia.org/wiki/Uname
51 UNAME_M := $(shell uname -m)
52 ifeq ($(UNAME_M),x86_64)
53 BINARY := $(BINARY64)
54 else ifeq ($(UNAME_M),amd64)
55 BINARY := $(BINARY64)
56 else ifeq ($(UNAME_M),i86pc)
57 BINARY := $(BINARY64)
58 else ifeq ($(UNAME_M),s390x)
59 BINARY := $(BINARYS390)
60 else ifeq ($(UNAME_M),i686)
61 BINARY := $(BINARY32)
62 else ifeq ($(UNAME_M),i386)
63 BINARY := $(BINARY32)
64 else ifeq ($(UNAME_M),armv5l)
65 BINARY := $(BINARYARM5)
66 else ifeq ($(UNAME_M),armv6l)
67 BINARY := $(BINARYARM6)
68 else ifeq ($(UNAME_M),armv7l)
69 BINARY := $(BINARYARM7)
70 else ifeq ($(UNAME_M),armv8l)
71 # armv8l is always 32-bit and should implement the armv7 ISA, so
72 # just use the same filename as for armv7.
73 BINARY := $(BINARYARM7)
74 else ifeq ($(UNAME_M),arm64)
75 BINARY := $(BINARYARM8)
76 else ifeq ($(UNAME_M),aarch64)
77 BINARY := $(BINARYARM8)
78 else ifeq ($(UNAME_M),ppc64le)
79 BINARY := $(BINARYPPC64LE)
80 else ifeq ($(UNAME_M),riscv64)
81 BINARY := $(BINARYRISCV64)
82 else ifeq ($(UNAME_M),loongarch64)
83 BINARY := $(BINARYLOONG64)
84 else
85 $(error Build on $(UNAME_M) is not supported, yet.)
86 endif
87
88 all: target/$(BINARY)
89
90 test: $(SOURCES)
91 SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \
92 github.com/junegunn/fzf/src \
93 github.com/junegunn/fzf/src/algo \
94 github.com/junegunn/fzf/src/tui \
95 github.com/junegunn/fzf/src/util
96
97 itest:
98 ruby test/runner.rb
99
100 # Actively fuzz the matcher fast paths against the general algorithm.
101 # Go fuzzes one target at a time, so iterate. Override duration with
102 # FUZZTIME (e.g. make fuzz FUZZTIME=5m).
103 FUZZTIME ?= 30s
104 fuzz:
105 @for t in FuzzFuzzyMatchV2Single FuzzFuzzyMatchV2Two FuzzRunePrefilter; do \
106 echo "== $$t =="; \
107 $(GO) test -run '^$$' -fuzz "^$$t$$" -fuzztime $(FUZZTIME) ./src/algo || exit 1; \
108 done
109
110 bench:
111 cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem
112
113 lint: $(SOURCES) test/*.rb test/lib/*.rb ${BASH_SCRIPTS}
114 [ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
115 bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance
116 shell/update.sh --check ${BASH_SCRIPTS}
117
118 fmt: $(SOURCES) $(BASH_SCRIPTS)
119 gofmt -s -w src
120 shell/update.sh ${BASH_SCRIPTS}
121
122 install: bin/fzf
123
124 generate:
125 PATH=$(PATH):$(GOPATH)/bin $(GO) generate ./...
126
127 build:
128 goreleaser build --clean --snapshot --skip=post-hooks
129
130 prerelease:
131 # Check if version numbers are properly updated
132 grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md
133 grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1
134 grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1
135 grep -qF $(VERSION) install
136 grep -qF $(VERSION) install.ps1
137 @echo "OK: all files consistent at $(VERSION)"
138
139 tag: prerelease
140 git tag -s v$(VERSION) -m v$(VERSION)
141 git push origin v$(VERSION)
142
143 release:
144 # Make sure that the tests pass and the build works
145 TAGS=tcell make test
146 make test build clean
147
148 ifndef GITHUB_TOKEN
149 $(error GITHUB_TOKEN is not defined)
150 endif
151
152 # Check if we are on master branch
153 ifneq ($(shell git symbolic-ref --short HEAD),master)
154 $(error Not on master branch)
155 endif
156
157 # Check if version numbers are properly updated
158 grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md
159 grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1
160 grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1
161 grep -qF $(VERSION) install
162 grep -qF $(VERSION) install.ps1
163
164 # Make release note out of CHANGELOG.md
165 mkdir -p tmp
166 sed -n '/^$(VERSION_REGEX)$$/,/^[0-9]/p' CHANGELOG.md | tail -r | \
167 sed '1,/^ *$$/d' | tail -r | sed 1,2d | tee tmp/release-note
168
169 # Push to temp branch first so that install scripts always works on master branch
170 git checkout -B temp master
171 git push origin temp --follow-tags --force
172
173 # Make a GitHub release
174 goreleaser --clean --release-notes tmp/release-note
175
176 # Push to master
177 git checkout master
178 git push origin master
179
180 # Delete temp branch
181 git push origin --delete temp
182
183 clean:
184 $(RM) -r dist target
185
186 target/$(BINARY32): $(SOURCES)
187 GOARCH=386 $(GO) build $(BUILD_FLAGS) -o $@
188
189 target/$(BINARY64): $(SOURCES)
190 GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o $@
191
192 target/$(BINARYS390): $(SOURCES)
193 GOARCH=s390x $(GO) build $(BUILD_FLAGS) -o $@
194 # https://github.com/golang/go/wiki/GoArm
195 target/$(BINARYARM5): $(SOURCES)
196 GOARCH=arm GOARM=5 $(GO) build $(BUILD_FLAGS) -o $@
197
198 target/$(BINARYARM6): $(SOURCES)
199 GOARCH=arm GOARM=6 $(GO) build $(BUILD_FLAGS) -o $@
200
201 target/$(BINARYARM7): $(SOURCES)
202 GOARCH=arm GOARM=7 $(GO) build $(BUILD_FLAGS) -o $@
203
204 target/$(BINARYARM8): $(SOURCES)
205 GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o $@
206
207 target/$(BINARYPPC64LE): $(SOURCES)
208 GOARCH=ppc64le $(GO) build $(BUILD_FLAGS) -o $@
209
210 target/$(BINARYRISCV64): $(SOURCES)
211 GOARCH=riscv64 $(GO) build $(BUILD_FLAGS) -o $@
212
213 target/$(BINARYLOONG64): $(SOURCES)
214 GOARCH=loong64 $(GO) build $(BUILD_FLAGS) -o $@
215
216 bin/fzf: target/$(BINARY) | bin
217 -rm -f bin/fzf
218 cp -f target/$(BINARY) bin/fzf
219
220 docker:
221 $(DOCKER) build -t fzf-ubuntu .
222 $(DOCKER) run -it fzf-ubuntu tmux
223
224 docker-test:
225 $(DOCKER) build -t fzf-ubuntu .
226 $(DOCKER) run -it fzf-ubuntu
227
228 update:
229 $(GO) get -u
230 $(GO) mod tidy
231
232 .PHONY: all generate build prerelease tag release test itest bench lint install clean docker docker-test update fmt