-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
124 lines (102 loc) · 3.4 KB
/
Makefile
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
base_url = https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/man-pages-posix/
BASE_URL = https://manp.gs/posix/
dirs = 0 1 3
MANDOC=mandoc
FLAGS=-Oman=../%S/%N,style=../style.css
FILTER=sed '/<pre>/,/<\/pre>/{/^<br\/>$$/d;}'
CMD=$(MANDOC) $(FLAGS) -Thtml "$<" | $(FILTER)
BUILD=$(CMD) > "$@"
REDIRECT = 1
ifeq ($(REDIRECT),1)
FILTER=sed \
-e "$$(printf '%s\n' '/<body>/,/<\/body>/c\' '<body>Redirecting…</body>')"\
-e 's|<title>\(.*\)(0P)</title>|&\n <meta http-equiv="refresh" content="0;url=https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/\1.html">|'\
-e 's|<title>\(.*\)(1P)</title>|&\n <meta http-equiv="refresh" content="0;url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/\1.html">|'\
-e 's|<title>\(.*\)(3P)</title>|&\n <meta http-equiv="refresh" content="0;url=https://pubs.opengroup.org/onlinepubs/9799919799/functions/\1.html">|'\
-e '/http-equiv/y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
endif
template = <!doctype html>\n<html lang="en">\n\
\40<head>\n\
\40\40\40<meta charset="utf-8">\n\
\40\40\40<title>%s</title>\n\
\40\40\40<link rel="stylesheet" href="%s">\n\
\40</head>\n\
\40<body>\n\
\40\40\40<main>\n\
\40\40\40\40\40<h1>%s</h1>\n%s\n\
\40\40\40</main>\n\
\40</body>\n</html>\n
sitemap = <?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n%s\n</urlset>\n
desc = desc() { \
case $$1 in \
0) echo Headers ;; \
1) echo Utilities ;; \
3) echo Functions ;; \
esac; \
};
html = $(shell find man/man?? -type f | sed 's|^.*/\([^/]*\)\.\([0-9]\)p$$|\2/\1.html|')
all: man $(dirs) index.html
$(MAKE) $(html)
$(MAKE) sitemap.xml
$(dirs):
mkdir -p "$@"
posix-man-pages.tar.gz:
curl -o $@ "${base_url}$$(curl ${base_url} | \
grep -o 'man-pages-posix-[^"]*.tar.gz' | tail -n1)"
man: posix-man-pages.tar.gz
tar -xf posix-man-pages.tar.gz
mv man-pages-posix-* man
man/whatis: man
/usr/libexec/makewhatis man
printf '%s\n' '1,$$s/(\([0-9]\)p)/(\1)/g' w q | ed -s man/whatis
clean:
$(RM) -r index.html sitemap.xml $(dirs) man posix-man-pages.tar.gz
index.html: $(addsuffix /index.html,$(dirs))
$(desc) \
printf '$(template)' "POSIX Manpages" "style.css" "POSIX Manpages" "$$(\
for s in $(dirs); do \
printf ' <h2><a href="%s">%s — %s</a></h2>\n' \
"$$s" "$$s" "$$(desc "$$s")"; \
done; \
)" > "$@"
sitemap.xml:
printf '$(sitemap)' "$$(\
(echo "" && printf '%s/\n' $(dirs)) | while read dir; do \
printf " <url><loc>%s%s</loc></url>\n" "$(BASE_URL)" "$$dir"; \
done; \
find $(dirs) -type f ! -name index.html | sort | awk '{ \
sub(/\.[^.]+$$/, ""); \
gsub(/ /, "%20"); \
gsub(/\[/, "%5B"); \
printf " <url><loc>%s%s</loc></url>\n", "$(BASE_URL)", $$0; \
}'; \
)" > "$@"
%/index.html: man/whatis
$(desc) \
sect=$$(dirname "$@"); \
printf '$(template)' "man$$sect — POSIX Manpages" "../style.css" \
"<a href=\"../\">POSIX</a> — $$(desc "$$sect")" "$$(\
printf ' <ul class="whatis">\n'; \
sed -n -e ' \
h; \
s/ - /\n/; \
s|.*\n||; \
x; \
s| - .*||; \
' -e 't clear' -e :clear -e ' \
s|('"$$sect"')|&|; \
' -e 't link' -e b -e :link -e '\
s|\([^, ][^(]*\)([0-9n][^)]*)|<a href="./\1">&</a>|g; \
s|^| <li>|; \
G; \
s|\n| \— |; \
s|$$|</li>|p; \
' man/whatis; \
printf ' </ul>\n' \
)" > "$@"
0/%.html: man/man0p/%.0p
$(BUILD)
1/%.html: man/man1p/%.1p
$(BUILD)
3/%.html: man/man3p/%.3p
$(BUILD)