Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 ducument 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 | DOCBOOKS := wanbook.xml z8530book.xml mcabook.xml videobook.xml \ |
Jeff Garzik | ac9296f | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 10 | kernel-hacking.xml kernel-locking.xml deviceiobook.xml \ |
James Bottomley | ad34ea2 | 2005-05-20 15:27:44 -0500 | [diff] [blame] | 11 | procfs-guide.xml writing_usb_driver.xml \ |
Adrian Bunk | c3cf560 | 2006-03-04 17:07:57 +0100 | [diff] [blame] | 12 | kernel-api.xml journal-api.xml lsm.xml usb.xml \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 13 | gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | ### |
| 16 | # The build process is as follows (targets): |
| 17 | # (xmldocs) |
| 18 | # file.tmpl --> file.xml +--> file.ps (psdocs) |
| 19 | # +--> file.pdf (pdfdocs) |
| 20 | # +--> DIR=file (htmldocs) |
| 21 | # +--> man/ (mandocs) |
| 22 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 23 | |
| 24 | # for PDF and PS output you can choose between xmlto and docbook-utils tools |
| 25 | PDF_METHOD = $(prefer-db2x) |
| 26 | PS_METHOD = $(prefer-db2x) |
| 27 | |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | ### |
| 30 | # The targets that may be used. |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 31 | PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) |
| 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 := $(patsubst %.xml, %.html, $(BOOKS)) |
| 44 | htmldocs: $(HTML) |
| 45 | |
| 46 | MAN := $(patsubst %.xml, %.9, $(BOOKS)) |
| 47 | mandocs: $(MAN) |
| 48 | |
| 49 | installmandocs: mandocs |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 50 | mkdir -p /usr/local/man/man9/ |
| 51 | install Documentation/DocBook/man/*.9.gz /usr/local/man/man9/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | ### |
| 54 | #External programs used |
| 55 | KERNELDOC = scripts/kernel-doc |
| 56 | DOCPROC = scripts/basic/docproc |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 57 | |
Jiri Slaby | 597f6ee | 2005-06-23 22:05:18 -0700 | [diff] [blame] | 58 | XMLTOFLAGS = -m $(srctree)/Documentation/DocBook/stylesheet.xsl |
Martin Waitz | 2948e57 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 59 | #XMLTOFLAGS += --skip-validation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | ### |
| 62 | # DOCPROC is used for two purposes: |
| 63 | # 1) To generate a dependency list for a .tmpl file |
| 64 | # 2) To preprocess a .tmpl file and call kernel-doc with |
| 65 | # appropriate parameters. |
| 66 | # The following rules are used to generate the .xml documentation |
| 67 | # required to generate the final targets. (ps, pdf, html). |
| 68 | quiet_cmd_docproc = DOCPROC $@ |
| 69 | cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@ |
| 70 | define rule_docproc |
| 71 | set -e; \ |
| 72 | $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \ |
| 73 | $(cmd_$(1)); \ |
| 74 | ( \ |
| 75 | echo 'cmd_$@ := $(cmd_$(1))'; \ |
| 76 | echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \ |
| 77 | ) > $(dir $@).$(notdir $@).cmd |
| 78 | endef |
| 79 | |
| 80 | %.xml: %.tmpl FORCE |
| 81 | $(call if_changed_rule,docproc) |
| 82 | |
| 83 | ### |
| 84 | #Read in all saved dependency files |
| 85 | cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd)) |
| 86 | |
| 87 | ifneq ($(cmd_files),) |
| 88 | include $(cmd_files) |
| 89 | endif |
| 90 | |
| 91 | ### |
| 92 | # Changes in kernel-doc force a rebuild of all documentation |
| 93 | $(BOOKS): $(KERNELDOC) |
| 94 | |
| 95 | ### |
| 96 | # procfs guide uses a .c file as example code. |
| 97 | # This requires an explicit dependency |
| 98 | C-procfs-example = procfs_example.xml |
| 99 | C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example)) |
| 100 | $(obj)/procfs-guide.xml: $(C-procfs-example2) |
| 101 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 102 | notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \ |
| 103 | exit 1 |
| 104 | db2xtemplate = db2TYPE -o $(dir $@) $< |
| 105 | xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $< |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 107 | # determine which methods are available |
| 108 | ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found) |
| 109 | use-db2x = db2x |
| 110 | prefer-db2x = db2x |
| 111 | else |
| 112 | use-db2x = notfound |
| 113 | prefer-db2x = $(use-xmlto) |
| 114 | endif |
| 115 | ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found) |
| 116 | use-xmlto = xmlto |
| 117 | prefer-xmlto = xmlto |
| 118 | else |
| 119 | use-xmlto = notfound |
| 120 | prefer-xmlto = $(use-db2x) |
| 121 | endif |
| 122 | |
| 123 | # the commands, generated from the chosen template |
| 124 | quiet_cmd_db2ps = PS $@ |
| 125 | cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | %.ps : %.xml |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | $(call cmd,db2ps) |
| 128 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 129 | quiet_cmd_db2pdf = PDF $@ |
| 130 | cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | %.pdf : %.xml |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | $(call cmd,db2pdf) |
| 133 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 134 | quiet_cmd_db2html = HTML $@ |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 135 | cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \ |
Martin Waitz | 4fa3516 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 136 | echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | Goto $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ |
| 138 | |
| 139 | %.html: %.xml |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 140 | @(which xmlto > /dev/null 2>&1) || \ |
Sam Ravnborg | fd4a324 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 141 | (echo "*** You need to install xmlto ***"; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | exit 1) |
| 143 | @rm -rf $@ $(patsubst %.html,%,$@) |
| 144 | $(call cmd,db2html) |
| 145 | @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ |
| 146 | cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi |
| 147 | |
Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 148 | quiet_cmd_db2man = MAN $@ |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 149 | cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi |
| 150 | %.9 : %.xml |
| 151 | @(which xmlto > /dev/null 2>&1) || \ |
Sam Ravnborg | fd4a324 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 152 | (echo "*** You need to install xmlto ***"; \ |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 153 | exit 1) |
| 154 | $(call cmd,db2man) |
| 155 | @touch $@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | ### |
| 158 | # Rules to generate postscripts and PNG imgages from .fig format files |
| 159 | quiet_cmd_fig2eps = FIG2EPS $@ |
| 160 | cmd_fig2eps = fig2dev -Leps $< $@ |
| 161 | |
| 162 | %.eps: %.fig |
| 163 | @(which fig2dev > /dev/null 2>&1) || \ |
| 164 | (echo "*** You need to install transfig ***"; \ |
| 165 | exit 1) |
| 166 | $(call cmd,fig2eps) |
| 167 | |
| 168 | quiet_cmd_fig2png = FIG2PNG $@ |
| 169 | cmd_fig2png = fig2dev -Lpng $< $@ |
| 170 | |
| 171 | %.png: %.fig |
| 172 | @(which fig2dev > /dev/null 2>&1) || \ |
| 173 | (echo "*** You need to install transfig ***"; \ |
| 174 | exit 1) |
| 175 | $(call cmd,fig2png) |
| 176 | |
| 177 | ### |
| 178 | # Rule to convert a .c file to inline XML documentation |
| 179 | %.xml: %.c |
| 180 | @echo ' GEN $@' |
| 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 ' Linux kernel internal documentation in different formats:' |
| 193 | @echo ' xmldocs (XML DocBook), psdocs (Postscript), pdfdocs (PDF)' |
| 194 | @echo ' htmldocs (HTML), mandocs (man pages, use installmandocs to install)' |
| 195 | |
| 196 | ### |
| 197 | # Temporary files left by various tools |
| 198 | clean-files := $(DOCBOOKS) \ |
| 199 | $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \ |
| 200 | $(patsubst %.xml, %.aux, $(DOCBOOKS)) \ |
| 201 | $(patsubst %.xml, %.tex, $(DOCBOOKS)) \ |
| 202 | $(patsubst %.xml, %.log, $(DOCBOOKS)) \ |
| 203 | $(patsubst %.xml, %.out, $(DOCBOOKS)) \ |
| 204 | $(patsubst %.xml, %.ps, $(DOCBOOKS)) \ |
| 205 | $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \ |
| 206 | $(patsubst %.xml, %.html, $(DOCBOOKS)) \ |
| 207 | $(patsubst %.xml, %.9, $(DOCBOOKS)) \ |
| 208 | $(C-procfs-example) |
| 209 | |
| 210 | clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) |
| 211 | |
| 212 | #man put files in man subdir - traverse down |
| 213 | subdir- := man/ |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 214 | |
| 215 | |
| 216 | # Declare the contents of the .PHONY variable as phony. We keep that |
| 217 | # information in a variable se we can use it in if_changed and friends. |
| 218 | |
| 219 | .PHONY: $(PHONY) |