Back to home page

LXR

 
 

    


0001 ###
0002 # This makefile is used to generate the kernel documentation,
0003 # primarily based on in-line comments in various source files.
0004 # See Documentation/kernel-doc-nano-HOWTO.txt for instruction in how
0005 # to document the SRC - and how to read it.
0006 # To add a new book the only step required is to add the book to the
0007 # list of DOCBOOKS.
0008 
0009 DOCBOOKS := z8530book.xml  \
0010             kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
0011             writing_usb_driver.xml networking.xml \
0012             kernel-api.xml filesystems.xml lsm.xml kgdb.xml \
0013             gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
0014             genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \
0015             sh.xml regulator.xml w1.xml \
0016             writing_musb_glue_layer.xml iio.xml
0017 
0018 ifeq ($(DOCBOOKS),)
0019 
0020 # Skip DocBook build if the user explicitly requested no DOCBOOKS.
0021 .DEFAULT:
0022         @echo "  SKIP    DocBook $@ target (DOCBOOKS=\"\" specified)."
0023 else
0024 ifneq ($(SPHINXDIRS),)
0025 
0026 # Skip DocBook build if the user explicitly requested a sphinx dir
0027 .DEFAULT:
0028         @echo "  SKIP    DocBook $@ target (SPHINXDIRS specified)."
0029 else
0030 
0031 
0032 ###
0033 # The build process is as follows (targets):
0034 #              (xmldocs) [by docproc]
0035 # file.tmpl --> file.xml +--> file.ps   (psdocs)   [by db2ps or xmlto]
0036 #                        +--> file.pdf  (pdfdocs)  [by db2pdf or xmlto]
0037 #                        +--> DIR=file  (htmldocs) [by xmlto]
0038 #                        +--> man/      (mandocs)  [by xmlto]
0039 
0040 
0041 # for PDF and PS output you can choose between xmlto and docbook-utils tools
0042 PDF_METHOD      = $(prefer-db2x)
0043 PS_METHOD       = $(prefer-db2x)
0044 
0045 
0046 targets += $(DOCBOOKS)
0047 BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
0048 xmldocs: $(BOOKS)
0049 sgmldocs: xmldocs
0050 
0051 PS := $(patsubst %.xml, %.ps, $(BOOKS))
0052 psdocs: $(PS)
0053 
0054 PDF := $(patsubst %.xml, %.pdf, $(BOOKS))
0055 pdfdocs: $(PDF)
0056 
0057 HTML := $(sort $(patsubst %.xml, %.html, $(BOOKS)))
0058 htmldocs: $(HTML)
0059         $(call cmd,build_main_index)
0060 
0061 MAN := $(patsubst %.xml, %.9, $(BOOKS))
0062 mandocs: $(MAN)
0063         find $(obj)/man -name '*.9' | xargs gzip -nf
0064 
0065 installmandocs: mandocs
0066         mkdir -p /usr/local/man/man9/
0067         find $(obj)/man -name '*.9.gz' -printf '%h %f\n' | \
0068                 sort -k 2 -k 1 | uniq -f 1 | sed -e 's: :/:' | \
0069                 xargs install -m 644 -t /usr/local/man/man9/
0070 
0071 # no-op for the DocBook toolchain
0072 epubdocs:
0073 latexdocs:
0074 
0075 ###
0076 #External programs used
0077 KERNELDOCXMLREF = $(srctree)/scripts/kernel-doc-xml-ref
0078 KERNELDOC       = $(srctree)/scripts/kernel-doc
0079 DOCPROC         = $(objtree)/scripts/docproc
0080 CHECK_LC_CTYPE = $(objtree)/scripts/check-lc_ctype
0081 
0082 # Use a fixed encoding - UTF-8 if the C library has support built-in
0083 # or ASCII if not
0084 LC_CTYPE := $(call try-run, LC_CTYPE=C.UTF-8 $(CHECK_LC_CTYPE),C.UTF-8,C)
0085 export LC_CTYPE
0086 
0087 XMLTOFLAGS = -m $(srctree)/$(src)/stylesheet.xsl
0088 XMLTOFLAGS += --skip-validation
0089 
0090 ###
0091 # DOCPROC is used for two purposes:
0092 # 1) To generate a dependency list for a .tmpl file
0093 # 2) To preprocess a .tmpl file and call kernel-doc with
0094 #     appropriate parameters.
0095 # The following rules are used to generate the .xml documentation
0096 # required to generate the final targets. (ps, pdf, html).
0097 quiet_cmd_docproc = DOCPROC $@
0098       cmd_docproc = SRCTREE=$(srctree)/ $(DOCPROC) doc $< >$@
0099 define rule_docproc
0100         set -e;                                                         \
0101         $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';)         \
0102         $(cmd_$(1));                                                    \
0103         (                                                               \
0104           echo 'cmd_$@ := $(cmd_$(1))';                                 \
0105           echo $@: `SRCTREE=$(srctree) $(DOCPROC) depend $<`;           \
0106         ) > $(dir $@).$(notdir $@).cmd
0107 endef
0108 
0109 %.xml: %.tmpl $(KERNELDOC) $(DOCPROC) $(KERNELDOCXMLREF) FORCE
0110         $(call if_changed_rule,docproc)
0111 
0112 # Tell kbuild to always build the programs
0113 always := $(hostprogs-y)
0114 
0115 notfoundtemplate = echo "*** You have to install docbook-utils or xmlto ***"; \
0116                    exit 1
0117 db2xtemplate = db2TYPE -o $(dir $@) $<
0118 xmltotemplate = xmlto TYPE $(XMLTOFLAGS) -o $(dir $@) $<
0119 
0120 # determine which methods are available
0121 ifeq ($(shell which db2ps >/dev/null 2>&1 && echo found),found)
0122         use-db2x = db2x
0123         prefer-db2x = db2x
0124 else
0125         use-db2x = notfound
0126         prefer-db2x = $(use-xmlto)
0127 endif
0128 ifeq ($(shell which xmlto >/dev/null 2>&1 && echo found),found)
0129         use-xmlto = xmlto
0130         prefer-xmlto = xmlto
0131 else
0132         use-xmlto = notfound
0133         prefer-xmlto = $(use-db2x)
0134 endif
0135 
0136 # the commands, generated from the chosen template
0137 quiet_cmd_db2ps = PS      $@
0138       cmd_db2ps = $(subst TYPE,ps, $($(PS_METHOD)template))
0139 %.ps : %.xml
0140         $(call cmd,db2ps)
0141 
0142 quiet_cmd_db2pdf = PDF     $@
0143       cmd_db2pdf = $(subst TYPE,pdf, $($(PDF_METHOD)template))
0144 %.pdf : %.xml
0145         $(call cmd,db2pdf)
0146 
0147 
0148 index = index.html
0149 main_idx = $(obj)/$(index)
0150 quiet_cmd_build_main_index = HTML    $(main_idx)
0151       cmd_build_main_index = rm -rf $(main_idx); \
0152                    echo '<h1>Linux Kernel HTML Documentation</h1>' >> $(main_idx) && \
0153                    echo '<h2>Kernel Version: $(KERNELVERSION)</h2>' >> $(main_idx) && \
0154                    cat $(HTML) >> $(main_idx)
0155 
0156 quiet_cmd_db2html = HTML    $@
0157       cmd_db2html = xmlto html $(XMLTOFLAGS) -o $(patsubst %.html,%,$@) $< && \
0158                 echo '<a HREF="$(patsubst %.html,%,$(notdir $@))/index.html"> \
0159                 $(patsubst %.html,%,$(notdir $@))</a><p>' > $@
0160 
0161 ###
0162 # Rules to create an aux XML and .db, and use them to re-process the DocBook XML
0163 # to fill internal hyperlinks
0164        gen_aux_xml = :
0165  quiet_gen_aux_xml = echo '  XMLREF  $@'
0166 silent_gen_aux_xml = :
0167 %.aux.xml: %.xml
0168         @$($(quiet)gen_aux_xml)
0169         @rm -rf $@
0170         @(cat $< | egrep "^<refentry id" | egrep -o "\".*\"" | cut -f 2 -d \" > $<.db)
0171         @$(KERNELDOCXMLREF) -db $<.db $< > $@
0172 .PRECIOUS: %.aux.xml
0173 
0174 %.html: %.aux.xml
0175         @(which xmlto > /dev/null 2>&1) || \
0176          (echo "*** You need to install xmlto ***"; \
0177           exit 1)
0178         @rm -rf $@ $(patsubst %.html,%,$@)
0179         $(call cmd,db2html)
0180         @if [ ! -z "$(PNG-$(basename $(notdir $@)))" ]; then \
0181             cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
0182 
0183 quiet_cmd_db2man = MAN     $@
0184       cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man/$(*F) $< ; fi
0185 %.9 : %.xml
0186         @(which xmlto > /dev/null 2>&1) || \
0187          (echo "*** You need to install xmlto ***"; \
0188           exit 1)
0189         $(Q)mkdir -p $(obj)/man/$(*F)
0190         $(call cmd,db2man)
0191         @touch $@
0192 
0193 ###
0194 # Rules to generate postscripts and PNG images from .fig format files
0195 quiet_cmd_fig2eps = FIG2EPS $@
0196       cmd_fig2eps = fig2dev -Leps $< $@
0197 
0198 %.eps: %.fig
0199         @(which fig2dev > /dev/null 2>&1) || \
0200          (echo "*** You need to install transfig ***"; \
0201           exit 1)
0202         $(call cmd,fig2eps)
0203 
0204 quiet_cmd_fig2png = FIG2PNG $@
0205       cmd_fig2png = fig2dev -Lpng $< $@
0206 
0207 %.png: %.fig
0208         @(which fig2dev > /dev/null 2>&1) || \
0209          (echo "*** You need to install transfig ***"; \
0210           exit 1)
0211         $(call cmd,fig2png)
0212 
0213 ###
0214 # Rule to convert a .c file to inline XML documentation
0215        gen_xml = :
0216  quiet_gen_xml = echo '  GEN     $@'
0217 silent_gen_xml = :
0218 %.xml: %.c
0219         @$($(quiet)gen_xml)
0220         @(                            \
0221            echo "<programlisting>";   \
0222            expand --tabs=8 < $< |     \
0223            sed -e "s/&/\\&amp;/g"     \
0224                -e "s/</\\&lt;/g"      \
0225                -e "s/>/\\&gt;/g";     \
0226            echo "</programlisting>")  > $@
0227 
0228 endif # DOCBOOKS=""
0229 endif # SPHINDIR=...
0230 
0231 ###
0232 # Help targets as used by the top-level makefile
0233 dochelp:
0234         @echo  ' Linux kernel internal documentation in different formats (DocBook):'
0235         @echo  '  htmldocs        - HTML'
0236         @echo  '  pdfdocs         - PDF'
0237         @echo  '  psdocs          - Postscript'
0238         @echo  '  xmldocs         - XML DocBook'
0239         @echo  '  mandocs         - man pages'
0240         @echo  '  installmandocs  - install man pages generated by mandocs'
0241         @echo  '  cleandocs       - clean all generated DocBook files'
0242         @echo
0243         @echo  '  make DOCBOOKS="s1.xml s2.xml" [target] Generate only docs s1.xml s2.xml'
0244         @echo  '  valid values for DOCBOOKS are: $(DOCBOOKS)'
0245         @echo
0246         @echo  "  make DOCBOOKS=\"\" [target] Don't generate docs from Docbook"
0247         @echo  '     This is useful to generate only the ReST docs (Sphinx)'
0248 
0249 
0250 ###
0251 # Temporary files left by various tools
0252 clean-files := $(DOCBOOKS) \
0253         $(patsubst %.xml, %.dvi,     $(DOCBOOKS)) \
0254         $(patsubst %.xml, %.aux,     $(DOCBOOKS)) \
0255         $(patsubst %.xml, %.tex,     $(DOCBOOKS)) \
0256         $(patsubst %.xml, %.log,     $(DOCBOOKS)) \
0257         $(patsubst %.xml, %.out,     $(DOCBOOKS)) \
0258         $(patsubst %.xml, %.ps,      $(DOCBOOKS)) \
0259         $(patsubst %.xml, %.pdf,     $(DOCBOOKS)) \
0260         $(patsubst %.xml, %.html,    $(DOCBOOKS)) \
0261         $(patsubst %.xml, %.9,       $(DOCBOOKS)) \
0262         $(patsubst %.xml, %.aux.xml, $(DOCBOOKS)) \
0263         $(patsubst %.xml, %.xml.db,  $(DOCBOOKS)) \
0264         $(patsubst %.xml, %.xml,     $(DOCBOOKS)) \
0265         $(patsubst %.xml, .%.xml.cmd, $(DOCBOOKS)) \
0266         $(index)
0267 
0268 clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS)) man
0269 
0270 cleandocs:
0271         $(Q)rm -f $(call objectify, $(clean-files))
0272         $(Q)rm -rf $(call objectify, $(clean-dirs))
0273 
0274 # Declare the contents of the .PHONY variable as phony.  We keep that
0275 # information in a variable se we can use it in if_changed and friends.
0276 
0277 .PHONY: $(PHONY)