Skip to content
Myr

Makefile

This file

Path

Makefile

236 lines · 6.8 KiB

Last changed by

Run itest in a separate tmux serverJunegunn Choibefore adoption981f153

History of this file

Take it

1GO             ?= go2DOCKER         ?= docker3GOOS           ?= $(shell $(GO) env GOOS)45MAKEFILE       := $(realpath $(lastword $(MAKEFILE_LIST)))6ROOT_DIR       := $(shell dirname $(MAKEFILE))7SOURCES        := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)89BASH_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.bash1718ifdef FZF_VERSION19VERSION        := $(FZF_VERSION)20else21VERSION        := $(shell git describe --abbrev=0 2> /dev/null | sed "s/^v//")22endif23ifeq ($(VERSION),)24$(error Not on git repository; cannot determine $$FZF_VERSION)25endif26VERSION_TRIM   := $(shell echo $(VERSION) | sed "s/^v//; s/-.*//")27VERSION_REGEX  := $(subst .,\.,$(VERSION_TRIM))2829ifdef FZF_REVISION30REVISION       := $(FZF_REVISION)31else32REVISION       := $(shell git log -n 1 --pretty=format:%h --abbrev=8 -- $(SOURCES) 2> /dev/null)33endif34ifeq ($(REVISION),)35$(error Not on git repository; cannot determine $$FZF_REVISION)36endif37BUILD_FLAGS    := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" -trimpath3839BINARY32       := fzf-$(GOOS)_38640BINARY64       := fzf-$(GOOS)_amd6441BINARYS390     := fzf-$(GOOS)_s390x42BINARYARM5     := fzf-$(GOOS)_arm543BINARYARM6     := fzf-$(GOOS)_arm644BINARYARM7     := fzf-$(GOOS)_arm745BINARYARM8     := fzf-$(GOOS)_arm846BINARYPPC64LE  := fzf-$(GOOS)_ppc64le47BINARYRISCV64  := fzf-$(GOOS)_riscv6448BINARYLOONG64  := fzf-$(GOOS)_loong644950# https://en.wikipedia.org/wiki/Uname51UNAME_M := $(shell uname -m)52ifeq ($(UNAME_M),x86_64)53	BINARY := $(BINARY64)54else ifeq ($(UNAME_M),amd64)55	BINARY := $(BINARY64)56else ifeq ($(UNAME_M),i86pc)57	BINARY := $(BINARY64)58else ifeq ($(UNAME_M),s390x)59	BINARY := $(BINARYS390)60else ifeq ($(UNAME_M),i686)61	BINARY := $(BINARY32)62else ifeq ($(UNAME_M),i386)63	BINARY := $(BINARY32)64else ifeq ($(UNAME_M),armv5l)65	BINARY := $(BINARYARM5)66else ifeq ($(UNAME_M),armv6l)67	BINARY := $(BINARYARM6)68else ifeq ($(UNAME_M),armv7l)69	BINARY := $(BINARYARM7)70else ifeq ($(UNAME_M),armv8l)71	# armv8l is always 32-bit and should implement the armv7 ISA, so72	# just use the same filename as for armv7.73	BINARY := $(BINARYARM7)74else ifeq ($(UNAME_M),arm64)75	BINARY := $(BINARYARM8)76else ifeq ($(UNAME_M),aarch64)77	BINARY := $(BINARYARM8)78else ifeq ($(UNAME_M),ppc64le)79	BINARY := $(BINARYPPC64LE)80else ifeq ($(UNAME_M),riscv64)81	BINARY := $(BINARYRISCV64)82else ifeq ($(UNAME_M),loongarch64)83	BINARY := $(BINARYLOONG64)84else85$(error Build on $(UNAME_M) is not supported, yet.)86endif8788all: target/$(BINARY)8990test: $(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/util9697# Run in a separate tmux server without user config, like CI (80x24)98itest:99	@dir=$$(mktemp -d) && \100	env -u TMUX TMUX_TMPDIR=$$dir sh -c \101		'tmux -f /dev/null new-session -d && ruby test/runner.rb; s=$$?; tmux kill-server; exit $$s'; \102	s=$$?; rm -rf $$dir; exit $$s103104# Actively fuzz the matcher fast paths against the general algorithm.105# Go fuzzes one target at a time, so iterate. Override duration with106# FUZZTIME (e.g. make fuzz FUZZTIME=5m).107FUZZTIME ?= 30s108fuzz:109	@for t in FuzzFuzzyMatchV2Single FuzzFuzzyMatchV2Two FuzzRunePrefilter; do \110		echo "== $$t =="; \111		$(GO) test -run '^$$' -fuzz "^$$t$$" -fuzztime $(FUZZTIME) ./src/algo || exit 1; \112	done113114bench:115	cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem116117lint: $(SOURCES) test/*.rb test/lib/*.rb ${BASH_SCRIPTS}118	[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)119	bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance120	shell/update.sh --check ${BASH_SCRIPTS}121122fmt: $(SOURCES) $(BASH_SCRIPTS)123	gofmt -s -w src124	shell/update.sh ${BASH_SCRIPTS}125126install: bin/fzf127128generate:129	PATH=$(PATH):$(GOPATH)/bin $(GO) generate ./...130131build:132	goreleaser build --clean --snapshot --skip=post-hooks133134prerelease:135	# Check if version numbers are properly updated136	grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md137	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1138	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1139	grep -qF $(VERSION) install140	grep -qF $(VERSION) install.ps1141	@echo "OK: all files consistent at $(VERSION)"142143tag: prerelease144	git tag -s v$(VERSION) -m v$(VERSION)145	git push origin v$(VERSION)146147release:148	# Make sure that the tests pass and the build works149	TAGS=tcell make test150	make test build clean151152ifndef GITHUB_TOKEN153	$(error GITHUB_TOKEN is not defined)154endif155156	# Check if we are on master branch157ifneq ($(shell git symbolic-ref --short HEAD),master)158	$(error Not on master branch)159endif160161	# Check if version numbers are properly updated162	grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md163	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1164	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1165	grep -qF $(VERSION) install166	grep -qF $(VERSION) install.ps1167168	# Make release note out of CHANGELOG.md169	mkdir -p tmp170	sed -n '/^$(VERSION_REGEX)$$/,/^[0-9]/p' CHANGELOG.md | tail -r | \171		sed '1,/^ *$$/d' | tail -r | sed 1,2d | tee tmp/release-note172173	# Push to temp branch first so that install scripts always works on master branch174	git checkout -B temp master175	git push origin temp --follow-tags --force176177	# Make a GitHub release178	goreleaser --clean --release-notes tmp/release-note179180	# Push to master181	git checkout master182	git push origin master183184	# Delete temp branch185	git push origin --delete temp186187clean:188	$(RM) -r dist target189190target/$(BINARY32): $(SOURCES)191	GOARCH=386 $(GO) build $(BUILD_FLAGS) -o $@192193target/$(BINARY64): $(SOURCES)194	GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o $@195196target/$(BINARYS390): $(SOURCES)197	GOARCH=s390x $(GO) build $(BUILD_FLAGS) -o $@198# https://github.com/golang/go/wiki/GoArm199target/$(BINARYARM5): $(SOURCES)200	GOARCH=arm GOARM=5 $(GO) build $(BUILD_FLAGS) -o $@201202target/$(BINARYARM6): $(SOURCES)203	GOARCH=arm GOARM=6 $(GO) build $(BUILD_FLAGS) -o $@204205target/$(BINARYARM7): $(SOURCES)206	GOARCH=arm GOARM=7 $(GO) build $(BUILD_FLAGS) -o $@207208target/$(BINARYARM8): $(SOURCES)209	GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o $@210211target/$(BINARYPPC64LE): $(SOURCES)212	GOARCH=ppc64le $(GO) build $(BUILD_FLAGS) -o $@213214target/$(BINARYRISCV64): $(SOURCES)215	GOARCH=riscv64 $(GO) build $(BUILD_FLAGS) -o $@216217target/$(BINARYLOONG64): $(SOURCES)218	GOARCH=loong64 $(GO) build $(BUILD_FLAGS) -o $@219220bin/fzf: target/$(BINARY) | bin221	-rm -f bin/fzf222	cp -f target/$(BINARY) bin/fzf223224docker:225	$(DOCKER) build -t fzf-ubuntu .226	$(DOCKER) run -it fzf-ubuntu tmux227228docker-test:229	$(DOCKER) build -t fzf-ubuntu .230	$(DOCKER) run -it fzf-ubuntu231232update:233	$(GO) get -u234	$(GO) mod tidy235236.PHONY: all generate build prerelease tag release test itest bench lint install clean docker docker-test update fmt