Home | History | Annotate | Download | only in DocBook
      1 # SPDX-License-Identifier: GPL-2.0
      2 ###
      3 # This makefile is used to generate the kernel documentation,
      4 # primarily based on in-line comments in various source files.
      5 # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
      6 # to document the SRC - and how to read it.
      7 # To add a new book the only step required is to add the book to the
      8 # list of DOCBOOKS.
      9 
     10 DOCBOOKS := efi.xml linker_lists.xml stdio.xml
     11 
     12 ###
     13 # The build process is as follows (targets):
     14 #              (xmldocs) [by docproc]
     15 # file.tmpl --> file.xml +--> file.ps   (psdocs)   [by db2ps or xmlto]
     16 #                        +--> file.pdf  (pdfdocs)  [by db2pdf or xmlto]
     17 #                        +--> DIR=file  (htmldocs) [by xmlto]
     18 #                        +--> man/      (mandocs)  [by xmlto]
     19 
     20 
     21 # for PDF and PS output you can choose between xmlto and docbook-utils tools
     22 PDF_METHOD	= $(prefer-db2x)
     23 PS_METHOD	= $(prefer-db2x)
     24 
     25 
     26 ###
     27 # The targets that may be used.
     28 PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
     29 
     30 targets += $(DOCBOOKS)
     31 BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
     32 xmldocs: $(BOOKS)
     33 sgmldocs: xmldocs
     34 
     35 PS := $(patsubst %.xml, %.ps, $(BOOKS))
     36 psdocs: $(PS)
     37 
     38 PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
     39 pdfdocs: $(PDF)
     40 
     41 HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
     42 htmldocs: $(HTML)
     43 	$(call build_main_index)
     44 	$(call build_images)
     45 	$(call install_media_images)
     46 
     47 MAN := $(patsubst %.xml, %.9, $(BOOKS))
     48 mandocs: $(MAN)
     49 	$(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9)
     50 
     51 installmandocs: mandocs
     52 	mkdir -p /usr/local/man/man9/
     53 	install $(obj)/man/*.9.gz /usr/local/man/man9/
     54 
     55 ###
     56 #External programs used
     57 KERNELDOC = $(srctree)/scripts/kernel-doc
     58 DOCPROC   = $(objtree)/scripts/docproc
     59 
     60 XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
     61 XMLTOFLAGS += --skip-validation
     62 
     63 ###
     64 # DOCPROC is used for two purposes:
     65 # 1) To generate a dependency list for a .tmpl file
     66 # 2) To preprocess a .tmpl file and call kernel-doc with
     67 #     appropriate parameters.
     68 # The following rules are used to generate the .xml documentation
     69 # required to generate the final targets. (ps, pdf, html).
     70 quiet_cmd_docproc = DOCPROC $@
     71       cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
     72 define rule_docproc
     73 	set -e;								\
     74         $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) 	\
     75         $(cmd_$(1)); 							\
     76         ( 								\
     77           echo 'cmd_$@ := $(cmd_$(1))'; 				\
     78           echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; 		\
     79         ) > $(dir $@).$(notdir $@).cmd
     80 endef
     81 
     82 %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE
     83 	$(call if_changed_rule,docproc)
     84 
     85 # Tell kbuild to always build the programs
     86 always := $(hostprogs-y)
     87 
     88 notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
     89 		   exit 1
     90 db2xtemplate = db2TYPE -o $(dir $@) $<
     91 xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
     92 
     93 # determine which methods are available
     94 ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
     95 	use-db2x = db2x
     96 	prefer-db2x = db2x
     97 else
     98 	use-db2x = notfound
     99 	prefer-db2x = $(use-xmlto)
    100 endif
    101 ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
    102 	use-xmlto = xmlto
    103 	prefer-xmlto = xmlto
    104 else
    105 	use-xmlto = notfound
    106 	prefer-xmlto = $(use-db2x)
    107 endif
    108 
    109 # the commands, generated from the chosen template
    110 quiet_cmd_db2ps = PS      $@
    111       cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
    112 %.ps : %.xml
    113 	$(call cmd,db2ps)
    114 
    115 quiet_cmd_db2pdf = PDF     $@
    116       cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
    117 %.pdf : %.xml
    118 	$(call cmd,db2pdf)
    119 
    120 
    121 index = index.html
    122 main_idx = $(obj)/$(index)
    123 build_main_index = rm -rf $(main_idx); \
    124 		   echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \
    125 		   echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \
    126 		   cat $(HTML) >> $(main_idx)
    127 
    128 quiet_cmd_db2html = HTML    $@
    129       cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
    130 		echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
    131 		$(patsubst %.html,%,$(notdir $@))</a><p>' > $@
    132 
    133 %.html:	%.xml
    134 	@(which xmlto > /dev/null 2>&1) || \
    135 	 (echo "*** You need to install xmlto ***"; \
    136 	  exit 1)
    137 	@rm -rf $@ $(patsubst %.html,%,$@)
    138 	$(call cmd,db2html)
    139 	@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
    140             cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
    141 
    142 quiet_cmd_db2man = MAN     $@
    143       cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
    144 %.9 : %.xml
    145 	@(which xmlto > /dev/null 2>&1) || \
    146 	 (echo "*** You need to install xmlto ***"; \
    147 	  exit 1)
    148 	$(Q)mkdir -p $(obj)/man
    149 	$(call cmd,db2man)
    150 	@touch $@
    151 
    152 ###
    153 # Rules to generate postscripts and PNG images from .fig format files
    154 quiet_cmd_fig2eps = FIG2EPS $@
    155       cmd_fig2eps = fig2dev -Leps $< $@
    156 
    157 %.eps: %.fig
    158 	@(which fig2dev > /dev/null 2>&1) || \
    159 	 (echo "*** You need to install transfig ***"; \
    160 	  exit 1)
    161 	$(call cmd,fig2eps)
    162 
    163 quiet_cmd_fig2png = FIG2PNG $@
    164       cmd_fig2png = fig2dev -Lpng $< $@
    165 
    166 %.png: %.fig
    167 	@(which fig2dev > /dev/null 2>&1) || \
    168 	 (echo "*** You need to install transfig ***"; \
    169 	  exit 1)
    170 	$(call cmd,fig2png)
    171 
    172 ###
    173 # Rule to convert a .c file to inline XML documentation
    174        gen_xml = :
    175  quiet_gen_xml = echo '  GEN     $@'
    176 silent_gen_xml = :
    177 %.xml: %.c
    178 	@$($(quiet)gen_xml)
    179 	@(                            \
    180 	   echo "<programlisting>";   \
    181 	   expand --tabs=8 < $< |     \
    182 	   sed -e "s/&/\\&amp;/g"     \
    183 	       -e "s/</\\&lt;/g"      \
    184 	       -e "s/>/\\&gt;/g";     \
    185 	   echo "</programlisting>")  > $@
    186 
    187 ###
    188 # Help targets as used by the top-level makefile
    189 dochelp:
    190 	@echo  ' U-Boot bootloader internal documentation in different formats:'
    191 	@echo  '  htmldocs        - HTML'
    192 	@echo  '  pdfdocs         - PDF'
    193 	@echo  '  psdocs          - Postscript'
    194 	@echo  '  xmldocs         - XML DocBook'
    195 	@echo  '  mandocs         - man pages'
    196 	@echo  '  installmandocs  - install man pages generated by mandocs'
    197 	@echo  '  cleandocs       - clean all generated DocBook files'
    198 
    199 ###
    200 # Temporary files left by various tools
    201 clean-files := $(DOCBOOKS) \
    202 	$(patsubst %.xml, %.dvi,  $(DOCBOOKS)) \
    203 	$(patsubst %.xml, %.aux,  $(DOCBOOKS)) \
    204 	$(patsubst %.xml, %.tex,  $(DOCBOOKS)) \
    205 	$(patsubst %.xml, %.log,  $(DOCBOOKS)) \
    206 	$(patsubst %.xml, %.out,  $(DOCBOOKS)) \
    207 	$(patsubst %.xml, %.ps,   $(DOCBOOKS)) \
    208 	$(patsubst %.xml, %.pdf,  $(DOCBOOKS)) \
    209 	$(patsubst %.xml, %.html, $(DOCBOOKS)) \
    210 	$(patsubst %.xml, %.9,    $(DOCBOOKS)) \
    211 	$(index)
    212 
    213 clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
    214 
    215 cleandocs:
    216 	$(Q)rm -f $(call objectify, $(clean-files))
    217 	$(Q)rm -rf $(call objectify, $(clean-dirs))
    218 
    219 # Declare the contents of the .PHONY variable as phony.  We keep that
    220 # information in a variable se we can use it in if_changed and friends.
    221 
    222 .PHONY: $(PHONY)
    223