forked from valkey-io/valkey-doc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
233 lines (181 loc) · 8.3 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Copyright (C) 2024, The Valkey contributors
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# Version info
VERSION ?= 8.0.0
DATE ?= 2024-09-23
# Path to the code repo.
VALKEY_ROOT ?= ../valkey
# Where to install man pages
INSTALL_MAN_DIR ?= /usr/local/share/man
# Where to put the generated pages.
BUILD_DIR ?= _build
MD_DIR ?= $(BUILD_DIR)/md
MAN_DIR ?= $(BUILD_DIR)/man
HTML_DIR ?= $(BUILD_DIR)/html
# -----------------------------------
.PHONY: all man html md clean distclean install uninstall
all: man
# ---- Sanity check ----
ifeq ("$(wildcard $(VALKEY_ROOT))","")
$(error Please provide the VALKEY_ROOT variable pointing to the Valkey source code)
endif
ifeq ("$(shell which pandoc)","")
$(error Please install pandoc)
endif
# ---- If we're in a git repo, override date and version ----
ifneq ($(wildcard .git),)
DATE=$(shell git log -1 --format=%cs)
described=$(shell git describe --tags --always)
# If git returned a clean version on the form X.Y.Z, then check that it
# matches the declared VERSION. This is just when tagging.
ifneq ($(shell echo $(described) | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$'),)
ifneq ($(described),$(VERSION))
$(error Declared VERSION $(VERSION) mismatches git tag $(described))
endif
endif
VERSION=$(described)
$(warning $(VERSION) $(DATE))
endif
# ---- Source files ----
topics = $(wildcard topics/*)
commands = $(wildcard commands/*.md)
topics_md = $(filter %.md,$(topics))
topics_pics = $(filter-out %.md,$(topics))
# ---- Temp files ----
# JSON files for the commands that have a .md file (excluding undocumented commands).
json_for_documented_commands = $(commands:commands/%.md=$(VALKEY_ROOT)/src/commands/%.json)
$(BUILD_DIR)/.commands-per-group.json: $(VALKEY_ROOT)/src/commands/. utils/build-command-groups.py | $(BUILD_DIR)
utils/build-command-groups.py $(json_for_documented_commands) > $@
$(BUILD_DIR):
mkdir -p $@
# ---- Pre-processed markdown files (make md) ----
md_topics_dir = $(MD_DIR)/topics
md_topics = $(topics:topics/%=$(md_topics_dir)/%)
$(md_topics): | $(md_topics_dir)
md_commands_dir = $(MD_DIR)/commands
md_commands = $(commands:commands/%=$(md_commands_dir)/%)
$(md_commands): | $(md_commands_dir)
md_targets = $(md_topics) $(md_commands) $(md_commands_dir)/index.md
$(md_topics_dir) $(md_commands_dir):
mkdir -p $@
$(md_topics_dir)/%.md: topics/%.md utils/preprocess-markdown.py | $(md_topics_dir)
utils/preprocess-markdown.py $< > $@
$(md_topics_dir)/%.png: topics/%.png | $(md_topics_dir)
cp $< $@
$(md_topics_dir)/%.gif: topics/%.gif | $(md_topics_dir)
cp $< $@
$(md_commands_dir)/index.md: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py | $(md_commands_dir)
utils/build-command-index.py --suffix .md \
--groups-json groups.json \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json > $@
$(md_commands_dir)/%.md: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json \
utils/preprocess-markdown.py utils/command_syntax.py
utils/preprocess-markdown.py --page-type command \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
--valkey-root $(VALKEY_ROOT) $< > $@
# ---- HTML (make html) ----
html_topics_dir = $(HTML_DIR)/topics
html_topics = $(topics_md:topics/%.md=$(html_topics_dir)/%.html)
html_topics_pics = $(topics_pics:topics/%=$(html_topics_dir)/%)
$(html_topics): | $(html_topics_dir)
html_commands_dir = $(HTML_DIR)/commands
html_commands = $(commands:commands/%.md=$(html_commands_dir)/%.html)
$(html_commands): | $(html_commands_dir)
html_targets = $(html_topics) $(html_topics_pics) $(html_commands) $(html_commands_dir)/index.html
$(html_topics_dir) $(html_commands_dir):
mkdir -p $@
$(html_topics_dir)/%.html: topics/%.md utils/preprocess-markdown.py | $(html_topics_dir)
utils/preprocess-markdown.py --suffix .html $< | pandoc -s --to html -o $@ -
$(html_topics_dir)/%.png: topics/%.png | $(html_topics_dir)
cp $< $@
$(html_topics_dir)/%.gif: topics/%.gif | $(html_topics_dir)
cp $< $@
$(html_commands_dir)/index.html: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py | $(html_commands_dir)
utils/build-command-index.py --suffix .html \
--groups-json groups.json \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
| pandoc -s --to html -o $@ -
$(html_commands_dir)/%.html: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json \
utils/preprocess-markdown.py utils/command_syntax.py
utils/preprocess-markdown.py --suffix .html --page-type command \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
--valkey-root $(VALKEY_ROOT) $< \
| pandoc -s --to html -o $@ -
# ---- Man pages (make man) ----
# Split topics into configs, programs and topics
progs = valkey-cli valkey-server valkey-benchmark valkey-sentinel valkey-check-rdb valkey-check-aof
programs = $(progs:valkey-%=topics/%.md)
configs = topics/valkey.conf.md
man1_src = $(filter $(programs),$(topics_md))
man3_src = $(commands)
man5_src = $(filter $(configs),$(topics_md))
man7_src = $(filter-out $(programs) $(configs) topics/index.md,$(topics_md))
# Target man pages
man1 = $(man1_src:topics/%.md=$(MAN_DIR)/man1/valkey-%.1.gz)
man3 = $(man3_src:commands/%.md=$(MAN_DIR)/man3/%.3valkey.gz)
man5 = $(man5_src:topics/%.md=$(MAN_DIR)/man5/%.5.gz)
man7 = $(man7_src:topics/%.md=$(MAN_DIR)/man7/valkey-%.7.gz) $(MAN_DIR)/man7/valkey-commands.7.gz $(MAN_DIR)/man7/valkey.7.gz
man_targets = $(man1) $(man3) $(man5) $(man7)
$(man1): | $(MAN_DIR)/man1
$(man3): | $(MAN_DIR)/man3
$(man5): | $(MAN_DIR)/man5
$(man7): | $(MAN_DIR)/man7
$(MAN_DIR)/man1 $(MAN_DIR)/man3 $(MAN_DIR)/man5 $(MAN_DIR)/man7:
mkdir -p $@
man_scripts = utils/preprocess-markdown.py utils/command_syntax.py utils/links-to-man.py
to_man = pandoc -s --to man - | gzip -
$(MAN_DIR)/man1/valkey-%.1.gz: topics/%.md $(man_scripts)
utils/preprocess-markdown.py --man --page-type program \
--version $(VERSION) --date $(DATE) \$< \
| utils/links-to-man.py - | $(to_man) > $@
$(MAN_DIR)/man3/%.3valkey.gz: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json $(man_scripts)
utils/preprocess-markdown.py --man --page-type command \
--version $(VERSION) --date $(DATE) \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
--valkey-root $(VALKEY_ROOT) $< \
| utils/links-to-man.py - | $(to_man) > $@
$(MAN_DIR)/man5/%.5.gz: topics/%.md $(man_scripts)
utils/preprocess-markdown.py --man --page-type config \
--version $(VERSION) --date $(DATE) $< \
| utils/links-to-man.py - | $(to_man) > $@
$(MAN_DIR)/man7/valkey-%.7.gz: topics/%.md $(man_scripts)
utils/preprocess-markdown.py --man --page-type topic \
--version $(VERSION) --date $(DATE) $< \
| utils/links-to-man.py - | $(to_man) > $@
$(MAN_DIR)/man7/valkey.7.gz: topics/index.md $(man_scripts)
utils/preprocess-markdown.py --man --page-type topic \
--version $(VERSION) --date $(DATE) $< \
| utils/links-to-man.py - | $(to_man) > $@
$(MAN_DIR)/man7/valkey-commands.7.gz: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py
utils/build-command-index.py --man \
--version $(VERSION) --date $(DATE) \
--groups-json groups.json \
--commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \
| $(to_man) > $@
.PHONY: install-man uninstall-man
install-man: man | $(INSTALL_MAN_DIR)/man1 $(INSTALL_MAN_DIR)/man3 $(INSTALL_MAN_DIR)/man5 $(INSTALL_MAN_DIR)/man7
cp $(MAN_DIR)/man1/valkey*.1.gz $(INSTALL_MAN_DIR)/man1/
cp $(MAN_DIR)/man3/*.3valkey.gz $(INSTALL_MAN_DIR)/man3/
cp $(MAN_DIR)/man5/valkey*.5.gz $(INSTALL_MAN_DIR)/man5/
cp $(MAN_DIR)/man7/valkey*.7.gz $(INSTALL_MAN_DIR)/man7/
$(INSTALL_MAN_DIR)/man1 $(INSTALL_MAN_DIR)/man3 $(INSTALL_MAN_DIR)/man5 $(INSTALL_MAN_DIR)/man7:
mkdir -p $@
uninstall-man:
rm -f $(INSTALL_MAN_DIR)/man1/valkey*.1*
rm -f $(INSTALL_MAN_DIR)/man3/*.3valkey*
rm -f $(INSTALL_MAN_DIR)/man4/valkey*.4*
rm -f $(INSTALL_MAN_DIR)/man5/valkey*.5*
rm -f $(INSTALL_MAN_DIR)/man7/valkey*.7*
# -------
# All targets
targets = $(man_targets) $(html_targets) $(md_targets)
md: $(md_targets)
html: $(html_targets)
man: $(man_targets)
clean:
rm -f $(targets) $(BUILD_DIR)/.commands-per-group.json
distclean:
rm -rf $(BUILD_DIR)
install: install-man
uninstall: uninstall-man