| 1 |
SOURCES=$(notdir $(wildcard ../mercurial/helptext/*.[0-9].txt)) |
| 2 |
MAN=$(SOURCES:%.txt=%) |
| 3 |
HTML=$(SOURCES:%.txt=%.html) |
| 4 |
GENDOC=gendoc.py ../mercurial/commands.py ../mercurial/help.py \ |
| 5 |
../mercurial/helptext/*.txt ../hgext/*.py ../hgext/*/__init__.py |
| 6 |
RUNRST=runrst |
| 7 |
PREFIX=/usr/local |
| 8 |
MANDIR=$(PREFIX)/share/man |
| 9 |
INSTALL=install -m 644 |
| 10 |
# Default to Python 3. |
| 11 |
# |
| 12 |
# Windows ships Python 3 as `python.exe`, which may not be on PATH. py.exe is. |
| 13 |
ifeq ($(OS),Windows_NT) |
| 14 |
PYTHON?=py -3 |
| 15 |
else |
| 16 |
PYTHON?=python3 |
| 17 |
endif |
| 18 |
|
| 19 |
RSTARGS= |
| 20 |
GENDOCARGS= |
| 21 |
GENDOCCMD=$(PYTHON) gendoc.py $(GENDOCARGS) |
| 22 |
|
| 23 |
# Output directories for individual help pages. |
| 24 |
MANOUT=man |
| 25 |
HTMLOUT=html |
| 26 |
BUILDDIR=build |
| 27 |
|
| 28 |
export HGENCODING=UTF-8 |
| 29 |
|
| 30 |
.PHONY: all |
| 31 |
all: man html |
| 32 |
|
| 33 |
# Generate a list of hg commands and extensions. |
| 34 |
commandlist.txt: $(GENDOC) |
| 35 |
${GENDOCCMD} commandlist > [email protected] |
| 36 |
mv [email protected] $@ |
| 37 |
|
| 38 |
topiclist.txt: $(GENDOC) |
| 39 |
${GENDOCCMD} topiclist > [email protected] |
| 40 |
mv [email protected] $@ |
| 41 |
|
| 42 |
extensionlist.txt: $(GENDOC) |
| 43 |
${GENDOCCMD} extensionlist > [email protected] |
| 44 |
mv [email protected] $@ |
| 45 |
|
| 46 |
# Build target for running runrst more easily by hand |
| 47 |
.PHONY: knownrefs |
| 48 |
knownrefs: commandlist.txt topiclist.txt extensionlist.txt |
| 49 |
|
| 50 |
BUILDFILES=commandlist.txt topiclist.txt extensionlist.txt |
| 51 |
|
| 52 |
# We want to generate a sub-Makefile that can build the RST/man/html doc for |
| 53 |
# each hg command. Here are templates that we'll use to generate this |
| 54 |
# sub-Makefile. |
| 55 |
HGCMDTPL=templates/cmdheader.txt |
| 56 |
TOPICTPL=templates/topicheader.txt |
| 57 |
EXTTPL=templates/extheader.txt |
| 58 |
|
| 59 |
define RuleAllCommandsTemplate |
| 60 |
HG_COMMANDS=$(1) |
| 61 |
.PHONY: all-commands |
| 62 |
all-commands: $$(HG_COMMANDS:%=$$(BUILDDIR)/hg-%.gendoc.txt) |
| 63 |
endef |
| 64 |
|
| 65 |
define RuleAllTopicsTemplate |
| 66 |
HG_TOPICS=$(1) |
| 67 |
.PHONY: all-topics |
| 68 |
all-topics: $$(HG_TOPICS:%=$$(BUILDDIR)/%.gendoc.txt) |
| 69 |
endef |
| 70 |
|
| 71 |
define RuleAllExtensionsTemplate |
| 72 |
HG_EXTENSIONS=$(1) |
| 73 |
.PHONY: all-extensions |
| 74 |
all-extensions: $$(HG_EXTENSIONS:%=$$(BUILDDIR)/%.gendoc.txt) |
| 75 |
endef |
| 76 |
|
| 77 |
define RuleCommandTemplate |
| 78 |
$$(BUILDDIR)/hg-$C.gendoc.txt: $$(GENDOC) $$(HGCMDTPL) |
| 79 |
mkdir -p $$(@D) |
| 80 |
$${GENDOCCMD} cmd-$C > [email protected] |
| 81 |
mv [email protected] $$@ |
| 82 |
endef |
| 83 |
|
| 84 |
define RuleTopicTemplate |
| 85 |
$$(BUILDDIR)/topic-$T.gendoc.txt: $$(GENDOC) $$(TOPICTPL) |
| 86 |
mkdir -p $$(@D) |
| 87 |
$${GENDOCCMD} topic-$T > [email protected] |
| 88 |
mv [email protected] $$@ |
| 89 |
endef |
| 90 |
|
| 91 |
define RuleExtensionTemplate |
| 92 |
$$(BUILDDIR)/ext-$E.gendoc.txt: $$(GENDOC) $$(EXTTPL) |
| 93 |
mkdir -p $$(@D) |
| 94 |
$${GENDOCCMD} ext-$E > [email protected] |
| 95 |
mv [email protected] $$@ |
| 96 |
endef |
| 97 |
|
| 98 |
# Actually generate the sub-Makefile. |
| 99 |
# The $file function is only supported by GNU Make 4 and above. |
| 100 |
CommandsTopicsExtensions.mk: commandlist.txt topiclist.txt extensionlist.txt Makefile |
| 101 |
ifeq (4.0,$(firstword $(sort $(MAKE_VERSION) 4.0))) |
| 102 |
$(file > [email protected],# Generated by Makefile) |
| 103 |
$(file >> [email protected],$(call RuleAllCommandsTemplate,$(file < commandlist.txt))) |
| 104 |
$(file >> [email protected],$(call RuleAllTopicsTemplate,$(file < topiclist.txt))) |
| 105 |
$(file >> [email protected],$(call RuleAllExtensionsTemplate,$(file < extensionlist.txt))) |
| 106 |
$(foreach C,$(file < commandlist.txt),$(file >> [email protected],$(RuleCommandTemplate))) |
| 107 |
$(foreach T,$(file < topiclist.txt),$(file >> [email protected],$(RuleTopicTemplate))) |
| 108 |
$(foreach E,$(file < extensionlist.txt),$(file >> [email protected],$(RuleExtensionTemplate))) |
| 109 |
mv [email protected] $@ |
| 110 |
else |
| 111 |
@echo "You are running make ${MAKE_VERSION} but you need make 4.0 or above" |
| 112 |
endif |
| 113 |
|
| 114 |
BUILDFILES+=CommandsTopicsExtensions.mk |
| 115 |
|
| 116 |
# Include the sub-Makefile that contains rules for generating each individual |
| 117 |
# command/help-topic/extension help page. This sub-Makefile is created by the |
| 118 |
# rule above (CommandsTopicsExtensions.mk) which in turn is created from the |
| 119 |
# plain-text lists of commands/help-topics/extensions. |
| 120 |
# |
| 121 |
# Any time the source code changes, these plain-text lists and this |
| 122 |
# sub-Makefile will get regenerated. Make will then restart itself to take |
| 123 |
# into account the rules inside the sub-Makefile. |
| 124 |
# |
| 125 |
# We want to avoid doing all this work for targets that we know don't need it |
| 126 |
# however. For example, running `make clean` would only generate these files |
| 127 |
# in order to delete them immediately. As a result, we don't include the |
| 128 |
# sub-Makefile (and therefore don't require generating it) if clean is one of |
| 129 |
# the targets. This might not do what we want when other targets are specified |
| 130 |
# but it's most likely what we want. |
| 131 |
ifeq (,$(filter clean,$(MAKECMDGOALS))) |
| 132 |
-include CommandsTopicsExtensions.mk |
| 133 |
endif |
| 134 |
|
| 135 |
# If the sub-Makefile is available, add all the hg commands, help-topics, and |
| 136 |
# extensions to the list of things to generate html and man pages for. |
| 137 |
# |
| 138 |
# Naming convention: |
| 139 |
# - commands: hg-foo (html and man) |
| 140 |
# - help topics: topic-foo (html), hgfoo (man) |
| 141 |
# - extensions: ext-foo (html), hgext-foo (man) |
| 142 |
# |
| 143 |
# Man pages for commands are in section 1 (user commands), topics and |
| 144 |
# extensions are in section 7 (miscellanea) |
| 145 |
# |
| 146 |
# NOTE: topics and extension are temporarily disabled for man pages because |
| 147 |
# they make docutils' RST converter crash. |
| 148 |
ifdef HG_COMMANDS |
| 149 |
HTML+=$(HG_COMMANDS:%=$(HTMLOUT)/hg-%.html) |
| 150 |
MAN+=$(HG_COMMANDS:%=$(MANOUT)/hg-%.1) |
| 151 |
endif |
| 152 |
|
| 153 |
ifdef HG_TOPICS |
| 154 |
HTML+=$(HG_TOPICS:%=$(HTMLOUT)/topic-%.html) |
| 155 |
#MAN+=$(HG_TOPICS:%=$(MANOUT)/hg%.7) |
| 156 |
endif |
| 157 |
|
| 158 |
ifdef HG_EXTENSIONS |
| 159 |
HTML+=$(HG_EXTENSIONS:%=$(HTMLOUT)/ext-%.html) |
| 160 |
#MAN+=$(HG_EXTENSIONS:%=$(MANOUT)/hgext-%.7) |
| 161 |
endif |
| 162 |
|
| 163 |
# Also add the HTML index page |
| 164 |
HTML+=$(HTMLOUT)/index.html |
| 165 |
|
| 166 |
.PHONY: man |
| 167 |
man: $(MAN) |
| 168 |
|
| 169 |
.PHONY: html |
| 170 |
html: $(HTML) |
| 171 |
|
| 172 |
# This logic is duplicated in setup.py:hgbuilddoc() |
| 173 |
common.txt $(SOURCES) $(SOURCES:%.txt=%.gendoc.txt): $(GENDOC) |
| 174 |
${GENDOCCMD} "$(basename $@)" > [email protected] |
| 175 |
mv [email protected] $@ |
| 176 |
|
| 177 |
%: %.txt %.gendoc.txt common.txt $(RUNRST) |
| 178 |
$(PYTHON) runrst hgmanpage $(RSTARGS) --halt warning \ |
| 179 |
--strip-elements-with-class htmlonly $*.txt $* |
| 180 |
|
| 181 |
%.html: %.txt %.gendoc.txt common.txt $(RUNRST) |
| 182 |
$(PYTHON) runrst html $(RSTARGS) --halt warning \ |
| 183 |
--link-stylesheet --stylesheet-path style.css $*.txt $*.html |
| 184 |
|
| 185 |
# Rules for index page and individual command/help-topic/extension pages |
| 186 |
# Because the naming isn't the same between html and man pages, we need to |
| 187 |
# break down man pages rules a bit more. |
| 188 |
$(BUILDDIR)/index.gendoc.txt: $(GENDOC) |
| 189 |
mkdir -p $(@D) |
| 190 |
${GENDOCCMD} index > [email protected] |
| 191 |
mv [email protected] $@ |
| 192 |
|
| 193 |
$(MANOUT)/hg-%.1: $(BUILDDIR)/hg-%.gendoc.txt common.txt $(RUNRST) |
| 194 |
mkdir -p $(@D) |
| 195 |
$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \ |
| 196 |
--strip-elements-with-class htmlonly $(BUILDDIR)/hg-$*.gendoc.txt $@ |
| 197 |
|
| 198 |
$(MANOUT)/hg%.7: $(BUILDDIR)/topic-%.gendoc.txt common.txt $(RUNRST) |
| 199 |
mkdir -p $(@D) |
| 200 |
$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \ |
| 201 |
--strip-elements-with-class htmlonly $(BUILDDIR)/topic-$*.gendoc.txt $@ |
| 202 |
|
| 203 |
$(MANOUT)/hgext-%.7: $(BUILDDIR)/ext-%.gendoc.txt common.txt $(RUNRST) |
| 204 |
mkdir -p $(@D) |
| 205 |
$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \ |
| 206 |
--strip-elements-with-class htmlonly $(BUILDDIR)/ext-$*.gendoc.txt $@ |
| 207 |
|
| 208 |
$(HTMLOUT)/%.html: $(BUILDDIR)/%.gendoc.txt common.txt $(RUNRST) |
| 209 |
mkdir -p $(@D) |
| 210 |
$(PYTHON) runrst html --hg-individual-pages $(RSTARGS) --halt warning \ |
| 211 |
--link-stylesheet --stylesheet-path style.css $(BUILDDIR)/$*.gendoc.txt $@ |
| 212 |
|
| 213 |
.PHONY: install |
| 214 |
install: man html |
| 215 |
for i in $(MAN) ; do \ |
| 216 |
subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \ |
| 217 |
mkdir -p "$(DESTDIR)$(MANDIR)"/$$subdir ; \ |
| 218 |
$(INSTALL) $$i "$(DESTDIR)$(MANDIR)"/$$subdir ; \ |
| 219 |
done |
| 220 |
|
| 221 |
# The clean target explicitly doesn't bother with the sub-Makefile, so we don't |
| 222 |
# know anything about all the command/topic/extension targets and files. |
| 223 |
# $(HTML) only has the basic topics, so we need to delete $(HTMLOUT)/*.html and |
| 224 |
# other similar files "by hand" here. |
| 225 |
.PHONY: clean |
| 226 |
clean: |
| 227 |
$(RM) $(MAN) $(HTML) common.txt $(SOURCES) *.gendoc.txt $(BUILDFILES) $(BUILDDIR)/*.gendoc.* $(HTMLOUT)/*.html |