summaryrefslogtreecommitdiff
path: root/Makefile
blob: e196a7e2e59cb49ed87d93df0d51e34b3be87a3e (plain) (blame)
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
name = idioms
version = 20200128

prefix ?=
bindir ?= $(prefix)/bin
datadir ?= $(prefix)/share
mandir ?= $(datadir)/man
man1dir ?= $(mandir)/man1

BINS := $(patsubst %.in, %, $(shell find bin/ -name '*.in'))
MAN1S := $(patsubst %.adoc, %, $(wildcard man/*.1.adoc))
HTMLS := $(patsubst %.adoc, %.html, $(wildcard man/*.adoc))
MANS := $(MAN1S)

INSTALLS := \
	$(addprefix $(DESTDIR)$(bindir)/,$(BINS:bin/%=%)) \
	$(addprefix $(DESTDIR)$(man1dir)/,$(MAN1S:man/%=%))

.PHONY: all
all: bin man

.PHONY: clean
clean:
	rm -f $(BINS) $(LIBS) $(MANS) $(HTMLS)

.PHONY: install
install: $(INSTALLS)

.PHONY: test check
test: check

check: all
	test/test.sh

.PHONY: bin
bin: $(BINS)

.PHONY: man
man: $(MANS)

.PHONY: html
html: $(HTMLS)

bin/%: bin/%.in
	sed \
		-e "s|@@name@@|$(name)|g" \
		-e "s|@@version@@|$(version)|g" \
		-e "s|@@prefix@@|$(prefix)|g" \
		-e "s|@@bindir@@|$(bindir)|g" \
		$< > $@
	chmod +x $@

.DELETE_ON_ERROR: man/%
man/%.html: man/%.adoc
	asciidoctor --failure-level=WARNING -b html5 -B $(PWD) -o $@ $<

.DELETE_ON_ERROR: man/%
man/%: man/%.adoc
	asciidoctor --failure-level=WARNING -b manpage -B $(PWD) -d manpage -o $@ $<

$(DESTDIR)$(bindir)/%: bin/%
	install -D $< $@

$(DESTDIR)$(man1dir)/%: man/%
	install -D $< $@