| 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 \ | 
 | 11 | 	    procfs-guide.xml writing_usb_driver.xml scsidrivers.xml \ | 
 | 12 | 	    sis900.xml kernel-api.xml journal-api.xml lsm.xml usb.xml \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | 	    gadget.xml libata.xml mtdnand.xml librs.xml | 
 | 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 |  | 
 | 23 | ### | 
 | 24 | # The targets that may be used. | 
 | 25 | .PHONY:	xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs | 
 | 26 |  | 
 | 27 | BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) | 
 | 28 | xmldocs: $(BOOKS) | 
 | 29 | sgmldocs: xmldocs | 
 | 30 |  | 
 | 31 | PS := $(patsubst %.xml, %.ps, $(BOOKS)) | 
 | 32 | psdocs: $(PS) | 
 | 33 |  | 
 | 34 | PDF := $(patsubst %.xml, %.pdf, $(BOOKS)) | 
 | 35 | pdfdocs: $(PDF) | 
 | 36 |  | 
 | 37 | HTML := $(patsubst %.xml, %.html, $(BOOKS)) | 
 | 38 | htmldocs: $(HTML) | 
 | 39 |  | 
 | 40 | MAN := $(patsubst %.xml, %.9, $(BOOKS)) | 
 | 41 | mandocs: $(MAN) | 
 | 42 |  | 
 | 43 | installmandocs: mandocs | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 44 | 	mkdir -p /usr/local/man/man9/ | 
 | 45 | 	install Documentation/DocBook/man/*.9.gz /usr/local/man/man9/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 |  | 
 | 47 | ### | 
 | 48 | #External programs used | 
 | 49 | KERNELDOC = scripts/kernel-doc | 
 | 50 | DOCPROC   = scripts/basic/docproc | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 51 |  | 
| Martin Waitz | 2948e57 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 52 | XMLTOFLAGS = -m Documentation/DocBook/stylesheet.xsl | 
 | 53 | #XMLTOFLAGS += --skip-validation | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 |  | 
 | 55 | ### | 
 | 56 | # DOCPROC is used for two purposes: | 
 | 57 | # 1) To generate a dependency list for a .tmpl file | 
 | 58 | # 2) To preprocess a .tmpl file and call kernel-doc with | 
 | 59 | #     appropriate parameters. | 
 | 60 | # The following rules are used to generate the .xml documentation | 
 | 61 | # required to generate the final targets. (ps, pdf, html). | 
 | 62 | quiet_cmd_docproc = DOCPROC $@ | 
 | 63 |       cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@ | 
 | 64 | define rule_docproc | 
 | 65 | 	set -e;								\ | 
 | 66 |         $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) 	\ | 
 | 67 |         $(cmd_$(1)); 							\ | 
 | 68 |         ( 								\ | 
 | 69 |           echo 'cmd_$@ := $(cmd_$(1))'; 				\ | 
 | 70 |           echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; 		\ | 
 | 71 |         ) > $(dir $@).$(notdir $@).cmd | 
 | 72 | endef | 
 | 73 |  | 
 | 74 | %.xml: %.tmpl FORCE | 
 | 75 | 	$(call if_changed_rule,docproc) | 
 | 76 |  | 
 | 77 | ### | 
 | 78 | #Read in all saved dependency files  | 
 | 79 | cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd)) | 
 | 80 |  | 
 | 81 | ifneq ($(cmd_files),) | 
 | 82 |   include $(cmd_files) | 
 | 83 | endif | 
 | 84 |  | 
 | 85 | ### | 
 | 86 | # Changes in kernel-doc force a rebuild of all documentation | 
 | 87 | $(BOOKS): $(KERNELDOC) | 
 | 88 |  | 
 | 89 | ### | 
 | 90 | # procfs guide uses a .c file as example code. | 
 | 91 | # This requires an explicit dependency | 
 | 92 | C-procfs-example = procfs_example.xml | 
 | 93 | C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example)) | 
 | 94 | $(obj)/procfs-guide.xml: $(C-procfs-example2) | 
 | 95 |  | 
 | 96 | ### | 
 | 97 | # Rules to generate postscript, PDF and HTML | 
 | 98 | # db2html creates a directory. Generate a html file used for timestamp | 
 | 99 |  | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 100 | quiet_cmd_db2ps = XMLTO    $@ | 
 | 101 |       cmd_db2ps = xmlto ps $(XMLTOFLAGS) -o $(dir $@) $< | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | %.ps : %.xml | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 103 | 	@(which xmlto > /dev/null 2>&1) || \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | 	 (echo "*** You need to install DocBook stylesheets ***"; \ | 
 | 105 | 	  exit 1) | 
 | 106 | 	$(call cmd,db2ps) | 
 | 107 |  | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 108 | quiet_cmd_db2pdf = XMLTO   $@ | 
 | 109 |       cmd_db2pdf = xmlto pdf $(XMLTOFLAGS) -o $(dir $@) $< | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | %.pdf : %.xml | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 111 | 	@(which xmlto > /dev/null 2>&1) || \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 	 (echo "*** You need to install DocBook stylesheets ***"; \ | 
 | 113 | 	  exit 1) | 
 | 114 | 	$(call cmd,db2pdf) | 
 | 115 |  | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 116 | quiet_cmd_db2html = XMLTO  $@ | 
 | 117 |       cmd_db2html = xmlto xhtml $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \ | 
| Martin Waitz | 4fa3516 | 2005-05-01 08:59:28 -0700 | [diff] [blame^] | 118 | 		echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 |          Goto $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ | 
 | 120 |  | 
 | 121 | %.html:	%.xml | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 122 | 	@(which xmlto > /dev/null 2>&1) || \ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 	 (echo "*** You need to install DocBook stylesheets ***"; \ | 
 | 124 | 	  exit 1) | 
 | 125 | 	@rm -rf $@ $(patsubst %.html,%,$@) | 
 | 126 | 	$(call cmd,db2html) | 
 | 127 | 	@if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ | 
 | 128 |             cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi | 
 | 129 |  | 
| Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 130 | quiet_cmd_db2man = XMLTO   $@ | 
 | 131 |       cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; gzip -f $(obj)/man/*.9; fi | 
 | 132 | %.9 : %.xml | 
 | 133 | 	@(which xmlto > /dev/null 2>&1) || \ | 
 | 134 | 	 (echo "*** You need to install DocBook stylesheets ***"; \ | 
 | 135 | 	  exit 1) | 
 | 136 | 	$(call cmd,db2man) | 
 | 137 | 	@touch $@ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
 | 139 | ### | 
 | 140 | # Rules to generate postscripts and PNG imgages from .fig format files | 
 | 141 | quiet_cmd_fig2eps = FIG2EPS $@ | 
 | 142 |       cmd_fig2eps = fig2dev -Leps $< $@ | 
 | 143 |  | 
 | 144 | %.eps: %.fig | 
 | 145 | 	@(which fig2dev > /dev/null 2>&1) || \ | 
 | 146 | 	 (echo "*** You need to install transfig ***"; \ | 
 | 147 | 	  exit 1) | 
 | 148 | 	$(call cmd,fig2eps) | 
 | 149 |  | 
 | 150 | quiet_cmd_fig2png = FIG2PNG $@ | 
 | 151 |       cmd_fig2png = fig2dev -Lpng $< $@ | 
 | 152 |  | 
 | 153 | %.png: %.fig | 
 | 154 | 	@(which fig2dev > /dev/null 2>&1) || \ | 
 | 155 | 	 (echo "*** You need to install transfig ***"; \ | 
 | 156 | 	  exit 1) | 
 | 157 | 	$(call cmd,fig2png) | 
 | 158 |  | 
 | 159 | ### | 
 | 160 | # Rule to convert a .c file to inline XML documentation | 
 | 161 | %.xml: %.c | 
 | 162 | 	@echo '  GEN     $@' | 
 | 163 | 	@(                            \ | 
 | 164 | 	   echo "<programlisting>";   \ | 
 | 165 | 	   expand --tabs=8 < $< |     \ | 
 | 166 | 	   sed -e "s/&/\\&/g"     \ | 
 | 167 | 	       -e "s/</\\</g"      \ | 
 | 168 | 	       -e "s/>/\\>/g";     \ | 
 | 169 | 	   echo "</programlisting>")  > $@ | 
 | 170 |  | 
 | 171 | ### | 
 | 172 | # Help targets as used by the top-level makefile | 
 | 173 | dochelp: | 
 | 174 | 	@echo  '  Linux kernel internal documentation in different formats:' | 
 | 175 | 	@echo  '  xmldocs (XML DocBook), psdocs (Postscript), pdfdocs (PDF)' | 
 | 176 | 	@echo  '  htmldocs (HTML), mandocs (man pages, use installmandocs to install)' | 
 | 177 |  | 
 | 178 | ### | 
 | 179 | # Temporary files left by various tools | 
 | 180 | clean-files := $(DOCBOOKS) \ | 
 | 181 | 	$(patsubst %.xml, %.dvi,  $(DOCBOOKS)) \ | 
 | 182 | 	$(patsubst %.xml, %.aux,  $(DOCBOOKS)) \ | 
 | 183 | 	$(patsubst %.xml, %.tex,  $(DOCBOOKS)) \ | 
 | 184 | 	$(patsubst %.xml, %.log,  $(DOCBOOKS)) \ | 
 | 185 | 	$(patsubst %.xml, %.out,  $(DOCBOOKS)) \ | 
 | 186 | 	$(patsubst %.xml, %.ps,   $(DOCBOOKS)) \ | 
 | 187 | 	$(patsubst %.xml, %.pdf,  $(DOCBOOKS)) \ | 
 | 188 | 	$(patsubst %.xml, %.html, $(DOCBOOKS)) \ | 
 | 189 | 	$(patsubst %.xml, %.9,    $(DOCBOOKS)) \ | 
 | 190 | 	$(C-procfs-example) | 
 | 191 |  | 
 | 192 | clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) | 
 | 193 |  | 
 | 194 | #man put files in man subdir - traverse down | 
 | 195 | subdir- := man/ |