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