2020-12-31 03:56:07 +00:00
|
|
|
SHELL := bash
|
2018-12-13 05:36:15 +00:00
|
|
|
GO ?= go
|
2024-05-02 11:52:27 +00:00
|
|
|
GOOS ?= $(shell $(GO) env GOOS)
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2018-07-16 09:55:06 +00:00
|
|
|
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
|
|
|
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
2024-05-20 10:33:46 +00:00
|
|
|
SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)
|
2018-07-16 09:55:06 +00:00
|
|
|
|
2020-10-28 09:33:22 +00:00
|
|
|
ifdef FZF_VERSION
|
|
|
|
VERSION := $(FZF_VERSION)
|
|
|
|
else
|
2024-07-07 07:30:23 +00:00
|
|
|
VERSION := $(shell git describe --abbrev=0 2> /dev/null | sed "s/^v//")
|
2020-10-28 09:33:22 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(VERSION),)
|
|
|
|
$(error Not on git repository; cannot determine $$FZF_VERSION)
|
|
|
|
endif
|
2024-07-07 07:30:23 +00:00
|
|
|
VERSION_TRIM := $(shell sed "s/^v//; s/-.*//" <<< $(VERSION))
|
2020-10-27 04:53:24 +00:00
|
|
|
VERSION_REGEX := $(subst .,\.,$(VERSION_TRIM))
|
2020-10-28 09:33:22 +00:00
|
|
|
|
|
|
|
ifdef FZF_REVISION
|
|
|
|
REVISION := $(FZF_REVISION)
|
|
|
|
else
|
2023-04-02 14:29:15 +00:00
|
|
|
REVISION := $(shell git log -n 1 --pretty=format:%h --abbrev=8 -- $(SOURCES) 2> /dev/null)
|
2020-10-28 09:33:22 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(REVISION),)
|
|
|
|
$(error Not on git repository; cannot determine $$FZF_REVISION)
|
|
|
|
endif
|
2024-04-23 08:24:50 +00:00
|
|
|
BUILD_FLAGS := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" -trimpath
|
2018-07-16 09:55:06 +00:00
|
|
|
|
2021-01-20 09:37:52 +00:00
|
|
|
BINARY32 := fzf-$(GOOS)_386
|
2018-07-16 09:55:06 +00:00
|
|
|
BINARY64 := fzf-$(GOOS)_amd64
|
2023-02-20 12:00:54 +00:00
|
|
|
BINARYS390 := fzf-$(GOOS)_s390x
|
2018-07-16 09:55:06 +00:00
|
|
|
BINARYARM5 := fzf-$(GOOS)_arm5
|
|
|
|
BINARYARM6 := fzf-$(GOOS)_arm6
|
|
|
|
BINARYARM7 := fzf-$(GOOS)_arm7
|
|
|
|
BINARYARM8 := fzf-$(GOOS)_arm8
|
|
|
|
BINARYPPC64LE := fzf-$(GOOS)_ppc64le
|
2021-10-10 12:33:06 +00:00
|
|
|
BINARYRISCV64 := fzf-$(GOOS)_riscv64
|
2022-06-28 00:16:26 +00:00
|
|
|
BINARYLOONG64 := fzf-$(GOOS)_loong64
|
2017-06-02 07:32:15 +00:00
|
|
|
|
|
|
|
# https://en.wikipedia.org/wiki/Uname
|
|
|
|
UNAME_M := $(shell uname -m)
|
|
|
|
ifeq ($(UNAME_M),x86_64)
|
|
|
|
BINARY := $(BINARY64)
|
|
|
|
else ifeq ($(UNAME_M),amd64)
|
|
|
|
BINARY := $(BINARY64)
|
2023-02-20 12:00:54 +00:00
|
|
|
else ifeq ($(UNAME_M),s390x)
|
|
|
|
BINARY := $(BINARYS390)
|
2021-01-20 09:37:52 +00:00
|
|
|
else ifeq ($(UNAME_M),i686)
|
|
|
|
BINARY := $(BINARY32)
|
|
|
|
else ifeq ($(UNAME_M),i386)
|
|
|
|
BINARY := $(BINARY32)
|
2017-06-02 07:32:15 +00:00
|
|
|
else ifeq ($(UNAME_M),armv5l)
|
|
|
|
BINARY := $(BINARYARM5)
|
|
|
|
else ifeq ($(UNAME_M),armv6l)
|
|
|
|
BINARY := $(BINARYARM6)
|
|
|
|
else ifeq ($(UNAME_M),armv7l)
|
|
|
|
BINARY := $(BINARYARM7)
|
2018-06-27 09:56:02 +00:00
|
|
|
else ifeq ($(UNAME_M),armv8l)
|
2023-09-11 10:32:45 +00:00
|
|
|
# armv8l is always 32-bit and should implement the armv7 ISA, so
|
|
|
|
# just use the same filename as for armv7.
|
|
|
|
BINARY := $(BINARYARM7)
|
2020-12-23 05:27:46 +00:00
|
|
|
else ifeq ($(UNAME_M),arm64)
|
|
|
|
BINARY := $(BINARYARM8)
|
2019-10-11 13:11:06 +00:00
|
|
|
else ifeq ($(UNAME_M),aarch64)
|
|
|
|
BINARY := $(BINARYARM8)
|
2018-07-16 09:55:06 +00:00
|
|
|
else ifeq ($(UNAME_M),ppc64le)
|
|
|
|
BINARY := $(BINARYPPC64LE)
|
2021-10-10 12:33:06 +00:00
|
|
|
else ifeq ($(UNAME_M),riscv64)
|
|
|
|
BINARY := $(BINARYRISCV64)
|
2022-06-28 00:16:26 +00:00
|
|
|
else ifeq ($(UNAME_M),loongarch64)
|
|
|
|
BINARY := $(BINARYLOONG64)
|
2017-06-02 07:32:15 +00:00
|
|
|
else
|
2020-10-27 04:53:24 +00:00
|
|
|
$(error Build on $(UNAME_M) is not supported, yet.)
|
2017-06-02 07:32:15 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
all: target/$(BINARY)
|
|
|
|
|
2018-12-13 05:36:15 +00:00
|
|
|
test: $(SOURCES)
|
|
|
|
SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \
|
2017-06-02 07:32:15 +00:00
|
|
|
github.com/junegunn/fzf/src \
|
|
|
|
github.com/junegunn/fzf/src/algo \
|
|
|
|
github.com/junegunn/fzf/src/tui \
|
|
|
|
github.com/junegunn/fzf/src/util
|
|
|
|
|
2021-03-11 10:34:50 +00:00
|
|
|
bench:
|
|
|
|
cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem
|
|
|
|
|
2024-08-17 09:23:42 +00:00
|
|
|
lint: $(SOURCES) test/test_go.rb
|
|
|
|
[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
|
|
|
|
rubocop --require rubocop-minitest --require rubocop-performance
|
|
|
|
|
2017-06-02 07:32:15 +00:00
|
|
|
install: bin/fzf
|
|
|
|
|
2023-12-25 14:43:46 +00:00
|
|
|
generate:
|
|
|
|
PATH=$(PATH):$(GOPATH)/bin $(GO) generate ./...
|
|
|
|
|
2020-10-27 04:53:24 +00:00
|
|
|
build:
|
2024-01-20 05:36:52 +00:00
|
|
|
goreleaser build --clean --snapshot --skip=post-hooks
|
2020-10-26 16:46:43 +00:00
|
|
|
|
2020-10-27 04:53:24 +00:00
|
|
|
release:
|
2023-11-12 13:08:08 +00:00
|
|
|
# Make sure that the tests pass and the build works
|
|
|
|
TAGS=tcell make test
|
|
|
|
make test build clean
|
|
|
|
|
2020-10-27 04:53:24 +00:00
|
|
|
ifndef GITHUB_TOKEN
|
|
|
|
$(error GITHUB_TOKEN is not defined)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Check if we are on master branch
|
|
|
|
ifneq ($(shell git symbolic-ref --short HEAD),master)
|
|
|
|
$(error Not on master branch)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Check if version numbers are properly updated
|
|
|
|
grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md
|
|
|
|
grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1
|
|
|
|
grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1
|
|
|
|
grep -qF $(VERSION) install
|
|
|
|
grep -qF $(VERSION) install.ps1
|
|
|
|
|
|
|
|
# Make release note out of CHANGELOG.md
|
2021-11-03 15:59:04 +00:00
|
|
|
mkdir -p tmp
|
2020-10-27 04:53:24 +00:00
|
|
|
sed -n '/^$(VERSION_REGEX)$$/,/^[0-9]/p' CHANGELOG.md | tail -r | \
|
|
|
|
sed '1,/^ *$$/d' | tail -r | sed 1,2d | tee tmp/release-note
|
|
|
|
|
|
|
|
# Push to temp branch first so that install scripts always works on master branch
|
|
|
|
git checkout -B temp master
|
|
|
|
git push origin temp --follow-tags --force
|
|
|
|
|
|
|
|
# Make a GitHub release
|
2024-01-20 05:36:52 +00:00
|
|
|
goreleaser --clean --release-notes tmp/release-note
|
2020-10-27 04:53:24 +00:00
|
|
|
|
|
|
|
# Push to master
|
|
|
|
git checkout master
|
|
|
|
git push origin master
|
|
|
|
|
|
|
|
# Delete temp branch
|
|
|
|
git push origin --delete temp
|
|
|
|
|
2017-06-02 07:32:15 +00:00
|
|
|
clean:
|
2020-10-26 16:46:43 +00:00
|
|
|
$(RM) -r dist target
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2021-01-20 09:37:52 +00:00
|
|
|
target/$(BINARY32): $(SOURCES)
|
|
|
|
GOARCH=386 $(GO) build $(BUILD_FLAGS) -o $@
|
|
|
|
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARY64): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2023-02-20 12:00:54 +00:00
|
|
|
target/$(BINARYS390): $(SOURCES)
|
|
|
|
GOARCH=s390x $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
# https://github.com/golang/go/wiki/GoArm
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARYARM5): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=arm GOARM=5 $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARYARM6): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=arm GOARM=6 $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARYARM7): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=arm GOARM=7 $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARYARM8): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o $@
|
2017-06-02 07:32:15 +00:00
|
|
|
|
2018-12-13 06:17:30 +00:00
|
|
|
target/$(BINARYPPC64LE): $(SOURCES)
|
2018-12-13 05:36:15 +00:00
|
|
|
GOARCH=ppc64le $(GO) build $(BUILD_FLAGS) -o $@
|
2018-07-16 09:55:06 +00:00
|
|
|
|
2021-10-10 12:33:06 +00:00
|
|
|
target/$(BINARYRISCV64): $(SOURCES)
|
|
|
|
GOARCH=riscv64 $(GO) build $(BUILD_FLAGS) -o $@
|
|
|
|
|
2022-06-28 00:16:26 +00:00
|
|
|
target/$(BINARYLOONG64): $(SOURCES)
|
|
|
|
GOARCH=loong64 $(GO) build $(BUILD_FLAGS) -o $@
|
|
|
|
|
2017-06-02 07:32:15 +00:00
|
|
|
bin/fzf: target/$(BINARY) | bin
|
2022-09-07 16:01:22 +00:00
|
|
|
-rm -f bin/fzf
|
2017-06-02 07:32:15 +00:00
|
|
|
cp -f target/$(BINARY) bin/fzf
|
|
|
|
|
2018-06-01 09:23:25 +00:00
|
|
|
docker:
|
2024-04-24 09:20:02 +00:00
|
|
|
docker build -t fzf-ubuntu .
|
|
|
|
docker run -it fzf-ubuntu tmux
|
2018-06-01 09:23:25 +00:00
|
|
|
|
|
|
|
docker-test:
|
2024-04-24 09:20:02 +00:00
|
|
|
docker build -t fzf-ubuntu .
|
|
|
|
docker run -it fzf-ubuntu
|
2018-06-01 09:23:25 +00:00
|
|
|
|
2018-12-13 05:36:15 +00:00
|
|
|
update:
|
|
|
|
$(GO) get -u
|
|
|
|
$(GO) mod tidy
|
|
|
|
|
2024-08-17 09:23:42 +00:00
|
|
|
.PHONY: all generate build release test bench lint install clean docker docker-test update
|