summaryrefslogtreecommitdiffstats
path: root/build/Makefile.asciidoc.inc
blob: a28a5bb17309d7f0e0900cadffc8233c4032b033 (plain)
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
# USAGE:
#
# - define 'TOPDIR' to point at the git root,
# - define in 'ASCIIDOC' all root .adoc files,
# - optionally define in 'ASCIIDOC_DEPS' all dependencies common to all .adocs,
# - include this file,
# - optionally define further dependencies for individual .pdf targets.
#
# e.g.
#
#     TOPDIR = ..
#     ASCIIDOC = osmo_yada.adoc osmo_moo.adoc
#     ASCIIDOC_DEPS = for_all/*.adoc
#     include $(TOPDIR)/build/Makefile.asciidoc.inc
#     osmo_yada.pdf: yada/*.adoc yada/*.msc

BUILDDIR = $(TOPDIR)/build

GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
GIT_DATE := $(shell $(TOPDIR)/build/unix-time-to-fmt.py `git log -n 1 "--pretty=%at" ../.`)

# prepend the document name with the version numbe suffix
#DOCS_VER = $(foreach P, $(ASCIIDOC_NAME), $(P)-v$(shell xmllint --recover --xpath "//revnumber[position()=last()]/text()" $(P)-docinfo.xml 2>/dev/null))
#PDFS = $(DOCS_VER:%=%.pdf)

# generate list of PDFs that we're supposed to render
ASCIIDOC_NAME = $(patsubst %.adoc,%,$(ASCIIDOC))
ASCIIDOC_PDF = $(ASCIIDOC_NAME:%=%.pdf)
ASCIIDOC_CHECKS = $(ASCIIDOC_NAME:%=%.check)

ASCIIDOCSTYLE ?= $(BUILDDIR)/custom-dblatex.sty

CLEAN_FILES += $(ASCIIDOC_NAME:%=%__*.png) $(ASCIIDOC_NAME:%=%__*.svg) $(ASCIIDOC_CHECKS)
CLEAN_FILES += $(ASCIIDOC_PDF)
UPLOAD_FILES += $(ASCIIDOC_PDF)

ASCIIDOC_OPTS := -f $(BUILDDIR)/mscgen-filter.conf -f $(BUILDDIR)/diag-filter.conf -f $(BUILDDIR)/docinfo-releaseinfo.conf -f $(BUILDDIR)/python2-filter.conf
DBLATEX_OPTS := -s $(ASCIIDOCSTYLE) -P draft.mode=yes -P draft.watermark=0

ifeq (,$(BUILD_RELEASE))
	REVNUMBER := DRAFT $(GIT_VERSION)
else
	REVNUMBER := $(GIT_VERSION)
endif

A2X_OPTS := -L --asciidoc-opts="$(ASCIIDOC_OPTS)" --dblatex-opts="$(DBLATEX_OPTS)" -a docinfo -a revnumber="$(REVNUMBER)" -a revdate="$(GIT_DATE)"


all: $(ASCIIDOC_PDF)

$(ASCIIDOC_PDF): %.pdf: %.adoc %-docinfo.xml \
		$(ASCIIDOC_DEPS) \
		$(ASCIIDOCSTYLE) \
		$(TOPDIR)/common/*/*.adoc \
		$(TOPDIR)/common/images/*
	@test -n "$(BUILD_RELEASE)" && echo -e "\n\n\
	  NOTE: TO REMOVE DRAFT MODE, YOU NEED TO EDIT build/custom-dblatex.sty\n\
	        and remove three lines starting with '% \"DRAFT\" on first page'\n" \
	  || true
	a2x $(A2X_OPTS) $< || asciidoc -v $(ASCIIDOC_OPTS) $<

check: $(ASCIIDOC_CHECKS)

$(ASCIIDOC_CHECKS): %.check: %.adoc %-docinfo.xml $(ASCIIDOCSTYLE) $(TOPDIR)/common/chapters/*.adoc chapters/*.adoc
	asciidoc -v $(ASCIIDOC_OPTS) $< > $@ 2>&1
	# Make absolutely sure that the %.check target is updated.
	touch $@
	# Do print the WARNING output but return error if any was found
	# (grep -v would omit the WARNING output from the log).
	@grep WARNING $@ && exit 1 || exit 0