xref: /linux/Documentation/conf.py (revision 75b1a8f9d62e50f05d0e4e9f3c8bcde32527ffc1)
1# -*- coding: utf-8 -*-
2#
3# The Linux Kernel documentation build configuration file, created by
4# sphinx-quickstart on Fri Feb 12 13:51:46 2016.
5#
6# This file is execfile()d with the current directory set to its
7# containing dir.
8#
9# Note that not all possible configuration values are present in this
10# autogenerated file.
11#
12# All configuration values have a default; values that are commented out
13# serve to show the default.
14
15import sys
16import os
17import sphinx
18
19from subprocess import check_output
20
21# Get Sphinx version
22major, minor, patch = sphinx.version_info[:3]
23
24
25# If extensions (or modules to document with autodoc) are in another directory,
26# add these directories to sys.path here. If the directory is relative to the
27# documentation root, use os.path.abspath to make it absolute, like shown here.
28sys.path.insert(0, os.path.abspath('sphinx'))
29from load_config import loadConfig
30
31# -- General configuration ------------------------------------------------
32
33# If your documentation needs a minimal Sphinx version, state it here.
34needs_sphinx = '1.3'
35
36# Add any Sphinx extension module names here, as strings. They can be
37# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
38# ones.
39extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include',
40              'kfigure', 'sphinx.ext.ifconfig', 'automarkup',
41              'maintainers_include', 'sphinx.ext.autosectionlabel',
42              'kernel_abi', 'kernel_feat']
43
44#
45# cdomain is badly broken in Sphinx 3+.  Leaving it out generates *most*
46# of the docs correctly, but not all.  Scream bloody murder but allow
47# the process to proceed; hopefully somebody will fix this properly soon.
48#
49if major >= 3:
50    sys.stderr.write('''WARNING: The kernel documentation build process
51        support for Sphinx v3.0 and above is brand new. Be prepared for
52        possible issues in the generated output.
53        ''')
54    if (major > 3) or (minor > 0 or patch >= 2):
55        # Sphinx c function parser is more pedantic with regards to type
56        # checking. Due to that, having macros at c:function cause problems.
57        # Those needed to be scaped by using c_id_attributes[] array
58        c_id_attributes = [
59            # GCC Compiler types not parsed by Sphinx:
60            "__restrict__",
61
62            # include/linux/compiler_types.h:
63            "__iomem",
64            "__kernel",
65            "noinstr",
66            "notrace",
67            "__percpu",
68            "__rcu",
69            "__user",
70
71            # include/linux/compiler_attributes.h:
72            "__alias",
73            "__aligned",
74            "__aligned_largest",
75            "__always_inline",
76            "__assume_aligned",
77            "__cold",
78            "__attribute_const__",
79            "__copy",
80            "__pure",
81            "__designated_init",
82            "__visible",
83            "__printf",
84            "__scanf",
85            "__gnu_inline",
86            "__malloc",
87            "__mode",
88            "__no_caller_saved_registers",
89            "__noclone",
90            "__nonstring",
91            "__noreturn",
92            "__packed",
93            "__pure",
94            "__section",
95            "__always_unused",
96            "__maybe_unused",
97            "__used",
98            "__weak",
99            "noinline",
100
101            # include/linux/memblock.h:
102            "__init_memblock",
103            "__meminit",
104
105            # include/linux/init.h:
106            "__init",
107            "__ref",
108
109            # include/linux/linkage.h:
110            "asmlinkage",
111        ]
112
113else:
114    extensions.append('cdomain')
115    if major == 1 and minor < 7:
116        sys.stderr.write('WARNING: Sphinx 1.7 or greater will be required as of '
117                         'the 5.12 release\n')
118
119# Ensure that autosectionlabel will produce unique names
120autosectionlabel_prefix_document = True
121autosectionlabel_maxdepth = 2
122
123# The name of the math extension changed on Sphinx 1.4
124if (major == 1 and minor > 3) or (major > 1):
125    extensions.append("sphinx.ext.imgmath")
126else:
127    extensions.append("sphinx.ext.pngmath")
128
129# Add any paths that contain templates here, relative to this directory.
130templates_path = ['_templates']
131
132# The suffix(es) of source filenames.
133# You can specify multiple suffix as a list of string:
134# source_suffix = ['.rst', '.md']
135source_suffix = '.rst'
136
137# The encoding of source files.
138#source_encoding = 'utf-8-sig'
139
140# The master toctree document.
141master_doc = 'index'
142
143# General information about the project.
144project = 'The Linux Kernel'
145copyright = 'The kernel development community'
146author = 'The kernel development community'
147
148# The version info for the project you're documenting, acts as replacement for
149# |version| and |release|, also used in various other places throughout the
150# built documents.
151#
152# In a normal build, version and release are are set to KERNELVERSION and
153# KERNELRELEASE, respectively, from the Makefile via Sphinx command line
154# arguments.
155#
156# The following code tries to extract the information by reading the Makefile,
157# when Sphinx is run directly (e.g. by Read the Docs).
158try:
159    makefile_version = None
160    makefile_patchlevel = None
161    for line in open('../Makefile'):
162        key, val = [x.strip() for x in line.split('=', 2)]
163        if key == 'VERSION':
164            makefile_version = val
165        elif key == 'PATCHLEVEL':
166            makefile_patchlevel = val
167        if makefile_version and makefile_patchlevel:
168            break
169except:
170    pass
171finally:
172    if makefile_version and makefile_patchlevel:
173        version = release = makefile_version + '.' + makefile_patchlevel
174    else:
175        version = release = "unknown version"
176
177# The language for content autogenerated by Sphinx. Refer to documentation
178# for a list of supported languages.
179#
180# This is also used if you do content translation via gettext catalogs.
181# Usually you set "language" from the command line for these cases.
182language = None
183
184# There are two options for replacing |today|: either, you set today to some
185# non-false value, then it is used:
186#today = ''
187# Else, today_fmt is used as the format for a strftime call.
188#today_fmt = '%B %d, %Y'
189
190# List of patterns, relative to source directory, that match files and
191# directories to ignore when looking for source files.
192exclude_patterns = ['output']
193
194# The reST default role (used for this markup: `text`) to use for all
195# documents.
196#default_role = None
197
198# If true, '()' will be appended to :func: etc. cross-reference text.
199#add_function_parentheses = True
200
201# If true, the current module name will be prepended to all description
202# unit titles (such as .. function::).
203#add_module_names = True
204
205# If true, sectionauthor and moduleauthor directives will be shown in the
206# output. They are ignored by default.
207#show_authors = False
208
209# The name of the Pygments (syntax highlighting) style to use.
210pygments_style = 'sphinx'
211
212# A list of ignored prefixes for module index sorting.
213#modindex_common_prefix = []
214
215# If true, keep warnings as "system message" paragraphs in the built documents.
216#keep_warnings = False
217
218# If true, `todo` and `todoList` produce output, else they produce nothing.
219todo_include_todos = False
220
221primary_domain = 'c'
222highlight_language = 'none'
223
224# -- Options for HTML output ----------------------------------------------
225
226# The theme to use for HTML and HTML Help pages.  See the documentation for
227# a list of builtin themes.
228
229# The Read the Docs theme is available from
230# - https://github.com/snide/sphinx_rtd_theme
231# - https://pypi.python.org/pypi/sphinx_rtd_theme
232# - python-sphinx-rtd-theme package (on Debian)
233try:
234    import sphinx_rtd_theme
235    html_theme = 'sphinx_rtd_theme'
236    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
237except ImportError:
238    sys.stderr.write('Warning: The Sphinx \'sphinx_rtd_theme\' HTML theme was not found. Make sure you have the theme installed to produce pretty HTML output. Falling back to the default theme.\n')
239
240# Theme options are theme-specific and customize the look and feel of a theme
241# further.  For a list of options available for each theme, see the
242# documentation.
243#html_theme_options = {}
244
245# Add any paths that contain custom themes here, relative to this directory.
246#html_theme_path = []
247
248# The name for this set of Sphinx documents.  If None, it defaults to
249# "<project> v<release> documentation".
250#html_title = None
251
252# A shorter title for the navigation bar.  Default is the same as html_title.
253#html_short_title = None
254
255# The name of an image file (relative to this directory) to place at the top
256# of the sidebar.
257#html_logo = None
258
259# The name of an image file (within the static path) to use as favicon of the
260# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
261# pixels large.
262#html_favicon = None
263
264# Add any paths that contain custom static files (such as style sheets) here,
265# relative to this directory. They are copied after the builtin static files,
266# so a file named "default.css" will overwrite the builtin "default.css".
267
268html_static_path = ['sphinx-static']
269
270html_context = {
271    'css_files': [
272        '_static/theme_overrides.css',
273    ],
274}
275
276# Add any extra paths that contain custom files (such as robots.txt or
277# .htaccess) here, relative to this directory. These files are copied
278# directly to the root of the documentation.
279#html_extra_path = []
280
281# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
282# using the given strftime format.
283#html_last_updated_fmt = '%b %d, %Y'
284
285# If true, SmartyPants will be used to convert quotes and dashes to
286# typographically correct entities.
287html_use_smartypants = False
288
289# Custom sidebar templates, maps document names to template names.
290#html_sidebars = {}
291
292# Additional templates that should be rendered to pages, maps page names to
293# template names.
294#html_additional_pages = {}
295
296# If false, no module index is generated.
297#html_domain_indices = True
298
299# If false, no index is generated.
300#html_use_index = True
301
302# If true, the index is split into individual pages for each letter.
303#html_split_index = False
304
305# If true, links to the reST sources are added to the pages.
306#html_show_sourcelink = True
307
308# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
309#html_show_sphinx = True
310
311# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
312#html_show_copyright = True
313
314# If true, an OpenSearch description file will be output, and all pages will
315# contain a <link> tag referring to it.  The value of this option must be the
316# base URL from which the finished HTML is served.
317#html_use_opensearch = ''
318
319# This is the file name suffix for HTML files (e.g. ".xhtml").
320#html_file_suffix = None
321
322# Language to be used for generating the HTML full-text search index.
323# Sphinx supports the following languages:
324#   'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
325#   'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
326#html_search_language = 'en'
327
328# A dictionary with options for the search language support, empty by default.
329# Now only 'ja' uses this config value
330#html_search_options = {'type': 'default'}
331
332# The name of a javascript file (relative to the configuration directory) that
333# implements a search results scorer. If empty, the default will be used.
334#html_search_scorer = 'scorer.js'
335
336# Output file base name for HTML help builder.
337htmlhelp_basename = 'TheLinuxKerneldoc'
338
339# -- Options for LaTeX output ---------------------------------------------
340
341latex_elements = {
342# The paper size ('letterpaper' or 'a4paper').
343'papersize': 'a4paper',
344
345# The font size ('10pt', '11pt' or '12pt').
346'pointsize': '11pt',
347
348# Latex figure (float) alignment
349#'figure_align': 'htbp',
350
351# Don't mangle with UTF-8 chars
352'inputenc': '',
353'utf8extra': '',
354
355# Additional stuff for the LaTeX preamble.
356    'preamble': '''
357	% Use some font with UTF-8 support with XeLaTeX
358        \\usepackage{fontspec}
359        \\setsansfont{DejaVu Sans}
360        \\setromanfont{DejaVu Serif}
361        \\setmonofont{DejaVu Sans Mono}
362     '''
363}
364
365# At least one book (translations) may have Asian characters
366# with are only displayed if xeCJK is used
367
368cjk_cmd = check_output(['fc-list', '--format="%{family[0]}\n"']).decode('utf-8', 'ignore')
369if cjk_cmd.find("Noto Sans CJK SC") >= 0:
370    print ("enabling CJK for LaTeX builder")
371    latex_elements['preamble']  += '''
372	% This is needed for translations
373        \\usepackage{xeCJK}
374        \\setCJKmainfont{Noto Sans CJK SC}
375     '''
376
377# Fix reference escape troubles with Sphinx 1.4.x
378if major == 1 and minor > 3:
379    latex_elements['preamble']  += '\\renewcommand*{\\DUrole}[2]{ #2 }\n'
380
381if major == 1 and minor <= 4:
382    latex_elements['preamble']  += '\\usepackage[margin=0.5in, top=1in, bottom=1in]{geometry}'
383elif major == 1 and (minor > 5 or (minor == 5 and patch >= 3)):
384    latex_elements['sphinxsetup'] = 'hmargin=0.5in, vmargin=1in'
385    latex_elements['preamble']  += '\\fvset{fontsize=auto}\n'
386
387# Customize notice background colors on Sphinx < 1.6:
388if major == 1 and minor < 6:
389   latex_elements['preamble']  += '''
390        \\usepackage{ifthen}
391
392        % Put notes in color and let them be inside a table
393	\\definecolor{NoteColor}{RGB}{204,255,255}
394	\\definecolor{WarningColor}{RGB}{255,204,204}
395	\\definecolor{AttentionColor}{RGB}{255,255,204}
396	\\definecolor{ImportantColor}{RGB}{192,255,204}
397	\\definecolor{OtherColor}{RGB}{204,204,204}
398        \\newlength{\\mynoticelength}
399        \\makeatletter\\newenvironment{coloredbox}[1]{%
400	   \\setlength{\\fboxrule}{1pt}
401	   \\setlength{\\fboxsep}{7pt}
402	   \\setlength{\\mynoticelength}{\\linewidth}
403	   \\addtolength{\\mynoticelength}{-2\\fboxsep}
404	   \\addtolength{\\mynoticelength}{-2\\fboxrule}
405           \\begin{lrbox}{\\@tempboxa}\\begin{minipage}{\\mynoticelength}}{\\end{minipage}\\end{lrbox}%
406	   \\ifthenelse%
407	      {\\equal{\\py@noticetype}{note}}%
408	      {\\colorbox{NoteColor}{\\usebox{\\@tempboxa}}}%
409	      {%
410	         \\ifthenelse%
411	         {\\equal{\\py@noticetype}{warning}}%
412	         {\\colorbox{WarningColor}{\\usebox{\\@tempboxa}}}%
413		 {%
414	            \\ifthenelse%
415	            {\\equal{\\py@noticetype}{attention}}%
416	            {\\colorbox{AttentionColor}{\\usebox{\\@tempboxa}}}%
417		    {%
418	               \\ifthenelse%
419	               {\\equal{\\py@noticetype}{important}}%
420	               {\\colorbox{ImportantColor}{\\usebox{\\@tempboxa}}}%
421	               {\\colorbox{OtherColor}{\\usebox{\\@tempboxa}}}%
422		    }%
423		 }%
424	      }%
425        }\\makeatother
426
427        \\makeatletter
428        \\renewenvironment{notice}[2]{%
429          \\def\\py@noticetype{#1}
430          \\begin{coloredbox}{#1}
431          \\bf\\it
432          \\par\\strong{#2}
433          \\csname py@noticestart@#1\\endcsname
434        }
435	{
436          \\csname py@noticeend@\\py@noticetype\\endcsname
437          \\end{coloredbox}
438        }
439	\\makeatother
440
441     '''
442
443# With Sphinx 1.6, it is possible to change the Bg color directly
444# by using:
445#	\definecolor{sphinxnoteBgColor}{RGB}{204,255,255}
446#	\definecolor{sphinxwarningBgColor}{RGB}{255,204,204}
447#	\definecolor{sphinxattentionBgColor}{RGB}{255,255,204}
448#	\definecolor{sphinximportantBgColor}{RGB}{192,255,204}
449#
450# However, it require to use sphinx heavy box with:
451#
452#	\renewenvironment{sphinxlightbox} {%
453#		\\begin{sphinxheavybox}
454#	}
455#		\\end{sphinxheavybox}
456#	}
457#
458# Unfortunately, the implementation is buggy: if a note is inside a
459# table, it isn't displayed well. So, for now, let's use boring
460# black and white notes.
461
462# Grouping the document tree into LaTeX files. List of tuples
463# (source start file, target name, title,
464#  author, documentclass [howto, manual, or own class]).
465# Sorted in alphabetical order
466latex_documents = [
467]
468
469# Add all other index files from Documentation/ subdirectories
470for fn in os.listdir('.'):
471    doc = os.path.join(fn, "index")
472    if os.path.exists(doc + ".rst"):
473        has = False
474        for l in latex_documents:
475            if l[0] == doc:
476                has = True
477                break
478        if not has:
479            latex_documents.append((doc, fn + '.tex',
480                                    'Linux %s Documentation' % fn.capitalize(),
481                                    'The kernel development community',
482                                    'manual'))
483
484# The name of an image file (relative to this directory) to place at the top of
485# the title page.
486#latex_logo = None
487
488# For "manual" documents, if this is true, then toplevel headings are parts,
489# not chapters.
490#latex_use_parts = False
491
492# If true, show page references after internal links.
493#latex_show_pagerefs = False
494
495# If true, show URL addresses after external links.
496#latex_show_urls = False
497
498# Documents to append as an appendix to all manuals.
499#latex_appendices = []
500
501# If false, no module index is generated.
502#latex_domain_indices = True
503
504
505# -- Options for manual page output ---------------------------------------
506
507# One entry per manual page. List of tuples
508# (source start file, name, description, authors, manual section).
509man_pages = [
510    (master_doc, 'thelinuxkernel', 'The Linux Kernel Documentation',
511     [author], 1)
512]
513
514# If true, show URL addresses after external links.
515#man_show_urls = False
516
517
518# -- Options for Texinfo output -------------------------------------------
519
520# Grouping the document tree into Texinfo files. List of tuples
521# (source start file, target name, title, author,
522#  dir menu entry, description, category)
523texinfo_documents = [
524    (master_doc, 'TheLinuxKernel', 'The Linux Kernel Documentation',
525     author, 'TheLinuxKernel', 'One line description of project.',
526     'Miscellaneous'),
527]
528
529# Documents to append as an appendix to all manuals.
530#texinfo_appendices = []
531
532# If false, no module index is generated.
533#texinfo_domain_indices = True
534
535# How to display URL addresses: 'footnote', 'no', or 'inline'.
536#texinfo_show_urls = 'footnote'
537
538# If true, do not generate a @detailmenu in the "Top" node's menu.
539#texinfo_no_detailmenu = False
540
541
542# -- Options for Epub output ----------------------------------------------
543
544# Bibliographic Dublin Core info.
545epub_title = project
546epub_author = author
547epub_publisher = author
548epub_copyright = copyright
549
550# The basename for the epub file. It defaults to the project name.
551#epub_basename = project
552
553# The HTML theme for the epub output. Since the default themes are not
554# optimized for small screen space, using the same theme for HTML and epub
555# output is usually not wise. This defaults to 'epub', a theme designed to save
556# visual space.
557#epub_theme = 'epub'
558
559# The language of the text. It defaults to the language option
560# or 'en' if the language is not set.
561#epub_language = ''
562
563# The scheme of the identifier. Typical schemes are ISBN or URL.
564#epub_scheme = ''
565
566# The unique identifier of the text. This can be a ISBN number
567# or the project homepage.
568#epub_identifier = ''
569
570# A unique identification for the text.
571#epub_uid = ''
572
573# A tuple containing the cover image and cover page html template filenames.
574#epub_cover = ()
575
576# A sequence of (type, uri, title) tuples for the guide element of content.opf.
577#epub_guide = ()
578
579# HTML files that should be inserted before the pages created by sphinx.
580# The format is a list of tuples containing the path and title.
581#epub_pre_files = []
582
583# HTML files that should be inserted after the pages created by sphinx.
584# The format is a list of tuples containing the path and title.
585#epub_post_files = []
586
587# A list of files that should not be packed into the epub file.
588epub_exclude_files = ['search.html']
589
590# The depth of the table of contents in toc.ncx.
591#epub_tocdepth = 3
592
593# Allow duplicate toc entries.
594#epub_tocdup = True
595
596# Choose between 'default' and 'includehidden'.
597#epub_tocscope = 'default'
598
599# Fix unsupported image types using the Pillow.
600#epub_fix_images = False
601
602# Scale large images.
603#epub_max_image_width = 0
604
605# How to display URL addresses: 'footnote', 'no', or 'inline'.
606#epub_show_urls = 'inline'
607
608# If false, no index is generated.
609#epub_use_index = True
610
611#=======
612# rst2pdf
613#
614# Grouping the document tree into PDF files. List of tuples
615# (source start file, target name, title, author, options).
616#
617# See the Sphinx chapter of https://ralsina.me/static/manual.pdf
618#
619# FIXME: Do not add the index file here; the result will be too big. Adding
620# multiple PDF files here actually tries to get the cross-referencing right
621# *between* PDF files.
622pdf_documents = [
623    ('kernel-documentation', u'Kernel', u'Kernel', u'J. Random Bozo'),
624]
625
626# kernel-doc extension configuration for running Sphinx directly (e.g. by Read
627# the Docs). In a normal build, these are supplied from the Makefile via command
628# line arguments.
629kerneldoc_bin = '../scripts/kernel-doc'
630kerneldoc_srctree = '..'
631
632# ------------------------------------------------------------------------------
633# Since loadConfig overwrites settings from the global namespace, it has to be
634# the last statement in the conf.py file
635# ------------------------------------------------------------------------------
636loadConfig(globals())
637