Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 1 | ### |
| 2 | # This makefile is used to generate the kernel documentation, |
| 3 | # primarily based on in-line comments in various source files. |
Masahiro Yamada | 8fac9c7 | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 4 | # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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. |
Tom Rini | da58dec | 2015-11-10 01:06:16 +0000 | [diff] [blame^] | 8 | # |
| 9 | # SPDX-License-Identifier: GPL-2.0 |
| 10 | # |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 11 | |
Masahiro Yamada | babb444 | 2014-02-05 10:52:52 +0900 | [diff] [blame] | 12 | DOCBOOKS := linker_lists.xml stdio.xml |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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 |
| 24 | PDF_METHOD = $(prefer-db2x) |
| 25 | PS_METHOD = $(prefer-db2x) |
| 26 | |
| 27 | |
| 28 | ### |
| 29 | # The targets that may be used. |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 30 | PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 31 | |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 32 | targets += $(DOCBOOKS) |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 33 | BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 34 | xmldocs: $(BOOKS) |
| 35 | sgmldocs: xmldocs |
| 36 | |
| 37 | PS := $(patsubst %.xml, %.ps, $(BOOKS)) |
| 38 | psdocs: $(PS) |
| 39 | |
| 40 | PDF := $(patsubst %.xml, %.pdf, $(BOOKS)) |
| 41 | pdfdocs: $(PDF) |
| 42 | |
| 43 | HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS))) |
| 44 | htmldocs: $(HTML) |
| 45 | $(call build_main_index) |
| 46 | $(call build_images) |
| 47 | $(call install_media_images) |
| 48 | |
| 49 | MAN := $(patsubst %.xml, %.9, $(BOOKS)) |
| 50 | mandocs: $(MAN) |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 51 | $(if $(wildcard $(obj)/man/*.9),gzip -f $(obj)/man/*.9) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 52 | |
| 53 | installmandocs: mandocs |
| 54 | mkdir -p /usr/local/man/man9/ |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 55 | install $(obj)/man/*.9.gz /usr/local/man/man9/ |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 56 | |
| 57 | ### |
| 58 | #External programs used |
Masahiro Yamada | 8fac9c7 | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 59 | KERNELDOC = $(srctree)/scripts/kernel-doc |
| 60 | DOCPROC = $(objtree)/scripts/docproc |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 61 | |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 62 | XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 63 | XMLTOFLAGS += --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). |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 72 | quiet_cmd_docproc = DOCPROC $@ |
| 73 | cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@ |
| 74 | define 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 |
| 82 | endef |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 83 | |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 84 | %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) FORCE |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 85 | $(call if_changed_rule,docproc) |
| 86 | |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 87 | # Tell kbuild to always build the programs |
| 88 | always := $(hostprogs-y) |
| 89 | |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 90 | notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \ |
| 91 | exit 1 |
| 92 | db2xtemplate = db2TYPE -o $(dir $@) $< |
| 93 | xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $< |
| 94 | |
| 95 | # determine which methods are available |
| 96 | ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found) |
| 97 | use-db2x = db2x |
| 98 | prefer-db2x = db2x |
| 99 | else |
| 100 | use-db2x = notfound |
| 101 | prefer-db2x = $(use-xmlto) |
| 102 | endif |
| 103 | ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found) |
| 104 | use-xmlto = xmlto |
| 105 | prefer-xmlto = xmlto |
| 106 | else |
| 107 | use-xmlto = notfound |
| 108 | prefer-xmlto = $(use-db2x) |
| 109 | endif |
| 110 | |
| 111 | # the commands, generated from the chosen template |
| 112 | quiet_cmd_db2ps = PS $@ |
| 113 | cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template)) |
| 114 | %.ps : %.xml |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 115 | $(call cmd,db2ps) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 116 | |
| 117 | quiet_cmd_db2pdf = PDF $@ |
| 118 | cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template)) |
| 119 | %.pdf : %.xml |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 120 | $(call cmd,db2pdf) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 121 | |
| 122 | |
| 123 | index = index.html |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 124 | main_idx = $(obj)/$(index) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 125 | build_main_index = rm -rf $(main_idx); \ |
| 126 | echo '<h1>U-Boot Bootloader HTML Documentation</h1>' >> $(main_idx) && \ |
Masahiro Yamada | 7424145 | 2014-02-24 11:12:09 +0900 | [diff] [blame] | 127 | echo '<h2>U-Boot Version: $(UBOOTVERSION)</h2>' >> $(main_idx) && \ |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 128 | cat $(HTML) >> $(main_idx) |
| 129 | |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 130 | quiet_cmd_db2html = HTML $@ |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 131 | cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \ |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 132 | echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \ |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 133 | $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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,%,$@) |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 140 | $(call cmd,db2html) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 141 | @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 142 | cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 143 | |
| 144 | quiet_cmd_db2man = MAN $@ |
Masahiro Yamada | 71ba245 | 2014-04-15 13:30:51 +0900 | [diff] [blame] | 145 | cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 146 | %.9 : %.xml |
| 147 | @(which xmlto > /dev/null 2>&1) || \ |
| 148 | (echo "*** You need to install xmlto ***"; \ |
| 149 | exit 1) |
Masahiro Yamada | 9e41403 | 2014-02-04 17:24:24 +0900 | [diff] [blame] | 150 | $(Q)mkdir -p $(obj)/man |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 151 | $(call cmd,db2man) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 152 | @touch $@ |
| 153 | |
| 154 | ### |
| 155 | # Rules to generate postscripts and PNG images from .fig format files |
| 156 | quiet_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) |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 163 | $(call cmd,fig2eps) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 164 | |
| 165 | quiet_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) |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 172 | $(call cmd,fig2png) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 173 | |
| 174 | ### |
| 175 | # Rule to convert a .c file to inline XML documentation |
| 176 | gen_xml = : |
| 177 | quiet_gen_xml = echo ' GEN $@' |
| 178 | silent_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 |
| 191 | dochelp: |
| 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 |
| 203 | clean-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 | |
| 215 | clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man |
| 216 | |
| 217 | cleandocs: |
Masahiro Yamada | 8fac9c7 | 2014-02-05 10:52:50 +0900 | [diff] [blame] | 218 | $(Q)rm -f $(call objectify, $(clean-files)) |
| 219 | $(Q)rm -rf $(call objectify, $(clean-dirs)) |
Marek Vasut | 30ff891 | 2012-10-06 14:04:58 +0000 | [diff] [blame] | 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) |