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 |
| 44 | $(MAKEMAN) install Documentation/DocBook/man |
| 45 | |
| 46 | ### |
| 47 | #External programs used |
| 48 | KERNELDOC = scripts/kernel-doc |
| 49 | DOCPROC = scripts/basic/docproc |
| 50 | SPLITMAN = $(PERL) $(srctree)/scripts/split-man |
| 51 | MAKEMAN = $(PERL) $(srctree)/scripts/makeman |
| 52 | |
| 53 | ### |
| 54 | # DOCPROC is used for two purposes: |
| 55 | # 1) To generate a dependency list for a .tmpl file |
| 56 | # 2) To preprocess a .tmpl file and call kernel-doc with |
| 57 | # appropriate parameters. |
| 58 | # The following rules are used to generate the .xml documentation |
| 59 | # required to generate the final targets. (ps, pdf, html). |
| 60 | quiet_cmd_docproc = DOCPROC $@ |
| 61 | cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@ |
| 62 | define rule_docproc |
| 63 | set -e; \ |
| 64 | $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \ |
| 65 | $(cmd_$(1)); \ |
| 66 | ( \ |
| 67 | echo 'cmd_$@ := $(cmd_$(1))'; \ |
| 68 | echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`; \ |
| 69 | ) > $(dir $@).$(notdir $@).cmd |
| 70 | endef |
| 71 | |
| 72 | %.xml: %.tmpl FORCE |
| 73 | $(call if_changed_rule,docproc) |
| 74 | |
| 75 | ### |
| 76 | #Read in all saved dependency files |
| 77 | cmd_files := $(wildcard $(foreach f,$(BOOKS),$(dir $(f)).$(notdir $(f)).cmd)) |
| 78 | |
| 79 | ifneq ($(cmd_files),) |
| 80 | include $(cmd_files) |
| 81 | endif |
| 82 | |
| 83 | ### |
| 84 | # Changes in kernel-doc force a rebuild of all documentation |
| 85 | $(BOOKS): $(KERNELDOC) |
| 86 | |
| 87 | ### |
| 88 | # procfs guide uses a .c file as example code. |
| 89 | # This requires an explicit dependency |
| 90 | C-procfs-example = procfs_example.xml |
| 91 | C-procfs-example2 = $(addprefix $(obj)/,$(C-procfs-example)) |
| 92 | $(obj)/procfs-guide.xml: $(C-procfs-example2) |
| 93 | |
| 94 | ### |
| 95 | # Rules to generate postscript, PDF and HTML |
| 96 | # db2html creates a directory. Generate a html file used for timestamp |
| 97 | |
| 98 | quiet_cmd_db2ps = DB2PS $@ |
| 99 | cmd_db2ps = db2ps -o $(dir $@) $< |
| 100 | %.ps : %.xml |
| 101 | @(which db2ps > /dev/null 2>&1) || \ |
| 102 | (echo "*** You need to install DocBook stylesheets ***"; \ |
| 103 | exit 1) |
| 104 | $(call cmd,db2ps) |
| 105 | |
| 106 | quiet_cmd_db2pdf = DB2PDF $@ |
| 107 | cmd_db2pdf = db2pdf -o $(dir $@) $< |
| 108 | %.pdf : %.xml |
| 109 | @(which db2pdf > /dev/null 2>&1) || \ |
| 110 | (echo "*** You need to install DocBook stylesheets ***"; \ |
| 111 | exit 1) |
| 112 | $(call cmd,db2pdf) |
| 113 | |
| 114 | quiet_cmd_db2html = DB2HTML $@ |
| 115 | cmd_db2html = db2html -o $(patsubst %.html,%,$@) $< && \ |
| 116 | echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/book1.html"> \ |
| 117 | Goto $(patsubst %.html,%,$(notdir $@))</a><p>' > $@ |
| 118 | |
| 119 | %.html: %.xml |
| 120 | @(which db2html > /dev/null 2>&1) || \ |
| 121 | (echo "*** You need to install DocBook stylesheets ***"; \ |
| 122 | exit 1) |
| 123 | @rm -rf $@ $(patsubst %.html,%,$@) |
| 124 | $(call cmd,db2html) |
| 125 | @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \ |
| 126 | cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi |
| 127 | |
| 128 | ### |
| 129 | # Rule to generate man files - output is placed in the man subdirectory |
| 130 | |
| 131 | %.9: %.xml |
| 132 | ifneq ($(KBUILD_SRC),) |
| 133 | $(Q)mkdir -p $(objtree)/Documentation/DocBook/man |
| 134 | endif |
| 135 | $(SPLITMAN) $< $(objtree)/Documentation/DocBook/man "$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)" |
| 136 | $(MAKEMAN) convert $(objtree)/Documentation/DocBook/man $< |
| 137 | |
| 138 | ### |
| 139 | # Rules to generate postscripts and PNG imgages from .fig format files |
| 140 | quiet_cmd_fig2eps = FIG2EPS $@ |
| 141 | cmd_fig2eps = fig2dev -Leps $< $@ |
| 142 | |
| 143 | %.eps: %.fig |
| 144 | @(which fig2dev > /dev/null 2>&1) || \ |
| 145 | (echo "*** You need to install transfig ***"; \ |
| 146 | exit 1) |
| 147 | $(call cmd,fig2eps) |
| 148 | |
| 149 | quiet_cmd_fig2png = FIG2PNG $@ |
| 150 | cmd_fig2png = fig2dev -Lpng $< $@ |
| 151 | |
| 152 | %.png: %.fig |
| 153 | @(which fig2dev > /dev/null 2>&1) || \ |
| 154 | (echo "*** You need to install transfig ***"; \ |
| 155 | exit 1) |
| 156 | $(call cmd,fig2png) |
| 157 | |
| 158 | ### |
| 159 | # Rule to convert a .c file to inline XML documentation |
| 160 | %.xml: %.c |
| 161 | @echo ' GEN $@' |
| 162 | @( \ |
| 163 | echo "<programlisting>"; \ |
| 164 | expand --tabs=8 < $< | \ |
| 165 | sed -e "s/&/\\&/g" \ |
| 166 | -e "s/</\\</g" \ |
| 167 | -e "s/>/\\>/g"; \ |
| 168 | echo "</programlisting>") > $@ |
| 169 | |
| 170 | ### |
| 171 | # Help targets as used by the top-level makefile |
| 172 | dochelp: |
| 173 | @echo ' Linux kernel internal documentation in different formats:' |
| 174 | @echo ' xmldocs (XML DocBook), psdocs (Postscript), pdfdocs (PDF)' |
| 175 | @echo ' htmldocs (HTML), mandocs (man pages, use installmandocs to install)' |
| 176 | |
| 177 | ### |
| 178 | # Temporary files left by various tools |
| 179 | clean-files := $(DOCBOOKS) \ |
| 180 | $(patsubst %.xml, %.dvi, $(DOCBOOKS)) \ |
| 181 | $(patsubst %.xml, %.aux, $(DOCBOOKS)) \ |
| 182 | $(patsubst %.xml, %.tex, $(DOCBOOKS)) \ |
| 183 | $(patsubst %.xml, %.log, $(DOCBOOKS)) \ |
| 184 | $(patsubst %.xml, %.out, $(DOCBOOKS)) \ |
| 185 | $(patsubst %.xml, %.ps, $(DOCBOOKS)) \ |
| 186 | $(patsubst %.xml, %.pdf, $(DOCBOOKS)) \ |
| 187 | $(patsubst %.xml, %.html, $(DOCBOOKS)) \ |
| 188 | $(patsubst %.xml, %.9, $(DOCBOOKS)) \ |
| 189 | $(C-procfs-example) |
| 190 | |
| 191 | clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) |
| 192 | |
| 193 | #man put files in man subdir - traverse down |
| 194 | subdir- := man/ |