xref: /openbmc/linux/Documentation/conf.py (revision be2b81b5)
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
18import shutil
19
20# helper
21# ------
22
23def have_command(cmd):
24    """Search ``cmd`` in the ``PATH`` environment.
25
26    If found, return True.
27    If not found, return False.
28    """
29    return shutil.which(cmd) is not None
30
31# Get Sphinx version
32major, minor, patch = sphinx.version_info[:3]
33
34
35# If extensions (or modules to document with autodoc) are in another directory,
36# add these directories to sys.path here. If the directory is relative to the
37# documentation root, use os.path.abspath to make it absolute, like shown here.
38sys.path.insert(0, os.path.abspath('sphinx'))
39from load_config import loadConfig
40
41# -- General configuration ------------------------------------------------
42
43# If your documentation needs a minimal Sphinx version, state it here.
44needs_sphinx = '1.7'
45
46# Add any Sphinx extension module names here, as strings. They can be
47# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
48# ones.
49extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include',
50              'kfigure', 'sphinx.ext.ifconfig', 'automarkup',
51              'maintainers_include', 'sphinx.ext.autosectionlabel',
52              'kernel_abi', 'kernel_feat']
53
54if major >= 3:
55    if (major > 3) or (minor > 0 or patch >= 2):
56        # Sphinx c function parser is more pedantic with regards to type
57        # checking. Due to that, having macros at c:function cause problems.
58        # Those needed to be scaped by using c_id_attributes[] array
59        c_id_attributes = [
60            # GCC Compiler types not parsed by Sphinx:
61            "__restrict__",
62
63            # include/linux/compiler_types.h:
64            "__iomem",
65            "__kernel",
66            "noinstr",
67            "notrace",
68            "__percpu",
69            "__rcu",
70            "__user",
71
72            # include/linux/compiler_attributes.h:
73            "__alias",
74            "__aligned",
75            "__aligned_largest",
76            "__always_inline",
77            "__assume_aligned",
78            "__cold",
79            "__attribute_const__",
80            "__copy",
81            "__pure",
82            "__designated_init",
83            "__visible",
84            "__printf",
85            "__scanf",
86            "__gnu_inline",
87            "__malloc",
88            "__mode",
89            "__no_caller_saved_registers",
90            "__noclone",
91            "__nonstring",
92            "__noreturn",
93            "__packed",
94            "__pure",
95            "__section",
96            "__always_unused",
97            "__maybe_unused",
98            "__used",
99            "__weak",
100            "noinline",
101            "__fix_address",
102
103            # include/linux/memblock.h:
104            "__init_memblock",
105            "__meminit",
106
107            # include/linux/init.h:
108            "__init",
109            "__ref",
110
111            # include/linux/linkage.h:
112            "asmlinkage",
113        ]
114
115else:
116    extensions.append('cdomain')
117
118# Ensure that autosectionlabel will produce unique names
119autosectionlabel_prefix_document = True
120autosectionlabel_maxdepth = 2
121
122# Load math renderer:
123# For html builder, load imgmath only when its dependencies are met.
124# mathjax is the default math renderer since Sphinx 1.8.
125have_latex =  have_command('latex')
126have_dvipng = have_command('dvipng')
127load_imgmath = have_latex and have_dvipng
128
129# Respect SPHINX_IMGMATH (for html docs only)
130if 'SPHINX_IMGMATH' in os.environ:
131    env_sphinx_imgmath = os.environ['SPHINX_IMGMATH']
132    if 'yes' in env_sphinx_imgmath:
133        load_imgmath = True
134    elif 'no' in env_sphinx_imgmath:
135        load_imgmath = False
136    else:
137        sys.stderr.write("Unknown env SPHINX_IMGMATH=%s ignored.\n" % env_sphinx_imgmath)
138
139# Always load imgmath for Sphinx <1.8 or for epub docs
140load_imgmath = (load_imgmath or (major == 1 and minor < 8)
141                or 'epub' in sys.argv)
142
143if load_imgmath:
144    extensions.append("sphinx.ext.imgmath")
145    math_renderer = 'imgmath'
146else:
147    math_renderer = 'mathjax'
148
149# Add any paths that contain templates here, relative to this directory.
150templates_path = ['_templates']
151
152# The suffix(es) of source filenames.
153# You can specify multiple suffix as a list of string:
154# source_suffix = ['.rst', '.md']
155source_suffix = '.rst'
156
157# The encoding of source files.
158#source_encoding = 'utf-8-sig'
159
160# The master toctree document.
161master_doc = 'index'
162
163# General information about the project.
164project = 'The Linux Kernel'
165copyright = 'The kernel development community'
166author = 'The kernel development community'
167
168# The version info for the project you're documenting, acts as replacement for
169# |version| and |release|, also used in various other places throughout the
170# built documents.
171#
172# In a normal build, version and release are are set to KERNELVERSION and
173# KERNELRELEASE, respectively, from the Makefile via Sphinx command line
174# arguments.
175#
176# The following code tries to extract the information by reading the Makefile,
177# when Sphinx is run directly (e.g. by Read the Docs).
178try:
179    makefile_version = None
180    makefile_patchlevel = None
181    for line in open('../Makefile'):
182        key, val = [x.strip() for x in line.split('=', 2)]
183        if key == 'VERSION':
184            makefile_version = val
185        elif key == 'PATCHLEVEL':
186            makefile_patchlevel = val
187        if makefile_version and makefile_patchlevel:
188            break
189except:
190    pass
191finally:
192    if makefile_version and makefile_patchlevel:
193        version = release = makefile_version + '.' + makefile_patchlevel
194    else:
195        version = release = "unknown version"
196
197#
198# HACK: there seems to be no easy way for us to get at the version and
199# release information passed in from the makefile...so go pawing through the
200# command-line options and find it for ourselves.
201#
202def get_cline_version():
203    c_version = c_release = ''
204    for arg in sys.argv:
205        if arg.startswith('version='):
206            c_version = arg[8:]
207        elif arg.startswith('release='):
208            c_release = arg[8:]
209    if c_version:
210        if c_release:
211            return c_version + '-' + c_release
212        return c_version
213    return version # Whatever we came up with before
214
215# The language for content autogenerated by Sphinx. Refer to documentation
216# for a list of supported languages.
217#
218# This is also used if you do content translation via gettext catalogs.
219# Usually you set "language" from the command line for these cases.
220language = 'en'
221
222# There are two options for replacing |today|: either, you set today to some
223# non-false value, then it is used:
224#today = ''
225# Else, today_fmt is used as the format for a strftime call.
226#today_fmt = '%B %d, %Y'
227
228# List of patterns, relative to source directory, that match files and
229# directories to ignore when looking for source files.
230exclude_patterns = ['output']
231
232# The reST default role (used for this markup: `text`) to use for all
233# documents.
234#default_role = None
235
236# If true, '()' will be appended to :func: etc. cross-reference text.
237#add_function_parentheses = True
238
239# If true, the current module name will be prepended to all description
240# unit titles (such as .. function::).
241#add_module_names = True
242
243# If true, sectionauthor and moduleauthor directives will be shown in the
244# output. They are ignored by default.
245#show_authors = False
246
247# The name of the Pygments (syntax highlighting) style to use.
248pygments_style = 'sphinx'
249
250# A list of ignored prefixes for module index sorting.
251#modindex_common_prefix = []
252
253# If true, keep warnings as "system message" paragraphs in the built documents.
254#keep_warnings = False
255
256# If true, `todo` and `todoList` produce output, else they produce nothing.
257todo_include_todos = False
258
259primary_domain = 'c'
260highlight_language = 'none'
261
262# -- Options for HTML output ----------------------------------------------
263
264# The theme to use for HTML and HTML Help pages.  See the documentation for
265# a list of builtin themes.
266
267# Default theme
268html_theme = 'alabaster'
269html_css_files = []
270
271if "DOCS_THEME" in os.environ:
272    html_theme = os.environ["DOCS_THEME"]
273
274if html_theme == 'sphinx_rtd_theme' or html_theme == 'sphinx_rtd_dark_mode':
275    # Read the Docs theme
276    try:
277        import sphinx_rtd_theme
278        html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
279
280        # Add any paths that contain custom static files (such as style sheets) here,
281        # relative to this directory. They are copied after the builtin static files,
282        # so a file named "default.css" will overwrite the builtin "default.css".
283        html_css_files = [
284            'theme_overrides.css',
285        ]
286
287        # Read the Docs dark mode override theme
288        if html_theme == 'sphinx_rtd_dark_mode':
289            try:
290                import sphinx_rtd_dark_mode
291                extensions.append('sphinx_rtd_dark_mode')
292            except ImportError:
293                html_theme == 'sphinx_rtd_theme'
294
295        if html_theme == 'sphinx_rtd_theme':
296                # Add color-specific RTD normal mode
297                html_css_files.append('theme_rtd_colors.css')
298
299        html_theme_options = {
300            'navigation_depth': -1,
301        }
302
303    except ImportError:
304        html_theme = 'alabaster'
305
306if "DOCS_CSS" in os.environ:
307    css = os.environ["DOCS_CSS"].split(" ")
308
309    for l in css:
310        html_css_files.append(l)
311
312if major <= 1 and minor < 8:
313    html_context = {
314        'css_files': [],
315    }
316
317    for l in html_css_files:
318        html_context['css_files'].append('_static/' + l)
319
320if  html_theme == 'alabaster':
321    html_theme_options = {
322        'description': get_cline_version(),
323        'page_width': '65em',
324        'sidebar_width': '15em',
325        'font_size': 'inherit',
326        'font_family': 'serif',
327    }
328
329sys.stderr.write("Using %s theme\n" % html_theme)
330
331# Add any paths that contain custom static files (such as style sheets) here,
332# relative to this directory. They are copied after the builtin static files,
333# so a file named "default.css" will overwrite the builtin "default.css".
334html_static_path = ['sphinx-static']
335
336# If true, SmartyPants will be used to convert quotes and dashes to
337# typographically correct entities.
338html_use_smartypants = False
339
340# Custom sidebar templates, maps document names to template names.
341# Note that the RTD theme ignores this
342html_sidebars = { '**': ["about.html", 'searchbox.html', 'localtoc.html', 'sourcelink.html']}
343
344# Output file base name for HTML help builder.
345htmlhelp_basename = 'TheLinuxKerneldoc'
346
347# -- Options for LaTeX output ---------------------------------------------
348
349latex_elements = {
350    # The paper size ('letterpaper' or 'a4paper').
351    'papersize': 'a4paper',
352
353    # The font size ('10pt', '11pt' or '12pt').
354    'pointsize': '11pt',
355
356    # Latex figure (float) alignment
357    #'figure_align': 'htbp',
358
359    # Don't mangle with UTF-8 chars
360    'inputenc': '',
361    'utf8extra': '',
362
363    # Set document margins
364    'sphinxsetup': '''
365        hmargin=0.5in, vmargin=1in,
366        parsedliteralwraps=true,
367        verbatimhintsturnover=false,
368    ''',
369
370    # For CJK One-half spacing, need to be in front of hyperref
371    'extrapackages': r'\usepackage{setspace}',
372
373    # Additional stuff for the LaTeX preamble.
374    'preamble': '''
375        % Use some font with UTF-8 support with XeLaTeX
376        \\usepackage{fontspec}
377        \\setsansfont{DejaVu Sans}
378        \\setromanfont{DejaVu Serif}
379        \\setmonofont{DejaVu Sans Mono}
380    ''',
381}
382
383# Fix reference escape troubles with Sphinx 1.4.x
384if major == 1:
385    latex_elements['preamble']  += '\\renewcommand*{\\DUrole}[2]{ #2 }\n'
386
387
388# Load kerneldoc specific LaTeX settings
389latex_elements['preamble'] += '''
390        % Load kerneldoc specific LaTeX settings
391	\\input{kerneldoc-preamble.sty}
392'''
393
394# With Sphinx 1.6, it is possible to change the Bg color directly
395# by using:
396#	\definecolor{sphinxnoteBgColor}{RGB}{204,255,255}
397#	\definecolor{sphinxwarningBgColor}{RGB}{255,204,204}
398#	\definecolor{sphinxattentionBgColor}{RGB}{255,255,204}
399#	\definecolor{sphinximportantBgColor}{RGB}{192,255,204}
400#
401# However, it require to use sphinx heavy box with:
402#
403#	\renewenvironment{sphinxlightbox} {%
404#		\\begin{sphinxheavybox}
405#	}
406#		\\end{sphinxheavybox}
407#	}
408#
409# Unfortunately, the implementation is buggy: if a note is inside a
410# table, it isn't displayed well. So, for now, let's use boring
411# black and white notes.
412
413# Grouping the document tree into LaTeX files. List of tuples
414# (source start file, target name, title,
415#  author, documentclass [howto, manual, or own class]).
416# Sorted in alphabetical order
417latex_documents = [
418]
419
420# Add all other index files from Documentation/ subdirectories
421for fn in os.listdir('.'):
422    doc = os.path.join(fn, "index")
423    if os.path.exists(doc + ".rst"):
424        has = False
425        for l in latex_documents:
426            if l[0] == doc:
427                has = True
428                break
429        if not has:
430            latex_documents.append((doc, fn + '.tex',
431                                    'Linux %s Documentation' % fn.capitalize(),
432                                    'The kernel development community',
433                                    'manual'))
434
435# The name of an image file (relative to this directory) to place at the top of
436# the title page.
437#latex_logo = None
438
439# For "manual" documents, if this is true, then toplevel headings are parts,
440# not chapters.
441#latex_use_parts = False
442
443# If true, show page references after internal links.
444#latex_show_pagerefs = False
445
446# If true, show URL addresses after external links.
447#latex_show_urls = False
448
449# Documents to append as an appendix to all manuals.
450#latex_appendices = []
451
452# If false, no module index is generated.
453#latex_domain_indices = True
454
455# Additional LaTeX stuff to be copied to build directory
456latex_additional_files = [
457    'sphinx/kerneldoc-preamble.sty',
458]
459
460
461# -- Options for manual page output ---------------------------------------
462
463# One entry per manual page. List of tuples
464# (source start file, name, description, authors, manual section).
465man_pages = [
466    (master_doc, 'thelinuxkernel', 'The Linux Kernel Documentation',
467     [author], 1)
468]
469
470# If true, show URL addresses after external links.
471#man_show_urls = False
472
473
474# -- Options for Texinfo output -------------------------------------------
475
476# Grouping the document tree into Texinfo files. List of tuples
477# (source start file, target name, title, author,
478#  dir menu entry, description, category)
479texinfo_documents = [
480    (master_doc, 'TheLinuxKernel', 'The Linux Kernel Documentation',
481     author, 'TheLinuxKernel', 'One line description of project.',
482     'Miscellaneous'),
483]
484
485# -- Options for Epub output ----------------------------------------------
486
487# Bibliographic Dublin Core info.
488epub_title = project
489epub_author = author
490epub_publisher = author
491epub_copyright = copyright
492
493# A list of files that should not be packed into the epub file.
494epub_exclude_files = ['search.html']
495
496#=======
497# rst2pdf
498#
499# Grouping the document tree into PDF files. List of tuples
500# (source start file, target name, title, author, options).
501#
502# See the Sphinx chapter of https://ralsina.me/static/manual.pdf
503#
504# FIXME: Do not add the index file here; the result will be too big. Adding
505# multiple PDF files here actually tries to get the cross-referencing right
506# *between* PDF files.
507pdf_documents = [
508    ('kernel-documentation', u'Kernel', u'Kernel', u'J. Random Bozo'),
509]
510
511# kernel-doc extension configuration for running Sphinx directly (e.g. by Read
512# the Docs). In a normal build, these are supplied from the Makefile via command
513# line arguments.
514kerneldoc_bin = '../scripts/kernel-doc'
515kerneldoc_srctree = '..'
516
517# ------------------------------------------------------------------------------
518# Since loadConfig overwrites settings from the global namespace, it has to be
519# the last statement in the conf.py file
520# ------------------------------------------------------------------------------
521loadConfig(globals())
522