aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 9f4702dddb099a6aab61eb16ab64ce8603298bba (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
DESTDIR ?= /usr/local
BUILD_DOCDIR ?= ./doc
CSS ?= /usr/share/javascript/bootstrap4/css/bootstrap.css
HTML_TEMPLATE ?= ./doc/template.html

HTML_FILES = $(addprefix $(BUILD_DOCDIR)/,$(patsubst ./doc/%.md,%.html,$(wildcard ./doc/*.md)))
MANUAL_FILES = $(addprefix $(BUILD_DOCDIR)/,$(patsubst ./doc/%.md,%,$(wildcard ./doc/*.[1-9].md)))

all: manual

manual: $(MANUAL_FILES)
html: $(HTML_FILES)

# upper case the headers and remove the links
$(MANUAL_FILES): $(BUILD_DOCDIR)/%: ./doc/%.md
	pandoc -f markdown -t json -- "$<" | ./pandoc2man.jq | pandoc -s -f json -t man -o "$@"

test:
	./tests/certs/generate
	./tests/run-all

release:
	@if ! git diff HEAD --quiet -- ./Changelog ./interimap ./pullimap ./lib/Net/IMAP/InterIMAP.pm; then \
		echo "Dirty state, refusing to release!" >&2; \
		exit 1; \
	fi
	VERS=$$(dpkg-parsechangelog -l Changelog -SVersion 2>/dev/null) && \
		if git rev-parse -q --verify "refs/tags/v$$VERS" >/dev/null; then echo "tag exists" 2>/dev/null; exit 1; fi && \
		sed -ri "0,/^( -- .*)  .*/ s//\\1  $(shell date -R)/" ./Changelog && \
		sed -ri "0,/^(our\\s+\\\$$VERSION\\s*=\\s*)'[0-9.]+'\\s*;/ s//\\1'$$VERS';/" \
			-- ./interimap ./pullimap && \
		sed -ri "0,/^(package\\s+Net::IMAP::InterIMAP\\s+)v[0-9.]+\\s*;/ s//\\1v$$VERS;/" \
			-- ./lib/Net/IMAP/InterIMAP.pm && \
		sed -ri "0,/^(use\\s+Net::IMAP::InterIMAP\\s+)[0-9.]+(\\s|\\$$)/ s//\\1$$VERS\\2/" \
			-- ./interimap ./pullimap && \
		git commit -m "Prepare new release v$$VERS." \
			-- ./Changelog ./interimap ./pullimap ./lib/Net/IMAP/InterIMAP.pm && \
		git tag -sm "Release version $$VERS" "v$$VERS"

## make html CSS="https://guilhem.org/static/css/bootstrap.min.css" BUILD_DOCDIR="$XDG_RUNTIME_DIR/Downloads"
$(HTML_FILES): $(BUILD_DOCDIR)/%.html: ./doc/%.md $(HTML_TEMPLATE)
	mtime="$$(git --no-pager log -1 --pretty="format:%ct" -- "$<" 2>/dev/null)"; \
	[ -n "$$mtime" ] || mtime="$$(date +%s -r "$<")"; \
	[ "$<" = "doc/index.md" ] && parent="" || parent="./index.html"; \
	pandoc -sp -f markdown -t html+smart --css=$(CSS) --template=$(HTML_TEMPLATE) \
		--variable=date:"$$(LC_TIME=C date +"Last modified on %a, %d %b %Y at %T %z" -d @"$$mtime")" \
		--variable=keywords:"interimap" \
		--variable=lang:"en" \
		--variable=parent:"$$parent" \
		--output="$@" -- "$<"

doc: manual html

prefix ?= $(DESTDIR)
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
libdir ?= $(exec_prefix)/lib
datarootdir ?= $(prefix)/share
mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1

install: all
	install -m0755 -vDt $(bindir) ./interimap ./pullimap
	install -m0644 -vDT ./lib/Net/IMAP/InterIMAP.pm $(datarootdir)/perl5/Net/IMAP/InterIMAP.pm
	install -m0644 -vDt $(man1dir) $(BUILD_DOCDIR)/interimap.1 $(BUILD_DOCDIR)/pullimap.1
	install -m0644 -vDt $(datarootdir)/doc/pullimap ./pullimap.sample
	install -m0644 -vDt $(datarootdir)/doc/interimap ./interimap.sample ./doc/getting-started.md ./doc/multi-account.md README
	install -m0644 -vDt $(libdir)/systemd/user ./*.service

uninstall:
	rm -vf -- $(bindir)/interimap $(man1dir)/interimap.1 $(libdir)/systemd/user/interimap*.service
	rm -vf -- $(bindir)/pullimap $(man1dir)/pullimap.1 $(libdir)/systemd/user/pullimap*.service
	rm -vf -- $(datarootdir)/perl5/Net/IMAP/InterIMAP.pm
	rm -rvf -- $(datarootdir)/doc/interimap $(datarootdir)/doc/pullimap
	rm -vf -- $(BUILD_DOCDIR)/interimap.1 $(BUILD_DOCDIR)/pullimap.1

clean:
	rm -vf -- $(MANUAL_FILES) $(HTML_FILES)

.PHONY: all manual html doc test release install uninstall clean