Makefile

1aebd1afe96d6b9a2f26ca598c88d5aae0ba5008
weechat-matrix-rs/Makefile history · blame · raw

81 lines · 3037 bytes

 1# See https://weechat.org/files/doc/weechat/stable/weechat_user.en.html#xdg_directories
 2XDG_DATA_HOME ?= $(HOME)/.local/share
 3WEECHAT_DATA_DIR ?= $(XDG_DATA_HOME)/weechat
 4DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null)
 5ifeq ($(DEB_HOST_MULTIARCH),)
 6WEECHAT_PLUGIN_DIR ?= /usr/lib/weechat/plugins
 7else
 8WEECHAT_PLUGIN_DIR ?= /usr/lib/$(DEB_HOST_MULTIARCH)/weechat/plugins
 9endif
10
11SOURCES := $(wildcard src/*.rs src/bar_items/*.rs src/commands/*.rs src/room/*.rs Cargo.lock)
12
13PROFILE ?= release
14
15.PHONY: install install-user uninstall uninstall-user install-dir install-user-dir lint check clean all help deb
16
17all: help
18
19help: ## Print this help message
20	@grep -E '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'; printf '\nAppend PROFILE=debug to the install and deb targets for debug builds\n\n'
21
22target/debug/libmatrix.so: $(SOURCES) ## Build plugin in dev profile
23	cargo build
24
25target/release/libmatrix.so: $(SOURCES) ## Build plugin release profile
26	cargo build --release
27
28install: install-dir target/$(PROFILE)/libmatrix.so ## Install plugin systemwide
29	install -m644  target/$(PROFILE)/libmatrix.so $(DESTDIR)$(WEECHAT_PLUGIN_DIR)/matrix.so
30
31install-user: install-user-dir target/$(PROFILE)/libmatrix.so ## Install plugin to user WeeChat dir
32	install -m644  target/$(PROFILE)/libmatrix.so $(DESTDIR)$(WEECHAT_DATA_DIR)/plugins/matrix.so
33
34uninstall: ## Remove systemwide plugin
35	rm -f $(DESTDIR)$(WEECHAT_PLUGIN_DIR)/matrix.so
36
37uninstall-user: ## Remove plugin from user WeeChat dir
38	rm -f $(DESTDIR)$(WEECHAT_DATA_DIR)/plugins/matrix.so
39
40install-dir:
41	install -d $(DESTDIR)$(WEECHAT_PLUGIN_DIR)
42
43install-user-dir:
44	install -d $(DESTDIR)$(WEECHAT_DATA_DIR)/plugins
45
46lint: ## Lint issues with clippy
47	cargo clippy
48
49check: ## Run test suite
50	cargo test --release
51
52clean: ## Remove build artifacts
53	cargo clean
54	rm -rf target/debian
55	-find src -name '*.rs.bk' -delete 2>/dev/null || true
56
57# Get the base package version from Cargo.toml (fallback when no git tags are found)
58CARGO_VERSION := $(shell grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
59
60deb: target/$(PROFILE)/libmatrix.so ## Build a .deb package with version from git describe
61	DEB_VERSION=$$( \
62	  desc=$$(git describe --tags --always --dirty --match '[0-9]*' 2>/dev/null); \
63	  if [ -z "$$desc" ]; then \
64	    echo "$(CARGO_VERSION)+unknown"; \
65	  else \
66	    case "$$desc" in \
67	      *-dirty) dirty=".dirty"; desc="$${desc%-dirty}" ;; \
68	      *) dirty="" ;; \
69	    esac; \
70	    case "$$desc" in \
71	      *.*) ;; \
72	      *) desc="$(CARGO_VERSION)+git.$$desc" ;; \
73	    esac; \
74	    desc=$$(echo "$$desc" | sed 's/-\([0-9][0-9]*\)-g\([0-9a-f][0-9a-f]*\)/+\1.\2/'); \
75	    echo "$$desc$$dirty"; \
76	  fi \
77	); \
78	cargo deb --no-build --deb-version "$$DEB_VERSION"
79	@echo ""
80	@echo "Package built: target/debian/weechat-matrix-rs_$${DEB_VERSION}*.deb"
81	@echo "Install with: sudo dpkg -i target/debian/weechat-matrix-rs_$${DEB_VERSION}*.deb"