| 1 | -include Makefile.local |
| 2 | |
| 3 | DESTDIR ?= |
| 4 | PREFIX ?= /usr/local |
| 5 | BINDIR ?= ${PREFIX}/bin |
| 6 | DATAROOTDIR ?= ${PREFIX}/share |
| 7 | MANDIR ?= ${DATAROOTDIR}/man |
| 8 | |
| 9 | TARBALLDIR ?= target/release/tarball |
| 10 | TARBALLFORMAT=tar.gz |
| 11 | |
| 12 | RM := rm |
| 13 | CARGO := cargo |
| 14 | SCDOC := scdoc |
| 15 | INSTALL := install |
| 16 | GIT := git |
| 17 | GPG := gpg |
| 18 | SED := sed |
| 19 | |
| 20 | DEBUG := 0 |
| 21 | ifeq ($(DEBUG), 0) |
| 22 | CARGO_OPTIONS := --release --locked |
| 23 | CARGO_TARGET := release |
| 24 | else |
| 25 | CARGO_OPTIONS := |
| 26 | CARGO_TARGET := debug |
| 27 | endif |
| 28 | |
| 29 | .PHONY: all dfrs test docs man completions clean install uninstall |
| 30 | |
| 31 | all: dfrs test docs |
| 32 | |
| 33 | dfrs: |
| 34 | $(CARGO) build $(CARGO_OPTIONS) |
| 35 | |
| 36 | test: |
| 37 | $(CARGO) test $(CARGO_OPTIONS) |
| 38 | |
| 39 | lint: |
| 40 | $(CARGO) fmt -- --check |
| 41 | $(CARGO) check |
| 42 | find . -name '*.rs' -exec touch {} + |
| 43 | $(CARGO) clippy --all -- -D warnings |
| 44 | |
| 45 | docs: man completions |
| 46 | |
| 47 | man: contrib/man/dfrs.1 |
| 48 | |
| 49 | contrib/man/%: contrib/man/%.scd |
| 50 | $(SCDOC) < $^ > $@ |
| 51 | |
| 52 | completions: dfrs |
| 53 | target/$(CARGO_TARGET)/dfrs completions bash | $(INSTALL) -Dm 644 /dev/stdin target/completion/bash/dfrs |
| 54 | target/$(CARGO_TARGET)/dfrs completions zsh | $(INSTALL) -Dm 644 /dev/stdin target/completion/zsh/_dfrs |
| 55 | target/$(CARGO_TARGET)/dfrs completions fish | $(INSTALL) -Dm 644 /dev/stdin target/completion/fish/dfrs.fish |
| 56 | |
| 57 | clean: |
| 58 | $(RM) -rf target contrib/man/*.1 |
| 59 | |
| 60 | install: dfrs docs |
| 61 | $(INSTALL) -Dm 755 target/$(CARGO_TARGET)/dfrs -t $(DESTDIR)$(BINDIR) |
| 62 | $(INSTALL) -Dm 644 contrib/man/*.1 -t $(DESTDIR)$(MANDIR)/man1 |
| 63 | $(INSTALL) -Dm 644 target/completion/bash/dfrs -t $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions |
| 64 | $(INSTALL) -Dm 644 target/completion/zsh/_dfrs -t $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions |
| 65 | $(INSTALL) -Dm 644 target/completion/fish/dfrs.fish -t $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d |
| 66 | |
| 67 | uninstall: |
| 68 | $(RM) -f $(DESTDIR)$(BINDIR)/dfrs |
| 69 | $(RM) -f $(DESTDIR)$(MANDIR)/man1/dfrs.1 |
| 70 | $(RM) -f $(DESTDIR)$(DATAROOTDIR)/bash-completion/completions/dfrs |
| 71 | $(RM) -f $(DESTDIR)$(DATAROOTDIR)/zsh/site-functions/_dfrs |
| 72 | $(RM) -f $(DESTDIR)$(DATAROOTDIR)/fish/vendor_completions.d/dfrs.fish |
| 73 | |
| 74 | release: all |
| 75 | $(INSTALL) -d $(TARBALLDIR) |
| 76 | @read -p 'version> ' TAG && \ |
| 77 | $(SED) "s|version = .*|version = \"$$TAG\"|" -i Cargo.toml && \ |
| 78 | $(CARGO) build --release && \ |
| 79 | $(GIT) commit --gpg-sign --message "version: release $$TAG" Cargo.toml Cargo.lock && \ |
| 80 | $(GIT) tag --sign --message "version: release $$TAG" $$TAG && \ |
| 81 | $(GIT) archive -o $(TARBALLDIR)/dfrs-$$TAG.$(TARBALLFORMAT) --format $(TARBALLFORMAT) --prefix=dfrs-$$TAG/ $$TAG && \ |
| 82 | $(GPG) --detach-sign $(TARBALLDIR)/dfrs-$$TAG.$(TARBALLFORMAT) |