Skip to content

Commit a38edab

Browse files
pks-tgitster
authored andcommitted
Makefile: generate doc versions via GIT-VERSION-GEN
The documentation we generate embeds information for the exact Git version used as well as the date of the commit. This information is injected by injecting attributes into the build process via command line argument. Refactor the logic so that we write the information into "asciidoc.conf" and "asciidoctor-extensions.rb" via `GIT-VERSION-GEN` for AsciiDoc and AsciiDoctor, respectively. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9bb10d2 commit a38edab

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

Documentation/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ tmp-doc-diff/
1515
GIT-ASCIIDOCFLAGS
1616
/.build/
1717
/GIT-EXCLUDED-PROGRAMS
18+
/asciidoc.conf
19+
/asciidoctor-extensions.rb

Documentation/Makefile

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Import tree-wide shared Makefile behavior and libraries
22
include ../shared.mak
33

4+
.PHONY: FORCE
5+
46
# Guard against environment variables
57
MAN1_TXT =
68
MAN5_TXT =
@@ -148,16 +150,12 @@ man5dir = $(mandir)/man5
148150
man7dir = $(mandir)/man7
149151
# DESTDIR =
150152

151-
GIT_DATE := $(shell git show --quiet --pretty='%as')
152-
153153
ASCIIDOC = asciidoc
154154
ASCIIDOC_EXTRA =
155155
ASCIIDOC_HTML = xhtml11
156156
ASCIIDOC_DOCBOOK = docbook
157157
ASCIIDOC_CONF = -f asciidoc.conf
158-
ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF) \
159-
-amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' \
160-
-arevdate='$(GIT_DATE)'
158+
ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF)
161159
ASCIIDOC_DEPS = asciidoc.conf GIT-ASCIIDOCFLAGS
162160
TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)
163161
TXT_TO_XML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_DOCBOOK)
@@ -210,6 +208,14 @@ ASCIIDOC_DEPS = asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS
210208
DBLATEX_COMMON =
211209
XMLTO_EXTRA += --skip-validation
212210
XMLTO_EXTRA += -x manpage.xsl
211+
212+
asciidoctor-extensions.rb: asciidoctor-extensions.rb.in FORCE
213+
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
214+
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
215+
else
216+
asciidoc.conf: asciidoc.conf.in FORCE
217+
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
218+
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
213219
endif
214220

215221
ASCIIDOC_DEPS += docinfo.html
@@ -341,6 +347,7 @@ clean:
341347
$(RM) SubmittingPatches.txt
342348
$(RM) $(cmds_txt) $(mergetools_txt) *.made
343349
$(RM) GIT-ASCIIDOCFLAGS
350+
$(RM) asciidoc.conf asciidoctor-extensions.rb
344351

345352
docinfo.html: docinfo-html.in
346353
$(QUIET_GEN)$(RM) $@ && cat $< >$@
@@ -364,7 +371,7 @@ manpage-cmd = $(QUIET_XMLTO)$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
364371
%.xml : %.txt $(ASCIIDOC_DEPS)
365372
$(QUIET_ASCIIDOC)$(TXT_TO_XML) -d manpage -o $@ $<
366373

367-
user-manual.xml: user-manual.txt user-manual.conf asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS
374+
user-manual.xml: user-manual.txt user-manual.conf $(ASCIIDOC_DEPS)
368375
$(QUIET_ASCIIDOC)$(TXT_TO_XML) -d book -o $@ $<
369376

370377
technical/api-index.txt: technical/api-index-skel.txt \
@@ -373,7 +380,7 @@ technical/api-index.txt: technical/api-index-skel.txt \
373380

374381
technical/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../
375382
$(patsubst %,%.html,$(API_DOCS) technical/api-index $(TECH_DOCS)): %.html : %.txt \
376-
asciidoc.conf GIT-ASCIIDOCFLAGS
383+
$(ASCIIDOC_DEPS)
377384
$(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt
378385

379386
SubmittingPatches.txt: SubmittingPatches
@@ -416,13 +423,13 @@ $(patsubst %.txt,%.texi,$(MAN_TXT)): %.texi : %.xml
416423
howto-index.txt: howto-index.sh $(HOWTO_TXT)
417424
$(QUIET_GEN)'$(SHELL_PATH_SQ)' ./howto-index.sh $(sort $(HOWTO_TXT)) >$@
418425

419-
$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt
426+
$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt $(ASCIIDOC_DEPS)
420427
$(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt
421428

422429
WEBDOC_DEST = /pub/software/scm/git/docs
423430

424431
howto/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../
425-
$(patsubst %.txt,%.html,$(HOWTO_TXT)): %.html : %.txt GIT-ASCIIDOCFLAGS
432+
$(patsubst %.txt,%.html,$(HOWTO_TXT)): %.html : %.txt $(ASCIIDOC_DEPS)
426433
$(QUIET_ASCIIDOC) \
427434
sed -e '1,/^$$/d' $< | \
428435
$(TXT_TO_HTML) - >$@

Documentation/asciidoc.conf renamed to Documentation/asciidoc.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ tilde=&#126;
2121
apostrophe=&#39;
2222
backtick=&#96;
2323
litdd=&#45;&#45;
24+
manmanual='Git Manual'
25+
mansource='Git @GIT_VERSION@'
26+
revdate='@GIT_DATE@'
2427

2528
ifdef::backend-docbook[]
2629
[linkgit-inlinemacro]

Documentation/asciidoctor-extensions.rb renamed to Documentation/asciidoctor-extensions.rb.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ def process(parent, target, attrs)
2929
class DocumentPostProcessor < Asciidoctor::Extensions::Postprocessor
3030
def process document, output
3131
if document.basebackend? 'docbook'
32-
mansource = document.attributes['mansource']
33-
manversion = document.attributes['manversion']
34-
manmanual = document.attributes['manmanual']
3532
new_tags = "" \
36-
"<refmiscinfo class=\"source\">#{mansource}</refmiscinfo>\n" \
37-
"<refmiscinfo class=\"version\">#{manversion}</refmiscinfo>\n" \
38-
"<refmiscinfo class=\"manual\">#{manmanual}</refmiscinfo>\n"
33+
"<refmiscinfo class=\"source\">@GIT_VERSION@</refmiscinfo>\n" \
34+
"<refmiscinfo class=\"manual\">Git Manual</refmiscinfo>\n"
3935
output = output.sub(/<\/refmeta>/, new_tags + "</refmeta>")
4036
end
4137
output

GIT-VERSION-GEN

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fi
5353

5454
GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
5555
GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
56+
GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
5657
if test -z "$GIT_USER_AGENT"
5758
then
5859
GIT_USER_AGENT="git/$GIT_VERSION"
@@ -72,6 +73,7 @@ sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
7273
-e "s|@GIT_PATCH_LEVEL@|$GIT_PATCH_LEVEL|" \
7374
-e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
7475
-e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
76+
-e "s|@GIT_DATE@|$GIT_DATE|" \
7577
"$INPUT" >"$OUTPUT"+
7678

7779
if ! test -f "$OUTPUT" || ! cmp "$OUTPUT"+ "$OUTPUT" >/dev/null

0 commit comments

Comments
 (0)