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