xref: /OK3568_Linux_fs/buildroot/package/doc-asciidoc.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# we can't use suitable-host-package here because that's not available in
2*4882a593Smuzhiyun# the context of 'make release'
3*4882a593Smuzhiyun.PHONY: asciidoc-check-dependencies
4*4882a593Smuzhiyunasciidoc-check-dependencies:
5*4882a593Smuzhiyun	$(Q)if [ -z "$(shell support/dependencies/check-host-asciidoc.sh)" ]; then \
6*4882a593Smuzhiyun		echo "You need a sufficiently recent asciidoc on your host" \
7*4882a593Smuzhiyun			"to generate documents"; \
8*4882a593Smuzhiyun		exit 1; \
9*4882a593Smuzhiyun	fi
10*4882a593Smuzhiyun	$(Q)if [ -z "`which w3m 2>/dev/null`" ]; then \
11*4882a593Smuzhiyun		echo "You need w3m on your host to generate documents"; \
12*4882a593Smuzhiyun		exit 1; \
13*4882a593Smuzhiyun	fi
14*4882a593Smuzhiyun
15*4882a593Smuzhiyunasciidoc-check-dependencies-pdf:
16*4882a593Smuzhiyun	$(Q)if [ -z "`which dblatex 2>/dev/null`" ]; then \
17*4882a593Smuzhiyun		echo "You need dblatex on your host to generate PDF documents"; \
18*4882a593Smuzhiyun		exit 1; \
19*4882a593Smuzhiyun	fi
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun# PDF generation is broken because of a bug in xsltproc program provided
22*4882a593Smuzhiyun# by libxslt <=1.1.28, which does not honor an option we need to set.
23*4882a593Smuzhiyun# Fortunately, this bug is already fixed upstream:
24*4882a593Smuzhiyun#   https://gitorious.org/libxslt/libxslt/commit/5af7ad745323004984287e48b42712e7305de35c
25*4882a593Smuzhiyun#
26*4882a593Smuzhiyun# So, bail out when trying to build a PDF using a buggy version of the
27*4882a593Smuzhiyun# xsltproc program.
28*4882a593Smuzhiyun#
29*4882a593Smuzhiyun# So, to overcome this issue and being able to build a PDF, you can
30*4882a593Smuzhiyun# build xsltproc from its source repository, then run:
31*4882a593Smuzhiyun#   $ PATH=/path/to/custom-xsltproc/bin:${PATH} make manual
32*4882a593SmuzhiyunGENDOC_XSLTPROC_IS_BROKEN = \
33*4882a593Smuzhiyun	$(shell xsltproc --maxvars 0 >/dev/null 2>/dev/null || echo y)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun# Apply this configuration to all documents
36*4882a593SmuzhiyunBR_ASCIIDOC_CONF = docs/conf/asciidoc.conf
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun################################################################################
39*4882a593Smuzhiyun# ASCIIDOC_INNER -- generates the make targets needed to build a specific type of
40*4882a593Smuzhiyun#                   asciidoc documentation.
41*4882a593Smuzhiyun#
42*4882a593Smuzhiyun#  argument 1 is the name of the document and the top-level asciidoc file must
43*4882a593Smuzhiyun#             have the same name
44*4882a593Smuzhiyun#  argument 2 is the uppercase name of the document
45*4882a593Smuzhiyun#  argument 3 is the directory containing the document
46*4882a593Smuzhiyun#  argument 4 is the type of document to generate (-f argument of a2x)
47*4882a593Smuzhiyun#  argument 5 is the document type as used in the make target
48*4882a593Smuzhiyun#  argument 6 is the output file extension for the document type
49*4882a593Smuzhiyun#  argument 7 is the human text for the document type
50*4882a593Smuzhiyun#  argument 8 (optional) are extra arguments for a2x
51*4882a593Smuzhiyun#
52*4882a593Smuzhiyun# The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
53*4882a593Smuzhiyun#
54*4882a593Smuzhiyun# Since this function will be called from within an $(eval ...)
55*4882a593Smuzhiyun# all variable references except the arguments must be $$-quoted.
56*4882a593Smuzhiyun################################################################################
57*4882a593Smuzhiyundefine ASCIIDOC_INNER
58*4882a593Smuzhiyun$(1): $(1)-$(5)
59*4882a593Smuzhiyun.PHONY: $(1)-$(5)
60*4882a593Smuzhiyun$(1)-$(5): $$(O)/docs/$(1)/$(1).$(6)
61*4882a593Smuzhiyun
62*4882a593Smuzhiyunasciidoc-check-dependencies-$(5):
63*4882a593Smuzhiyun.PHONY: $(1)-check-dependencies-$(5)
64*4882a593Smuzhiyun# Single line, because splitting a foreach is not easy...
65*4882a593Smuzhiyun$(1)-check-dependencies-$(5): asciidoc-check-dependencies-$(5)
66*4882a593Smuzhiyun	$$(Q)$$(foreach hook,$$($(2)_CHECK_DEPENDENCIES_$$(call UPPERCASE,$(5))_HOOKS),$$(call $$(hook))$$(sep))
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun# Include Buildroot's AsciiDoc configuration first:
69*4882a593Smuzhiyun#  - generic configuration,
70*4882a593Smuzhiyun#  - then output-specific configuration
71*4882a593Smuzhiyunifneq ($$(wildcard $$(BR_ASCIIDOC_CONF)),)
72*4882a593Smuzhiyun$(2)_$(4)_ASCIIDOC_OPTS += -f $$(BR_ASCIIDOC_CONF)
73*4882a593Smuzhiyunendif
74*4882a593SmuzhiyunBR_$(4)_ASCIIDOC_CONF = docs/conf/asciidoc-$(4).conf
75*4882a593Smuzhiyunifneq ($$(wildcard $$(BR_$(4)_ASCIIDOC_CONF)),)
76*4882a593Smuzhiyun$(2)_$(4)_ASCIIDOC_OPTS += -f $$(BR_$(4)_ASCIIDOC_CONF)
77*4882a593Smuzhiyunendif
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun# Then include the document's AsciiDoc configuration:
80*4882a593Smuzhiyun#  - generic configuration,
81*4882a593Smuzhiyun#  - then output-specific configuration
82*4882a593Smuzhiyunifneq ($$(wildcard $$($(2)_ASCIIDOC_CONF)),)
83*4882a593Smuzhiyun$(2)_$(4)_ASCIIDOC_OPTS += -f $$($(2)_ASCIIDOC_CONF)
84*4882a593Smuzhiyunendif
85*4882a593Smuzhiyun$(2)_$(4)_ASCIIDOC_CONF = $(3)/asciidoc-$(4).conf
86*4882a593Smuzhiyunifneq ($$(wildcard $$($(2)_$(4)_ASCIIDOC_CONF)),)
87*4882a593Smuzhiyun$(2)_$(4)_ASCIIDOC_OPTS += -f $$($(2)_$(4)_ASCIIDOC_CONF)
88*4882a593Smuzhiyunendif
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun# Handle a2x warning about --destination-dir option only applicable to HTML
91*4882a593Smuzhiyun# based outputs. So:
92*4882a593Smuzhiyun# - use the --destination-dir option if possible (html and split-html),
93*4882a593Smuzhiyun# - otherwise copy the generated document to the output directory
94*4882a593Smuzhiyun$(2)_$(4)_A2X_OPTS =
95*4882a593Smuzhiyunifneq ($$(filter $(5),html split-html),)
96*4882a593Smuzhiyun$(2)_$(4)_A2X_OPTS += --destination-dir="$$(@D)"
97*4882a593Smuzhiyunelse
98*4882a593Smuzhiyundefine $(2)_$(4)_INSTALL_CMDS
99*4882a593Smuzhiyun	$$(Q)cp -f $$(BUILD_DIR)/docs/$(1)/$(1).$(6) $$(@D)
100*4882a593Smuzhiyunendef
101*4882a593Smuzhiyunendif
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun$$(O)/docs/$(1)/$(1).$(6): export TZ=UTC
104*4882a593Smuzhiyun
105*4882a593Smuzhiyunifeq ($(6)-$$(GENDOC_XSLTPROC_IS_BROKEN),pdf-y)
106*4882a593Smuzhiyun$$(O)/docs/$(1)/$(1).$(6):
107*4882a593Smuzhiyun	$$(warning PDF generation is disabled because of a bug in \
108*4882a593Smuzhiyun		xsltproc. To be able to generate a PDF, you should \
109*4882a593Smuzhiyun		build xsltproc from the libxslt sources >=1.1.29 and pass it \
110*4882a593Smuzhiyun		to make through the command line: \
111*4882a593Smuzhiyun		'PATH=/path/to/custom-xsltproc/bin:$$$${PATH} make $(1)-pdf')
112*4882a593Smuzhiyunelse
113*4882a593Smuzhiyun# -r $(@D) is there for documents that use external filters; those filters
114*4882a593Smuzhiyun# generate code at the same location it finds the document's source files.
115*4882a593Smuzhiyun$$(O)/docs/$(1)/$(1).$(6): $$($(2)_SOURCES) \
116*4882a593Smuzhiyun			   $(1)-check-dependencies \
117*4882a593Smuzhiyun			   $(1)-check-dependencies-$(5) \
118*4882a593Smuzhiyun			   $(1)-prepare-sources
119*4882a593Smuzhiyun	$$(Q)$$(call MESSAGE,"Generating $(7) $(1)...")
120*4882a593Smuzhiyun	$$(Q)mkdir -p $$(@D)
121*4882a593Smuzhiyun	$$(Q)a2x $(8) -f $(4) -d book -L \
122*4882a593Smuzhiyun		$$(foreach r,$$($(2)_RESOURCES) $$(@D), \
123*4882a593Smuzhiyun			--resource="$$(abspath $$(r))") \
124*4882a593Smuzhiyun		$$($(2)_$(4)_A2X_OPTS) \
125*4882a593Smuzhiyun		--asciidoc-opts="$$($(2)_$(4)_ASCIIDOC_OPTS)" \
126*4882a593Smuzhiyun		$$(BUILD_DIR)/docs/$(1)/$(1).txt
127*4882a593Smuzhiyun# install the generated document
128*4882a593Smuzhiyun	$$($(2)_$(4)_INSTALL_CMDS)
129*4882a593Smuzhiyunendif
130*4882a593Smuzhiyunendef
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun################################################################################
133*4882a593Smuzhiyun# ASCIIDOC -- generates the make targets needed to build asciidoc documentation.
134*4882a593Smuzhiyun#
135*4882a593Smuzhiyun# argument 1 is the lowercase name of the document; the document's main file
136*4882a593Smuzhiyun#            must have the same name, with the .txt extension
137*4882a593Smuzhiyun# argument 2 is the uppercase name of the document
138*4882a593Smuzhiyun# argument 3 is the directory containing the document's sources
139*4882a593Smuzhiyun#
140*4882a593Smuzhiyun# The variable <DOCUMENT_NAME>_SOURCES defines the dependencies.
141*4882a593Smuzhiyun# The variable <DOCUMENT_NAME>_RESOURCES defines where the document's
142*4882a593Smuzhiyun# resources, such as images, are located; must be an absolute path.
143*4882a593Smuzhiyun################################################################################
144*4882a593Smuzhiyundefine ASCIIDOC
145*4882a593Smuzhiyun# Single line, because splitting a foreach is not easy...
146*4882a593Smuzhiyun.PHONY: $(1)-check-dependencies
147*4882a593Smuzhiyun$(1)-check-dependencies: asciidoc-check-dependencies $$($(2)_DEPENDENCIES)
148*4882a593Smuzhiyun	$$(Q)$$(foreach hook,$$($(2)_CHECK_DEPENDENCIES_HOOKS),$$(call $$(hook))$$(sep))
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun# Single line, because splitting a foreach is not easy...
151*4882a593Smuzhiyun# Do not touch the stamp file, so we get to rsync again every time we build
152*4882a593Smuzhiyun# the document.
153*4882a593Smuzhiyun$$(BUILD_DIR)/docs/$(1)/.stamp_doc_rsynced:
154*4882a593Smuzhiyun	$$(Q)$$(call MESSAGE,"Preparing the $(1) sources...")
155*4882a593Smuzhiyun	$$(Q)mkdir -p $$(@D)
156*4882a593Smuzhiyun	$$(Q)rsync -a $(3) $$(@D)
157*4882a593Smuzhiyun	$$(Q)$$(foreach hook,$$($(2)_POST_RSYNC_HOOKS),$$(call $$(hook))$$(sep))
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun.PHONY: $(1)-prepare-sources
160*4882a593Smuzhiyun$(1)-prepare-sources: $$(BUILD_DIR)/docs/$(1)/.stamp_doc_rsynced
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun$(2)_ASCIIDOC_CONF = $(3)/asciidoc.conf
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun$(call ASCIIDOC_INNER,$(1),$(2),$(3),xhtml,html,html,HTML,\
165*4882a593Smuzhiyun	--xsltproc-opts "--stringparam toc.section.depth 1")
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun$(call ASCIIDOC_INNER,$(1),$(2),$(3),chunked,split-html,chunked,split HTML,\
168*4882a593Smuzhiyun	--xsltproc-opts "--stringparam toc.section.depth 1")
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun# dblatex needs to pass the '--maxvars ...' option to xsltproc to prevent it
171*4882a593Smuzhiyun# from reaching the template recursion limit when processing the (long) target
172*4882a593Smuzhiyun# package table and bailing out.
173*4882a593Smuzhiyun$(call ASCIIDOC_INNER,$(1),$(2),$(3),pdf,pdf,pdf,PDF,\
174*4882a593Smuzhiyun	--dblatex-opts "-P latex.output.revhistory=0 -x '--maxvars 100000'")
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun$(call ASCIIDOC_INNER,$(1),$(2),$(3),text,text,text,text)
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun$(call ASCIIDOC_INNER,$(1),$(2),$(3),epub,epub,epub,ePUB)
179*4882a593Smuzhiyun
180*4882a593Smuzhiyunclean: $(1)-clean
181*4882a593Smuzhiyun$(1)-clean:
182*4882a593Smuzhiyun	$$(Q)$$(RM) -rf $$(BUILD_DIR)/docs/$(1)
183*4882a593Smuzhiyun.PHONY: $(1) $(1)-clean
184*4882a593Smuzhiyunendef
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun################################################################################
187*4882a593Smuzhiyun# asciidoc-document -- the target generator macro for asciidoc documents
188*4882a593Smuzhiyun################################################################################
189*4882a593Smuzhiyun
190*4882a593Smuzhiyunasciidoc-document = $(call ASCIIDOC,$(pkgname),$(call UPPERCASE,$(pkgname)),$(pkgdir))
191