Skip to content
Myr

Makefile

This file

Path

Makefile

144 lines · 3.8 KiB

Last changed by

Make build flags consistentJunegunn Choibefore adoptiona7d3b72

History of this file

Take it

1GO             ?= go2GOOS           ?= $(word 1, $(subst /, " ", $(word 4, $(shell go version))))34MAKEFILE       := $(realpath $(lastword $(MAKEFILE_LIST)))5ROOT_DIR       := $(shell dirname $(MAKEFILE))6SOURCES        := $(wildcard *.go src/*.go src/*/*.go) $(MAKEFILE)78ifdef FZF_VERSION9VERSION        := $(FZF_VERSION)10else11VERSION        := $(shell git describe --abbrev=0 2> /dev/null)12endif13ifeq ($(VERSION),)14$(error Not on git repository; cannot determine $$FZF_VERSION)15endif16VERSION_TRIM   := $(shell sed "s/-.*//" <<< $(VERSION))17VERSION_REGEX  := $(subst .,\.,$(VERSION_TRIM))1819ifdef FZF_REVISION20REVISION       := $(FZF_REVISION)21else22REVISION       := $(shell git log -n 1 --pretty=format:%h -- $(SOURCES) 2> /dev/null)23endif24ifeq ($(REVISION),)25$(error Not on git repository; cannot determine $$FZF_REVISION)26endif27BUILD_FLAGS    := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)"2829BINARY64       := fzf-$(GOOS)_amd6430BINARYARM5     := fzf-$(GOOS)_arm531BINARYARM6     := fzf-$(GOOS)_arm632BINARYARM7     := fzf-$(GOOS)_arm733BINARYARM8     := fzf-$(GOOS)_arm834BINARYPPC64LE  := fzf-$(GOOS)_ppc64le3536# https://en.wikipedia.org/wiki/Uname37UNAME_M := $(shell uname -m)38ifeq ($(UNAME_M),x86_64)39	BINARY := $(BINARY64)40else ifeq ($(UNAME_M),amd64)41	BINARY := $(BINARY64)42else ifeq ($(UNAME_M),armv5l)43	BINARY := $(BINARYARM5)44else ifeq ($(UNAME_M),armv6l)45	BINARY := $(BINARYARM6)46else ifeq ($(UNAME_M),armv7l)47	BINARY := $(BINARYARM7)48else ifeq ($(UNAME_M),armv8l)49	BINARY := $(BINARYARM8)50else ifeq ($(UNAME_M),aarch64)51	BINARY := $(BINARYARM8)52else ifeq ($(UNAME_M),ppc64le)53	BINARY := $(BINARYPPC64LE)54else55$(error Build on $(UNAME_M) is not supported, yet.)56endif5758all: target/$(BINARY)5960test: $(SOURCES)61	SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \62				github.com/junegunn/fzf/src \63				github.com/junegunn/fzf/src/algo \64				github.com/junegunn/fzf/src/tui \65				github.com/junegunn/fzf/src/util6667install: bin/fzf6869build:70	goreleaser --rm-dist --snapshot7172release:73ifndef GITHUB_TOKEN74	$(error GITHUB_TOKEN is not defined)75endif7677	# Check if we are on master branch78ifneq ($(shell git symbolic-ref --short HEAD),master)79	$(error Not on master branch)80endif8182	# Check if version numbers are properly updated83	grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md84	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.185	grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.186	grep -qF $(VERSION) install87	grep -qF $(VERSION) install.ps18889	# Make release note out of CHANGELOG.md90	sed -n '/^$(VERSION_REGEX)$$/,/^[0-9]/p' CHANGELOG.md | tail -r | \91		sed '1,/^ *$$/d' | tail -r | sed 1,2d | tee tmp/release-note9293	# Push to temp branch first so that install scripts always works on master branch94	git checkout -B temp master95	git push origin temp --follow-tags --force9697	# Make a GitHub release98	goreleaser --rm-dist --release-notes tmp/release-note99100	# Push to master101	git checkout master102	git push origin master103104	# Delete temp branch105	git push origin --delete temp106107clean:108	$(RM) -r dist target109110target/$(BINARY64): $(SOURCES)111	GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o $@112113# https://github.com/golang/go/wiki/GoArm114target/$(BINARYARM5): $(SOURCES)115	GOARCH=arm GOARM=5 $(GO) build $(BUILD_FLAGS) -o $@116117target/$(BINARYARM6): $(SOURCES)118	GOARCH=arm GOARM=6 $(GO) build $(BUILD_FLAGS) -o $@119120target/$(BINARYARM7): $(SOURCES)121	GOARCH=arm GOARM=7 $(GO) build $(BUILD_FLAGS) -o $@122123target/$(BINARYARM8): $(SOURCES)124	GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o $@125126target/$(BINARYPPC64LE): $(SOURCES)127	GOARCH=ppc64le $(GO) build $(BUILD_FLAGS) -o $@128129bin/fzf: target/$(BINARY) | bin130	cp -f target/$(BINARY) bin/fzf131132docker:133	docker build -t fzf-arch .134	docker run -it fzf-arch tmux135136docker-test:137	docker build -t fzf-arch .138	docker run -it fzf-arch139140update:141	$(GO) get -u142	$(GO) mod tidy143144.PHONY: all build release test install clean docker docker-test update