aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 7bd231c523a2d7f81ef399e1cbfb5824c6091336 (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
.POSIX:
.SUFFIXES:
.SUFFIXES: .md .html .gmi

# commands
GIT = git
PANDOC = pandoc
PDFINFO = pdfinfo

# input files
SRC = index.md vs-c.md tagged-unions.md types.md safety.md errors.md syntax.md LICENSE.md
HTML = $(SRC:.md=.html)
GMI = $(SRC:.md=.gmi)

all: spec.pdf $(GMI)

spec.pdf: $(HTML)
	@if $(GIT) describe --tags --exact-match 2>/dev/null; \
	then \
		metadata="subtitle=$$($(GIT) describe --tags --exact-match)"; \
	else \
		metadata="version=$$($(GIT) log -1 --no-decorate --oneline)"; \
	fi; \
	$(PANDOC) --defaults=etc/pdf.yml -M "$$metadata" -o $@ $(HTML)

.md.html:
	@offset=`echo $(SRC) | awk '{for (i=1; i<=NF; i++) if ($$i == "$<") print (i-1) }'`; \
	$(PANDOC) --defaults=etc/md.yml --number-offset=$$offset -o $@ $<

.md.gmi:
	@offset=`echo $(SRC) | awk '{for (i=1; i<=NF; i++) if ($$i == "$<") print (i-1) }'`; \
	$(PANDOC) --defaults=etc/md.yml --write=etc/gemtext.lua --template=etc/template.gmi --number-offset=$$offset -o $@ $<

clean: clean-pdf clean-html clean-gmi

clean-pdf:
	rm -f spec.pdf

clean-html:
	rm -f $(HTML)

clean-gmi:
	rm -f $(GMI)

check: spec.pdf
	test $$($(PDFINFO) spec.pdf | grep Pages | awk '{ print $$2 }') -le 200