Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 2 | ### |
| 3 | # This makefile is used to generate the kernel documentation, |
| 4 | # primarily based on in-line comments in various source files. |
Masahiro Yamada | 5bfd11b | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 5 | # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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 | |
Masahiro Yamada | b9f9ce4 | 2014-02-05 10:52:52 +0900 | [diff] [blame] | 10 | DOCBOOKS := linker_lists.xml stdio.xml |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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. |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 28 | PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 29 | |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 30 | targets += $(DOCBOOKS) |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 31 | BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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) |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 49 | $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 50 | |
| 51 | installmandocs: mandocs |
| 52 | mkdir -p /usr/local/man/man9/ |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 53 | install $(obj)/man/*.9.gz /usr/local/man/man9/ |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 54 | |
| 55 | ### |
| 56 | #External programs used |
Masahiro Yamada | 5bfd11b | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 57 | KERNELDOC = $(srctree)/scripts/kernel-doc |
| 58 | DOCPROC = $(objtree)/scripts/docproc |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 59 | |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 60 | XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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). |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 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 |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 81 | |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 82 | %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 83 | $(call if_changed_rule,docproc) |
| 84 | |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 85 | # Tell kbuild to always build the programs |
| 86 | always := $(hostprogs-y) |
| 87 | |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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 |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 113 | $(call cmd,db2ps) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 114 | |
| 115 | quiet_cmd_db2pdf = PDF $@ |
| 116 | cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template)) |
| 117 | %.pdf : %.xml |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 118 | $(call cmd,db2pdf) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 119 | |
| 120 | |
| 121 | index = index.html |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 122 | main_idx = $(obj)/$(index) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 123 | build_main_index = rm -rf $(main_idx); \ |
| 124 | echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \ |
Masahiro Yamada | b91674a | 2014-02-24 11:12:09 +0900 | [diff] [blame] | 125 | echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \ |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 126 | cat $(HTML) >> $(main_idx) |
| 127 | |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 128 | quiet_cmd_db2html = HTML $@ |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 129 | cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \ |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 130 | echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \ |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 131 | $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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,%,$@) |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 138 | $(call cmd,db2html) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 139 | @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 140 | cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 141 | |
| 142 | quiet_cmd_db2man = MAN $@ |
Masahiro Yamada | 9d9ef81 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 143 | cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 144 | %.9 : %.xml |
| 145 | @(which xmlto > /dev/null 2>&1) || \ |
| 146 | (echo "*** You need to install xmlto ***"; \ |
| 147 | exit 1) |
Masahiro Yamada | 59f15f2 | 2014-02-04 17:24:24 +0900 | [diff] [blame] | 148 | $(Q)mkdir -p $(obj)/man |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 149 | $(call cmd,db2man) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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) |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 161 | $(call cmd,fig2eps) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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) |
Masahiro Yamada | 0d68fb1 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 170 | $(call cmd,fig2png) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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/&/\\&/g" \ |
| 183 | -e "s/</\\</g" \ |
| 184 | -e "s/>/\\>/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: |
Masahiro Yamada | 5bfd11b | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 216 | $(Q)rm -f $(call objectify, $(clean-files)) |
| 217 | $(Q)rm -rf $(call objectify, $(clean-dirs)) |
Marek Vasut | 1f747c1 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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) |