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