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