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