File: Makefile

package info (click to toggle)
mercurial 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,080 kB
  • sloc: python: 208,589; ansic: 56,460; tcl: 3,715; sh: 1,839; lisp: 1,483; cpp: 864; makefile: 769; javascript: 649; xml: 36
file content (227 lines) | stat: -rw-r--r-- 7,538 bytes parent folder | download | duplicates (2)
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
SOURCES=$(notdir $(wildcard ../mercurial/helptext/*.[0-9].txt))
MAN=$(SOURCES:%.txt=%)
HTML=$(SOURCES:%.txt=%.html)
GENDOC=gendoc.py ../mercurial/commands.py ../mercurial/help.py \
	../mercurial/helptext/*.txt ../hgext/*.py ../hgext/*/__init__.py
RUNRST=runrst
PREFIX=/usr/local
MANDIR=$(PREFIX)/share/man
INSTALL=install -m 644
# Default to Python 3.
#
# Windows ships Python 3 as `python.exe`, which may not be on PATH.  py.exe is.
ifeq ($(OS),Windows_NT)
PYTHON?=py -3
else
PYTHON?=python3
endif

RSTARGS=
GENDOCARGS=
GENDOCCMD=$(PYTHON) gendoc.py $(GENDOCARGS)

# Output directories for individual help pages.
MANOUT=man
HTMLOUT=html
BUILDDIR=build

export HGENCODING=UTF-8

.PHONY: all
all: man html

# Generate a list of hg commands and extensions.
commandlist.txt: $(GENDOC)
	${GENDOCCMD} commandlist > $@.tmp
	mv $@.tmp $@

topiclist.txt: $(GENDOC)
	${GENDOCCMD} topiclist > $@.tmp
	mv $@.tmp $@

extensionlist.txt: $(GENDOC)
	${GENDOCCMD} extensionlist > $@.tmp
	mv $@.tmp $@

# Build target for running runrst more easily by hand
.PHONY: knownrefs
knownrefs: commandlist.txt topiclist.txt extensionlist.txt

BUILDFILES=commandlist.txt topiclist.txt extensionlist.txt

# We want to generate a sub-Makefile that can build the RST/man/html doc for
# each hg command. Here are templates that we'll use to generate this
# sub-Makefile.
HGCMDTPL=templates/cmdheader.txt
TOPICTPL=templates/topicheader.txt
EXTTPL=templates/extheader.txt

define RuleAllCommandsTemplate
HG_COMMANDS=$(1)
.PHONY: all-commands
all-commands: $$(HG_COMMANDS:%=$$(BUILDDIR)/hg-%.gendoc.txt)
endef

define RuleAllTopicsTemplate
HG_TOPICS=$(1)
.PHONY: all-topics
all-topics: $$(HG_TOPICS:%=$$(BUILDDIR)/%.gendoc.txt)
endef

define RuleAllExtensionsTemplate
HG_EXTENSIONS=$(1)
.PHONY: all-extensions
all-extensions: $$(HG_EXTENSIONS:%=$$(BUILDDIR)/%.gendoc.txt)
endef

define RuleCommandTemplate
$$(BUILDDIR)/hg-$C.gendoc.txt: $$(GENDOC) $$(HGCMDTPL)
	mkdir -p $$(@D)
	$${GENDOCCMD} cmd-$C > $$@.tmp
	mv $$@.tmp $$@
endef

define RuleTopicTemplate
$$(BUILDDIR)/topic-$T.gendoc.txt: $$(GENDOC) $$(TOPICTPL)
	mkdir -p $$(@D)
	$${GENDOCCMD} topic-$T > $$@.tmp
	mv $$@.tmp $$@
endef

define RuleExtensionTemplate
$$(BUILDDIR)/ext-$E.gendoc.txt: $$(GENDOC) $$(EXTTPL)
	mkdir -p $$(@D)
	$${GENDOCCMD} ext-$E > $$@.tmp
	mv $$@.tmp $$@
endef

# Actually generate the sub-Makefile.
# The $file function is only supported by GNU Make 4 and above.
CommandsTopicsExtensions.mk: commandlist.txt topiclist.txt extensionlist.txt Makefile
ifeq (4.0,$(firstword $(sort $(MAKE_VERSION) 4.0)))
	$(file > $@.tmp,# Generated by Makefile)
	$(file >> $@.tmp,$(call RuleAllCommandsTemplate,$(file < commandlist.txt)))
	$(file >> $@.tmp,$(call RuleAllTopicsTemplate,$(file < topiclist.txt)))
	$(file >> $@.tmp,$(call RuleAllExtensionsTemplate,$(file < extensionlist.txt)))
	$(foreach C,$(file < commandlist.txt),$(file >> $@.tmp,$(RuleCommandTemplate)))
	$(foreach T,$(file < topiclist.txt),$(file >> $@.tmp,$(RuleTopicTemplate)))
	$(foreach E,$(file < extensionlist.txt),$(file >> $@.tmp,$(RuleExtensionTemplate)))
	mv $@.tmp $@
else
	@echo "You are running make ${MAKE_VERSION} but you need make 4.0 or above"
endif

BUILDFILES+=CommandsTopicsExtensions.mk

# Include the sub-Makefile that contains rules for generating each individual
# command/help-topic/extension help page. This sub-Makefile is created by the
# rule above (CommandsTopicsExtensions.mk) which in turn is created from the
# plain-text lists of commands/help-topics/extensions.
#
# Any time the source code changes, these plain-text lists and this
# sub-Makefile will get regenerated. Make will then restart itself to take
# into account the rules inside the sub-Makefile.
#
# We want to avoid doing all this work for targets that we know don't need it
# however. For example, running `make clean` would only generate these files
# in order to delete them immediately. As a result, we don't include the
# sub-Makefile (and therefore don't require generating it) if clean is one of
# the targets. This might not do what we want when other targets are specified
# but it's most likely what we want.
ifeq (,$(filter clean,$(MAKECMDGOALS)))
-include CommandsTopicsExtensions.mk
endif

# If the sub-Makefile is available, add all the hg commands, help-topics, and
# extensions to the list of things to generate html and man pages for.
#
# Naming convention:
# - commands: hg-foo (html and man)
# - help topics: topic-foo (html), hgfoo (man)
# - extensions: ext-foo (html), hgext-foo (man)
#
# Man pages for commands are in section 1 (user commands), topics and
# extensions are in section 7 (miscellanea)
#
# NOTE: topics and extension are temporarily disabled for man pages because
# they make docutils' RST converter crash.
ifdef HG_COMMANDS
HTML+=$(HG_COMMANDS:%=$(HTMLOUT)/hg-%.html)
MAN+=$(HG_COMMANDS:%=$(MANOUT)/hg-%.1)
endif

ifdef HG_TOPICS
HTML+=$(HG_TOPICS:%=$(HTMLOUT)/topic-%.html)
#MAN+=$(HG_TOPICS:%=$(MANOUT)/hg%.7)
endif

ifdef HG_EXTENSIONS
HTML+=$(HG_EXTENSIONS:%=$(HTMLOUT)/ext-%.html)
#MAN+=$(HG_EXTENSIONS:%=$(MANOUT)/hgext-%.7)
endif

# Also add the HTML index page
HTML+=$(HTMLOUT)/index.html

.PHONY: man
man: $(MAN)

.PHONY: html
html: $(HTML)

# This logic is duplicated in setup.py:hgbuilddoc()
common.txt $(SOURCES) $(SOURCES:%.txt=%.gendoc.txt): $(GENDOC)
	${GENDOCCMD} "$(basename $@)" > $@.tmp
	mv $@.tmp $@

%: %.txt %.gendoc.txt common.txt $(RUNRST)
	$(PYTHON) runrst hgmanpage $(RSTARGS) --halt warning \
	  --strip-elements-with-class htmlonly $*.txt $*

%.html: %.txt %.gendoc.txt common.txt $(RUNRST)
	$(PYTHON) runrst html $(RSTARGS) --halt warning \
	  --link-stylesheet --stylesheet-path style.css $*.txt $*.html

# Rules for index page and individual command/help-topic/extension pages
# Because the naming isn't the same between html and man pages, we need to
# break down man pages rules a bit more.
$(BUILDDIR)/index.gendoc.txt: $(GENDOC)
	mkdir -p $(@D)
	${GENDOCCMD} index > $@.tmp
	mv $@.tmp $@

$(MANOUT)/hg-%.1: $(BUILDDIR)/hg-%.gendoc.txt common.txt $(RUNRST)
	mkdir -p $(@D)
	$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \
	  --strip-elements-with-class htmlonly $(BUILDDIR)/hg-$*.gendoc.txt $@

$(MANOUT)/hg%.7: $(BUILDDIR)/topic-%.gendoc.txt common.txt $(RUNRST)
	mkdir -p $(@D)
	$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \
	  --strip-elements-with-class htmlonly $(BUILDDIR)/topic-$*.gendoc.txt $@

$(MANOUT)/hgext-%.7: $(BUILDDIR)/ext-%.gendoc.txt common.txt $(RUNRST)
	mkdir -p $(@D)
	$(PYTHON) runrst hgmanpage --hg-individual-pages $(RSTARGS) --halt warning \
	  --strip-elements-with-class htmlonly $(BUILDDIR)/ext-$*.gendoc.txt $@

$(HTMLOUT)/%.html: $(BUILDDIR)/%.gendoc.txt common.txt $(RUNRST)
	mkdir -p $(@D)
	$(PYTHON) runrst html --hg-individual-pages $(RSTARGS) --halt warning \
	  --link-stylesheet --stylesheet-path style.css $(BUILDDIR)/$*.gendoc.txt $@

.PHONY: install
install: man html
	for i in $(MAN) ; do \
	  subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \
	  mkdir -p "$(DESTDIR)$(MANDIR)"/$$subdir ; \
	  $(INSTALL) $$i "$(DESTDIR)$(MANDIR)"/$$subdir ; \
	done

# The clean target explicitly doesn't bother with the sub-Makefile, so we don't
# know anything about all the command/topic/extension targets and files.
# $(HTML) only has the basic topics, so we need to delete $(HTMLOUT)/*.html and
# other similar files "by hand" here.
.PHONY: clean
clean:
	$(RM) $(MAN) $(HTML) common.txt $(SOURCES) *.gendoc.txt $(BUILDFILES) $(BUILDDIR)/*.gendoc.* $(HTMLOUT)/*.html