From ee99baede064db3cda18aa01a7e55920f6cf7357 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 10 Mar 2021 00:39:52 +0100 Subject: [PATCH] chore: add make targets for convenience --- Makefile | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c848f7 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ +-include Makefile.local + +DESTDIR ?= +PREFIX ?= /usr/local +BINDIR ?= ${PREFIX}/bin +DATAROOTDIR ?= ${PREFIX}/share +MANDIR ?= ${DATAROOTDIR}/man + +TARBALLDIR ?= target/release/tarball +TARBALLFORMAT=tar.gz + +RM := rm +CARGO := cargo +SCDOC := scdoc +INSTALL := install +GIT := git +GPG := gpg +SED := sed + +DEBUG := 0 +ifeq ($(DEBUG), 0) + CARGO_OPTIONS := --release --locked + CARGO_TARGET := release +else + CARGO_OPTIONS := + CARGO_TARGET := debug +endif + +.PHONY: all git-smash test docs completions clean install uninstall + +all: git-smash test docs + +git-smash: + $(CARGO) build $(CARGO_OPTIONS) + +test: + $(CARGO) test $(CARGO_OPTIONS) + +lint: + $(CARGO) fmt -- --check + $(CARGO) check + find . -name '*.rs' -exec touch {} + + $(CARGO) clippy --all -- -D warnings + +docs: completions + +completions: git-smash + target/$(CARGO_TARGET)/git-smash completions bash | $(INSTALL) -Dm 644 /dev/stdin target/completion/bash/git-smash + target/$(CARGO_TARGET)/git-smash completions zsh | $(INSTALL) -Dm 644 /dev/stdin target/completion/zsh/_git-smash + target/$(CARGO_TARGET)/git-smash completions fish | $(INSTALL) -Dm 644 /dev/stdin target/completion/fish/git-smash.fish + +clean: + $(RM) -rf target contrib/man/*.1 + +install: git-smash docs + $(INSTALL) -Dm 755 target/$(CARGO_TARGET)/git-smash -t $(DESTDIR)$(BINDIR) + $(INSTALL) -Dm 644 target/completion/bash/git-smash -t $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions + $(INSTALL) -Dm 644 target/completion/zsh/_git-smash -t $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions + $(INSTALL) -Dm 644 target/completion/fish/git-smash.fish -t $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d + +uninstall: + $(RM) -f $(DESTDIR)$(BINDIR)/git-smash + $(RM) -f $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions/git-smash + $(RM) -f $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions/_git-smash + $(RM) -f $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d/git-smash.fish + +release: all + $(INSTALL) -d $(TARBALLDIR) + @read -p 'version> ' TAG && \ + $(SED) "s|version = .*|version = \"$$TAG\"|" -i Cargo.toml && \ + $(CARGO) build --release && \ + $(GIT) commit --gpg-sign --message "version: release $$TAG" Cargo.toml Cargo.lock && \ + $(GIT) tag --sign --message "version: release $$TAG" $$TAG && \ + $(GIT) archive -o $(TARBALLDIR)/git-smash-$$TAG.$(TARBALLFORMAT) --format $(TARBALLFORMAT) --prefix=git-smash-$$TAG/ $$TAG && \ + $(GPG) --detach-sign $(TARBALLDIR)/git-smash-$$TAG.$(TARBALLFORMAT)