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