Makefile

4fddc50d6d9f3d82220a4e3264d792d54fc940cf
weechat-matrix-rs/Makefile history · blame · raw

55 lines · 2047 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
 4
 5SOURCES := $(wildcard src/*.rs src/bar_items/*.rs src/commands/*.rs src/room/*.rs Cargo.lock)
 6
 7PROFILE ?= release
 8
 9.PHONY: install install-dir lint all help deb
10
11all: help
12
13help: ## Print this help message
14	@grep -E '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
15
16target/debug/libmatrix.so: $(SOURCES) ## Build plugin in dev profile
17	cargo build
18
19target/release/libmatrix.so: $(SOURCES) ## Build plugin release profile
20	cargo build --release
21
22install: install-dir target/$(PROFILE)/libmatrix.so ## Install plugin to weechat dir
23	install -m644  target/$(PROFILE)/libmatrix.so $(DESTDIR)$(WEECHAT_DATA_DIR)/plugins/matrix.so
24
25install-dir: ## Create plugins directory
26	install -d $(DESTDIR)$(WEECHAT_DATA_DIR)/plugins
27
28lint: ## Lint issues with clippy
29	cargo clippy
30
31# Get the base package version from Cargo.toml (fallback when no git tags are found)
32CARGO_VERSION := $(shell grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
33
34deb: target/$(PROFILE)/libmatrix.so ## Build a .deb package with version from git describe
35	DEB_VERSION=$$( \
36	  desc=$$(git describe --tags --always --dirty --match '[0-9]*' 2>/dev/null); \
37	  if [ -z "$$desc" ]; then \
38	    echo "$(CARGO_VERSION)+unknown"; \
39	  else \
40	    case "$$desc" in \
41	      *-dirty) dirty=".dirty"; desc="$${desc%-dirty}" ;; \
42	      *) dirty="" ;; \
43	    esac; \
44	    case "$$desc" in \
45	      *.*) ;; \
46	      *) desc="$(CARGO_VERSION)+git.$$desc" ;; \
47	    esac; \
48	    desc=$$(echo "$$desc" | sed 's/-\([0-9][0-9]*\)-g\([0-9a-f][0-9a-f]*\)/+\1.\2/'); \
49	    echo "$$desc$$dirty"; \
50	  fi \
51	); \
52	cargo deb --no-build --deb-version "$$DEB_VERSION"
53	@echo ""
54	@echo "Package built: target/debian/weechat-matrix_$${DEB_VERSION}*.deb"
55	@echo "Install with: sudo dpkg -i target/debian/weechat-matrix_$${DEB_VERSION}*.deb"