summaryrefslogtreecommitdiff
path: root/Makefile
blob: a0c2bf1fcbb03f09eaf9104dfad5dacd981f7ffa (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.POSIX:

PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
DEPENDENCIES = neomutt curl msmtp pass gettext
NON_EXEC_DEPS = isync ca-certificates

check-dependencies:
	@for dep in $(DEPENDENCIES); do \
		if ! command -v $$dep >/dev/null 2>&1; then \
			echo "Error: $$dep is not installed."; \
			exit 1; \
		fi; \
	done
	@for dep in $(NON_EXEC_DEPS); do \
		if command -v pacman >/dev/null 2>&1; then \
			if ! pacman -Q $$dep >/dev/null 2>&1; then \
				echo "Error: $$dep is not installed."; \
				exit 1; \
			fi; \
		elif command -v dpkg >/dev/null 2>&1; then \
			if ! dpkg -s $$dep >/dev/null 2>&1; then \
				echo "Error: $$dep is not installed."; \
				exit 1; \
			fi; \
		elif command -v rpm >/dev/null 2>&1; then \
			if ! rpm -q $$dep >/dev/null 2>&1; then \
				echo "Error: $$dep is not installed."; \
				exit 1; \
			fi; \
		elif command -v zypper >/dev/null 2>&1; then \
			if ! zypper se -i $$dep >/dev/null 2>&1; then \
				echo "Error: $$dep is not installed."; \
				exit 1; \
			fi; \
		else \
			echo "Error: Unsupported package manager. Cannot verify installation of $$dep."; \
			exit 1; \
		fi; \
	done
	@echo "All dependencies are installed."

install-dependencies:
	@if command -v apt-get >/dev/null 2>&1; then \
		echo "Using apt-get to install dependencies..."; \
		sudo apt-get update; \
		sudo apt-get install -y $(DEPENDENCIES); \
	elif command -v yum >/dev/null 2>&1; then \
		echo "Using yum to install dependencies..."; \
		sudo yum install -y $(DEPENDENCIES); \
	elif command -v dnf >/dev/null 2>&1; then \
		echo "Using dnf to install dependencies..."; \
		sudo dnf install -y $(DEPENDENCIES); \
	elif command -v pacman >/dev/null 2>&1; then \
		echo "Using pacman to install dependencies..."; \
		sudo pacman -S --needed $(DEPENDENCIES); \
	elif command -v zypper >/dev/null 2>&1; then \
		echo "Using zypper to install dependencies..."; \
		sudo zypper install -y $(DEPENDENCIES); \
	else \
		echo "Error: No supported package manager found. Please install dependencies manually."; \
		exit 1; \
	fi

install: install-dependencies check-dependencies
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	mkdir -p $(DESTDIR)$(PREFIX)/lib/mutt-wizard
	mkdir -p $(DESTDIR)$(PREFIX)/share/mutt-wizard
	cp -f bin/mailsync $(DESTDIR)$(PREFIX)/bin
	cp -f lib/openfile $(DESTDIR)$(PREFIX)/lib/mutt-wizard
	chmod 755 $(DESTDIR)$(PREFIX)/share/mutt-wizard
	for shared in share/*; do \
		cp -f $$shared $(DESTDIR)$(PREFIX)/share/mutt-wizard; \
		chmod 644 $(DESTDIR)$(PREFIX)/share/mutt-wizard/$$(basename $(notdir $$shared)); \
	done
	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
	cp -f mailsync.1 $(DESTDIR)$(MANPREFIX)/man1/mailsync.1
	sed 's:/usr/local:$(PREFIX):' < share/mutt-wizard.muttrc > $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc
	sed 's:/usr/local:$(PREFIX):' < share/mailcap > $(DESTDIR)$(PREFIX)/share/mutt-wizard/mailcap
	sed 's:/usr/local:$(PREFIX):' < bin/mw > $(DESTDIR)$(PREFIX)/bin/mw
	sed 's:/usr/local:$(PREFIX):' < mw.1 > $(DESTDIR)$(MANPREFIX)/man1/mw.1
	chmod 644 $(DESTDIR)$(MANPREFIX)/man1/mw.1 $(DESTDIR)$(MANPREFIX)/man1/mailsync.1
	chmod 755 $(DESTDIR)$(PREFIX)/bin/mw $(DESTDIR)$(PREFIX)/bin/mailsync $(DESTDIR)$(PREFIX)/lib/mutt-wizard/openfile
	mkdir -p $(DESTDIR)$(PREFIX)/share/zsh/site-functions/
	chmod 755 $(DESTDIR)$(PREFIX)/share/zsh/site-functions/
	cp -f completion/_mutt-wizard.zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_mutt-wizard.zsh
	chmod 644 $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_mutt-wizard.zsh

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/mw $(DESTDIR)$(PREFIX)/bin/mailsync $(DESTDIR)$(PREFIX)/lib/mutt-wizard/openfile
	rm -rf $(DESTDIR)$(PREFIX)/share/mutt-wizard  $(DESTDIR)$(PREFIX)/lib/mutt-wizard
	rm -f $(DESTDIR)$(MANPREFIX)/man1/mw.1  $(DESTDIR)$(MANPREFIX)/man1/mailsync.1
	rm -f $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_mutt-wizard.zsh

.PHONY: install uninstall check-dependencies install-dependencies