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