|
| 1 | +# Copyright (C) 2024, The Valkey contributors |
| 2 | +# All rights reserved. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | + |
| 5 | +# Path to the code repo. |
| 6 | +VALKEY_ROOT ?= ../valkey |
| 7 | + |
| 8 | +# Where to install man pages |
| 9 | +INSTALL_MAN_DIR ?= /usr/local/share/man |
| 10 | + |
| 11 | +# Where to put the generated pages. |
| 12 | +BUILD_DIR ?= _build |
| 13 | +MD_DIR ?= $(BUILD_DIR)/md |
| 14 | +MAN_DIR ?= $(BUILD_DIR)/man |
| 15 | +HTML_DIR ?= $(BUILD_DIR)/html |
| 16 | + |
| 17 | +# ----------------------------------- |
| 18 | + |
| 19 | +.PHONY: all man html md clean distclean install uninstall |
| 20 | + |
| 21 | +all: man |
| 22 | + |
| 23 | +# ---- Sanity check ---- |
| 24 | + |
| 25 | +ifeq ("$(wildcard $(VALKEY_ROOT))","") |
| 26 | + $(error Please provide the VALKEY_ROOT variable pointing to the Valkey source code) |
| 27 | +endif |
| 28 | + |
| 29 | +ifeq ("$(shell which pandoc)","") |
| 30 | + $(error Please install pandoc) |
| 31 | +endif |
| 32 | + |
| 33 | +# ---- Source files ---- |
| 34 | + |
| 35 | +topics = $(wildcard topics/*) |
| 36 | +commands = $(wildcard commands/*.md) |
| 37 | + |
| 38 | +topics_md = $(filter %.md,$(topics)) |
| 39 | +topics_pics = $(filter-out %.md,$(topics)) |
| 40 | + |
| 41 | +# ---- Temp files ---- |
| 42 | + |
| 43 | +# JSON files for the commands that have a .md file (excluding undocumented commands). |
| 44 | +json_for_documented_commands = $(commands:commands/%.md=$(VALKEY_ROOT)/src/commands/%.json) |
| 45 | + |
| 46 | +$(BUILD_DIR)/.commands-per-group.json: $(VALKEY_ROOT)/src/commands/. utils/build-command-groups.py | $(BUILD_DIR) |
| 47 | + utils/build-command-groups.py $(json_for_documented_commands) > $@ |
| 48 | +$(BUILD_DIR): |
| 49 | + mkdir -p $@ |
| 50 | + |
| 51 | +# ---- Pre-processed markdown files (make md) ---- |
| 52 | + |
| 53 | +md_topics_dir = $(MD_DIR)/topics |
| 54 | +md_topics = $(topics:topics/%=$(md_topics_dir)/%) |
| 55 | +$(md_topics): | $(md_topics_dir) |
| 56 | + |
| 57 | +md_commands_dir = $(MD_DIR)/commands |
| 58 | +md_commands = $(commands:commands/%=$(md_commands_dir)/%) |
| 59 | +$(md_commands): | $(md_commands_dir) |
| 60 | + |
| 61 | +md_targets = $(md_topics) $(md_commands) $(md_commands_dir)/index.md |
| 62 | + |
| 63 | +$(md_topics_dir) $(md_commands_dir): |
| 64 | + mkdir -p $@ |
| 65 | + |
| 66 | +$(md_topics_dir)/%.md: topics/%.md utils/preprocess-markdown.py | $(md_topics_dir) |
| 67 | + utils/preprocess-markdown.py $< > $@ |
| 68 | +$(md_topics_dir)/%.png: topics/%.png | $(md_topics_dir) |
| 69 | + cp $< $@ |
| 70 | +$(md_topics_dir)/%.gif: topics/%.gif | $(md_topics_dir) |
| 71 | + cp $< $@ |
| 72 | + |
| 73 | +$(md_commands_dir)/index.md: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py | $(md_commands_dir) |
| 74 | + utils/build-command-index.py --suffix .md \ |
| 75 | + --groups-json groups.json \ |
| 76 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json > $@ |
| 77 | + |
| 78 | +$(md_commands_dir)/%.md: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json \ |
| 79 | + utils/preprocess-markdown.py utils/command_syntax.py |
| 80 | + utils/preprocess-markdown.py --page-type command \ |
| 81 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \ |
| 82 | + --valkey-root $(VALKEY_ROOT) $< > $@ |
| 83 | + |
| 84 | +# ---- HTML (make html) ---- |
| 85 | + |
| 86 | +html_topics_dir = $(HTML_DIR)/topics |
| 87 | +html_topics = $(topics_md:topics/%.md=$(html_topics_dir)/%.html) |
| 88 | +html_topics_pics = $(topics_pics:topics/%=$(html_topics_dir)/%) |
| 89 | +$(html_topics): | $(html_topics_dir) |
| 90 | + |
| 91 | +html_commands_dir = $(HTML_DIR)/commands |
| 92 | +html_commands = $(commands:commands/%.md=$(html_commands_dir)/%.html) |
| 93 | +$(html_commands): | $(html_commands_dir) |
| 94 | + |
| 95 | +html_targets = $(html_topics) $(html_topics_pics) $(html_commands) $(html_commands_dir)/index.html |
| 96 | + |
| 97 | +$(html_topics_dir) $(html_commands_dir): |
| 98 | + mkdir -p $@ |
| 99 | + |
| 100 | +$(html_topics_dir)/%.html: topics/%.md utils/preprocess-markdown.py | $(html_topics_dir) |
| 101 | + utils/preprocess-markdown.py --suffix .html $< | pandoc -s --to html -o $@ - |
| 102 | +$(html_topics_dir)/%.png: topics/%.png | $(html_topics_dir) |
| 103 | + cp $< $@ |
| 104 | +$(html_topics_dir)/%.gif: topics/%.gif | $(html_topics_dir) |
| 105 | + cp $< $@ |
| 106 | + |
| 107 | +$(html_commands_dir)/index.html: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py | $(html_commands_dir) |
| 108 | + utils/build-command-index.py --suffix .html \ |
| 109 | + --groups-json groups.json \ |
| 110 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \ |
| 111 | + | pandoc -s --to html -o $@ - |
| 112 | +$(html_commands_dir)/%.html: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json \ |
| 113 | + utils/preprocess-markdown.py utils/command_syntax.py |
| 114 | + utils/preprocess-markdown.py --suffix .html --page-type command \ |
| 115 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \ |
| 116 | + --valkey-root $(VALKEY_ROOT) $< \ |
| 117 | + | pandoc -s --to html -o $@ - |
| 118 | + |
| 119 | +# ---- Man pages (make man) ---- |
| 120 | + |
| 121 | +# Split topics into configs, programs and topics |
| 122 | +progs = valkey-cli valkey-server valkey-benchmark valkey-sentinel valkey-check-rdb valkey-check-aof |
| 123 | +programs = $(progs:valkey-%=topics/%.md) |
| 124 | +configs = topics/valkey.conf.md |
| 125 | + |
| 126 | +man1_src = $(filter $(programs),$(topics_md)) |
| 127 | +man3_src = $(commands) |
| 128 | +man4_src = $(filter $(configs),$(topics_md)) |
| 129 | +man7_src = $(filter-out $(programs) $(configs) topics/index.md,$(topics_md)) |
| 130 | + |
| 131 | +# Target man pages |
| 132 | +man1 = $(man1_src:topics/%.md=$(MAN_DIR)/man1/valkey-%.1) |
| 133 | +man3 = $(man3_src:commands/%.md=$(MAN_DIR)/man3/%.3valkey) |
| 134 | +man4 = $(man4_src:topics/%.md=$(MAN_DIR)/man4/%.4) |
| 135 | +man7 = $(man7_src:topics/%.md=$(MAN_DIR)/man7/valkey-%.7) $(MAN_DIR)/man7/valkey-commands.7 $(MAN_DIR)/man7/valkey.7 |
| 136 | + |
| 137 | +man_targets = $(man1) $(man3) $(man4) $(man7) |
| 138 | + |
| 139 | +$(man1): | $(MAN_DIR)/man1 |
| 140 | +$(man3): | $(MAN_DIR)/man3 |
| 141 | +$(man4): | $(MAN_DIR)/man4 |
| 142 | +$(man7): | $(MAN_DIR)/man7 |
| 143 | +$(MAN_DIR)/man1 $(MAN_DIR)/man3 $(MAN_DIR)/man4 $(MAN_DIR)/man7: |
| 144 | + mkdir -p $@ |
| 145 | + |
| 146 | +man_scripts = utils/preprocess-markdown.py utils/command_syntax.py utils/links-to-man.py |
| 147 | + |
| 148 | +$(MAN_DIR)/man1/valkey-%.1: topics/%.md $(man_scripts) |
| 149 | + utils/preprocess-markdown.py --man --page-type program $< \ |
| 150 | + | utils/links-to-man.py - | pandoc -s --to man -o $@ - |
| 151 | +$(MAN_DIR)/man3/%.3valkey: commands/%.md $(VALKEY_ROOT)/src/commands/%.json $(BUILD_DIR)/.commands-per-group.json $(man_scripts) |
| 152 | + utils/preprocess-markdown.py --man --page-type command \ |
| 153 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \ |
| 154 | + --valkey-root $(VALKEY_ROOT) $< \ |
| 155 | + | utils/links-to-man.py - | pandoc -s --to man -o $@ - |
| 156 | +$(MAN_DIR)/man4/%.4: topics/%.md $(man_scripts) |
| 157 | + utils/preprocess-markdown.py --man --page-type config $< \ |
| 158 | + | utils/links-to-man.py - | pandoc -s --to man -o $@ - |
| 159 | +$(MAN_DIR)/man7/valkey-%.7: topics/%.md $(man_scripts) |
| 160 | + utils/preprocess-markdown.py --man --page-type topic $< \ |
| 161 | + | utils/links-to-man.py - | pandoc -s --to man -o $@ - |
| 162 | +$(MAN_DIR)/man7/valkey.7: topics/index.md $(man_scripts) |
| 163 | + utils/preprocess-markdown.py --man --page-type topic $< \ |
| 164 | + | utils/links-to-man.py - | pandoc -s --to man -o $@ - |
| 165 | +$(MAN_DIR)/man7/valkey-commands.7: $(BUILD_DIR)/.commands-per-group.json groups.json utils/build-command-index.py |
| 166 | + utils/build-command-index.py --man \ |
| 167 | + --groups-json groups.json \ |
| 168 | + --commands-per-group-json $(BUILD_DIR)/.commands-per-group.json \ |
| 169 | + | pandoc -s --to man -o $@ - |
| 170 | + |
| 171 | +.PHONY: install-man uninstall-man |
| 172 | +install-man: man | $(INSTALL_MAN_DIR)/man1 $(INSTALL_MAN_DIR)/man3 $(INSTALL_MAN_DIR)/man4 $(INSTALL_MAN_DIR)/man7 |
| 173 | + cp $(MAN_DIR)/man1/valkey*.1 $(INSTALL_MAN_DIR)/man1/ |
| 174 | + cp $(MAN_DIR)/man3/*.3valkey $(INSTALL_MAN_DIR)/man3/ |
| 175 | + cp $(MAN_DIR)/man4/valkey*.4 $(INSTALL_MAN_DIR)/man4/ |
| 176 | + cp $(MAN_DIR)/man7/valkey*.7 $(INSTALL_MAN_DIR)/man7/ |
| 177 | + |
| 178 | +$(INSTALL_MAN_DIR)/man1 $(INSTALL_MAN_DIR)/man3 $(INSTALL_MAN_DIR)/man4 $(INSTALL_MAN_DIR)/man7: |
| 179 | + mkdir -p $@ |
| 180 | + |
| 181 | +uninstall-man: |
| 182 | + rm $(INSTALL_MAN_DIR)/man1/valkey*.1 |
| 183 | + rm $(INSTALL_MAN_DIR)/man3/*.3valkey |
| 184 | + rm $(INSTALL_MAN_DIR)/man4/valkey*.4 |
| 185 | + rm $(INSTALL_MAN_DIR)/man7/valkey*.7 |
| 186 | + |
| 187 | +# ------- |
| 188 | + |
| 189 | +# All targets |
| 190 | +targets = $(man_targets) $(html_targets) $(md_targets) |
| 191 | + |
| 192 | +md: $(md_targets) |
| 193 | + |
| 194 | +html: $(html_targets) |
| 195 | + |
| 196 | +man: $(man_targets) |
| 197 | + |
| 198 | +clean: |
| 199 | + rm -f $(targets) $(BUILD_DIR)/.commands-per-group.json |
| 200 | +distclean: |
| 201 | + rm -rf $(BUILD_DIR) |
| 202 | + |
| 203 | +install: install-man |
| 204 | + |
| 205 | +uninstall: uninstall-man |
0 commit comments