| 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 | 
| Adrian Bunk | 58ef2c4 | 2006-04-01 01:04:59 +0200 | [diff] [blame] | 5 | # to document the SRC - and how to read it. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 \ | 
| Randy Dunlap | 733b72c | 2006-11-02 22:07:02 -0800 | [diff] [blame] | 12 | 	    kernel-api.xml filesystems.xml lsm.xml usb.xml \ | 
| Thomas Gleixner | 11c869e | 2006-06-29 02:24:47 -0700 | [diff] [blame] | 13 | 	    gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \ | 
 | 14 | 	    genericirq.xml | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 |  | 
 | 16 | ### | 
 | 17 | # The build process is as follows (targets): | 
 | 18 | #              (xmldocs) | 
 | 19 | # file.tmpl --> file.xml +--> file.ps   (psdocs) | 
 | 20 | #                        +--> file.pdf  (pdfdocs) | 
 | 21 | #                        +--> DIR=file  (htmldocs) | 
 | 22 | #                        +--> man/      (mandocs) | 
 | 23 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 24 |  | 
 | 25 | # for PDF and PS output you can choose between xmlto and docbook-utils tools | 
 | 26 | PDF_METHOD	= $(prefer-db2x) | 
 | 27 | PS_METHOD	= $(prefer-db2x) | 
 | 28 |  | 
 | 29 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | ### | 
 | 31 | # The targets that may be used. | 
| Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 32 | PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 |  | 
 | 34 | BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) | 
 | 35 | xmldocs: $(BOOKS) | 
 | 36 | sgmldocs: xmldocs | 
 | 37 |  | 
 | 38 | PS := $(patsubst %.xml, %.ps, $(BOOKS)) | 
 | 39 | psdocs: $(PS) | 
 | 40 |  | 
 | 41 | PDF := $(patsubst %.xml, %.pdf, $(BOOKS)) | 
 | 42 | pdfdocs: $(PDF) | 
 | 43 |  | 
 | 44 | HTML := $(patsubst %.xml, %.html, $(BOOKS)) | 
 | 45 | htmldocs: $(HTML) | 
 | 46 |  | 
 | 47 | MAN := $(patsubst %.xml, %.9, $(BOOKS)) | 
 | 48 | mandocs: $(MAN) | 
 | 49 |  | 
 | 50 | installmandocs: mandocs | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 51 | 	mkdir -p /usr/local/man/man9/ | 
 | 52 | 	install Documentation/DocBook/man/*.9.gz /usr/local/man/man9/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
 | 54 | ### | 
 | 55 | #External programs used | 
| Mike Frysinger | 829ad75 | 2006-12-29 16:49:07 -0800 | [diff] [blame] | 56 | KERNELDOC = $(srctree)/scripts/kernel-doc | 
 | 57 | DOCPROC   = $(objtree)/scripts/basic/docproc | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 58 |  | 
| Jiri Slaby | 597f6ee | 2005-06-23 22:05:18 -0700 | [diff] [blame] | 59 | XMLTOFLAGS = -m $(srctree)/Documentation/DocBook/stylesheet.xsl | 
| Martin Waitz | 2948e57 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 60 | #XMLTOFLAGS += --skip-validation | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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). | 
 | 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 | 
 | 80 |  | 
 | 81 | %.xml: %.tmpl FORCE | 
 | 82 | 	$(call if_changed_rule,docproc) | 
 | 83 |  | 
 | 84 | ### | 
 | 85 | #Read in all saved dependency files  | 
 | 86 | cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd)) | 
 | 87 |  | 
 | 88 | ifneq ($(cmd_files),) | 
 | 89 |   include $(cmd_files) | 
 | 90 | endif | 
 | 91 |  | 
 | 92 | ### | 
 | 93 | # Changes in kernel-doc force a rebuild of all documentation | 
 | 94 | $(BOOKS): $(KERNELDOC) | 
 | 95 |  | 
 | 96 | ### | 
 | 97 | # procfs guide uses a .c file as example code. | 
 | 98 | # This requires an explicit dependency | 
 | 99 | C-procfs-example = procfs_example.xml | 
 | 100 | C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example)) | 
 | 101 | $(obj)/procfs-guide.xml: $(C-procfs-example2) | 
 | 102 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 103 | notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \ | 
 | 104 | 		   exit 1 | 
 | 105 | db2xtemplate = db2TYPE -o $(dir $@) $< | 
 | 106 | xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $< | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 108 | # determine which methods are available | 
 | 109 | ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found) | 
 | 110 | 	use-db2x = db2x | 
 | 111 | 	prefer-db2x = db2x | 
 | 112 | else | 
 | 113 | 	use-db2x = notfound | 
 | 114 | 	prefer-db2x = $(use-xmlto) | 
 | 115 | endif | 
 | 116 | ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found) | 
 | 117 | 	use-xmlto = xmlto | 
 | 118 | 	prefer-xmlto = xmlto | 
 | 119 | else | 
 | 120 | 	use-xmlto = notfound | 
 | 121 | 	prefer-xmlto = $(use-db2x) | 
 | 122 | endif | 
 | 123 |  | 
 | 124 | # the commands, generated from the chosen template | 
 | 125 | quiet_cmd_db2ps = PS      $@ | 
 | 126 |       cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | %.ps : %.xml | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | 	$(call cmd,db2ps) | 
 | 129 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 130 | quiet_cmd_db2pdf = PDF      $@ | 
 | 131 |       cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | %.pdf : %.xml | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | 	$(call cmd,db2pdf) | 
 | 134 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 135 | quiet_cmd_db2html = HTML   $@ | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 136 |       cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \ | 
| Martin Waitz | 4fa3516 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 137 | 		echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |          Goto $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ | 
 | 139 |  | 
 | 140 | %.html:	%.xml | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 141 | 	@(which xmlto > /dev/null 2>&1) || \ | 
| Sam Ravnborg | fd4a324 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 142 | 	 (echo "*** You need to install xmlto ***"; \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | 	  exit 1) | 
 | 144 | 	@rm -rf $@ $(patsubst %.html,%,$@) | 
 | 145 | 	$(call cmd,db2html) | 
 | 146 | 	@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ | 
 | 147 |             cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi | 
 | 148 |  | 
| Martin Waitz | 71f95cf | 2005-11-13 16:08:15 -0800 | [diff] [blame] | 149 | quiet_cmd_db2man = MAN     $@ | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 150 |       cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi | 
 | 151 | %.9 : %.xml | 
 | 152 | 	@(which xmlto > /dev/null 2>&1) || \ | 
| Sam Ravnborg | fd4a324 | 2005-05-01 08:59:28 -0700 | [diff] [blame] | 153 | 	 (echo "*** You need to install xmlto ***"; \ | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 154 | 	  exit 1) | 
 | 155 | 	$(call cmd,db2man) | 
 | 156 | 	@touch $@ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 |  | 
 | 158 | ### | 
 | 159 | # Rules to generate postscripts and PNG imgages from .fig format files | 
 | 160 | quiet_cmd_fig2eps = FIG2EPS $@ | 
 | 161 |       cmd_fig2eps = fig2dev -Leps $< $@ | 
 | 162 |  | 
 | 163 | %.eps: %.fig | 
 | 164 | 	@(which fig2dev > /dev/null 2>&1) || \ | 
 | 165 | 	 (echo "*** You need to install transfig ***"; \ | 
 | 166 | 	  exit 1) | 
 | 167 | 	$(call cmd,fig2eps) | 
 | 168 |  | 
 | 169 | quiet_cmd_fig2png = FIG2PNG $@ | 
 | 170 |       cmd_fig2png = fig2dev -Lpng $< $@ | 
 | 171 |  | 
 | 172 | %.png: %.fig | 
 | 173 | 	@(which fig2dev > /dev/null 2>&1) || \ | 
 | 174 | 	 (echo "*** You need to install transfig ***"; \ | 
 | 175 | 	  exit 1) | 
 | 176 | 	$(call cmd,fig2png) | 
 | 177 |  | 
 | 178 | ### | 
 | 179 | # Rule to convert a .c file to inline XML documentation | 
 | 180 | %.xml: %.c | 
 | 181 | 	@echo '  GEN     $@' | 
 | 182 | 	@(                            \ | 
 | 183 | 	   echo "<programlisting>";   \ | 
 | 184 | 	   expand --tabs=8 < $< |     \ | 
 | 185 | 	   sed -e "s/&/\\&/g"     \ | 
 | 186 | 	       -e "s/</\\</g"      \ | 
 | 187 | 	       -e "s/>/\\>/g";     \ | 
 | 188 | 	   echo "</programlisting>")  > $@ | 
 | 189 |  | 
 | 190 | ### | 
 | 191 | # Help targets as used by the top-level makefile | 
 | 192 | dochelp: | 
| Jesper Juhl | 6fc52f8 | 2006-12-07 00:16:26 +0100 | [diff] [blame] | 193 | 	@echo  ' Linux kernel internal documentation in different formats:' | 
 | 194 | 	@echo  '  htmldocs        - HTML' | 
 | 195 | 	@echo  '  installmandocs  - install man pages generated by mandocs' | 
 | 196 | 	@echo  '  mandocs         - man pages' | 
 | 197 | 	@echo  '  pdfdocs         - PDF' | 
 | 198 | 	@echo  '  psdocs          - Postscript' | 
 | 199 | 	@echo  '  xmldocs         - XML DocBook' | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 	$(C-procfs-example) | 
 | 214 |  | 
 | 215 | clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) | 
 | 216 |  | 
 | 217 | #man put files in man subdir - traverse down | 
 | 218 | subdir- := man/ | 
| Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 219 |  | 
 | 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) |