aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 23a62336445bad31aac95ff138ac5e2b87403117 (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
all: manual

MANUALS = $(patsubst %.md,%,$(wildcard ./doc/*.[1-9].md))
manual: $(MANUALS)

# upper case the headers and remove the links
$(MANUALS): %: %.md
	@pandoc -f markdown -t json -- "$<" | \
	jq "                                                                        \
	    def fixheaders:                                                         \
	        if .t == \"Header\" then                                            \
	            .c[2][] |= (if .t == \"Str\" then .c |= ascii_upcase else . end)\
	        else                                                                \
	            .                                                               \
	        end;                                                                \
	    def fixlinks:                                                           \
	        if type == \"object\" then                                          \
	            if .t == \"Link\" then                                          \
	                if .c[2][0][0:7] == \"mailto:\" then . else .c[1][] end     \
	            else                                                            \
	                map_values(fixlinks)                                        \
	            end                                                             \
	        else if type == \"array\" then                                      \
	                map(fixlinks)                                               \
	            else                                                            \
	                .                                                           \
	            end                                                             \
	        end;                                                                \
	    { \"pandoc-api-version\"                                                \
	    , meta                                                                  \
	    , blocks: .blocks | map(fixheaders) | map(fixlinks)                     \
	    }" | \
	pandoc -s -f json -t man+smart -o "$@"

test:
	@for t in tests/*; do if [ -f "$$t/run" ]; then ./tests/run "$$t" || exit 1; fi; done

HTML_ROOTDIR ?= ./doc
CSS ?= /usr/share/javascript/bootstrap/css/bootstrap.min.css
HTML_TEMPLATE ?= ./doc/template.html

HTML_FILES = $(addprefix $(HTML_ROOTDIR)/,$(patsubst ./doc/%.md,%.html,$(wildcard ./doc/*.md)))
html: $(HTML_FILES)

## CSS="https://guilhem.org/static/css/bootstrap.min.css" HTML_ROOTDIR="$XDG_RUNTIME_DIR/Downloads" make html
$(HTML_ROOTDIR)/%.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=parent:"$$parent" \
		--output="$@" -- "$<"

doc: manual html

install:

clean:
	rm -f $(MANUALS) $(HTML_FILES)

.PHONY: all manual html doc test install clean