xref: /openbmc/linux/Documentation/conf.py (revision f0168042)
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.  This will convert "--" to "—",
349# which is not always what we want, so disable it.
350smartquotes = False
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    # For CJK One-half spacing, need to be in front of hyperref
387    'extrapackages': r'\usepackage{setspace}',
388
389    # Additional stuff for the LaTeX preamble.
390    'preamble': '''
391        % Use some font with UTF-8 support with XeLaTeX
392        \\usepackage{fontspec}
393        \\setsansfont{DejaVu Sans}
394        \\setromanfont{DejaVu Serif}
395        \\setmonofont{DejaVu Sans Mono}
396    ''',
397}
398
399# Fix reference escape troubles with Sphinx 1.4.x
400if major == 1:
401    latex_elements['preamble']  += '\\renewcommand*{\\DUrole}[2]{ #2 }\n'
402
403
404# Load kerneldoc specific LaTeX settings
405latex_elements['preamble'] += '''
406        % Load kerneldoc specific LaTeX settings
407	\\input{kerneldoc-preamble.sty}
408'''
409
410# With Sphinx 1.6, it is possible to change the Bg color directly
411# by using:
412#	\definecolor{sphinxnoteBgColor}{RGB}{204,255,255}
413#	\definecolor{sphinxwarningBgColor}{RGB}{255,204,204}
414#	\definecolor{sphinxattentionBgColor}{RGB}{255,255,204}
415#	\definecolor{sphinximportantBgColor}{RGB}{192,255,204}
416#
417# However, it require to use sphinx heavy box with:
418#
419#	\renewenvironment{sphinxlightbox} {%
420#		\\begin{sphinxheavybox}
421#	}
422#		\\end{sphinxheavybox}
423#	}
424#
425# Unfortunately, the implementation is buggy: if a note is inside a
426# table, it isn't displayed well. So, for now, let's use boring
427# black and white notes.
428
429# Grouping the document tree into LaTeX files. List of tuples
430# (source start file, target name, title,
431#  author, documentclass [howto, manual, or own class]).
432# Sorted in alphabetical order
433latex_documents = [
434]
435
436# Add all other index files from Documentation/ subdirectories
437for fn in os.listdir('.'):
438    doc = os.path.join(fn, "index")
439    if os.path.exists(doc + ".rst"):
440        has = False
441        for l in latex_documents:
442            if l[0] == doc:
443                has = True
444                break
445        if not has:
446            latex_documents.append((doc, fn + '.tex',
447                                    'Linux %s Documentation' % fn.capitalize(),
448                                    'The kernel development community',
449                                    'manual'))
450
451# The name of an image file (relative to this directory) to place at the top of
452# the title page.
453#latex_logo = None
454
455# For "manual" documents, if this is true, then toplevel headings are parts,
456# not chapters.
457#latex_use_parts = False
458
459# If true, show page references after internal links.
460#latex_show_pagerefs = False
461
462# If true, show URL addresses after external links.
463#latex_show_urls = False
464
465# Documents to append as an appendix to all manuals.
466#latex_appendices = []
467
468# If false, no module index is generated.
469#latex_domain_indices = True
470
471# Additional LaTeX stuff to be copied to build directory
472latex_additional_files = [
473    'sphinx/kerneldoc-preamble.sty',
474]
475
476
477# -- Options for manual page output ---------------------------------------
478
479# One entry per manual page. List of tuples
480# (source start file, name, description, authors, manual section).
481man_pages = [
482    (master_doc, 'thelinuxkernel', 'The Linux Kernel Documentation',
483     [author], 1)
484]
485
486# If true, show URL addresses after external links.
487#man_show_urls = False
488
489
490# -- Options for Texinfo output -------------------------------------------
491
492# Grouping the document tree into Texinfo files. List of tuples
493# (source start file, target name, title, author,
494#  dir menu entry, description, category)
495texinfo_documents = [
496    (master_doc, 'TheLinuxKernel', 'The Linux Kernel Documentation',
497     author, 'TheLinuxKernel', 'One line description of project.',
498     'Miscellaneous'),
499]
500
501# -- Options for Epub output ----------------------------------------------
502
503# Bibliographic Dublin Core info.
504epub_title = project
505epub_author = author
506epub_publisher = author
507epub_copyright = copyright
508
509# A list of files that should not be packed into the epub file.
510epub_exclude_files = ['search.html']
511
512#=======
513# rst2pdf
514#
515# Grouping the document tree into PDF files. List of tuples
516# (source start file, target name, title, author, options).
517#
518# See the Sphinx chapter of https://ralsina.me/static/manual.pdf
519#
520# FIXME: Do not add the index file here; the result will be too big. Adding
521# multiple PDF files here actually tries to get the cross-referencing right
522# *between* PDF files.
523pdf_documents = [
524    ('kernel-documentation', u'Kernel', u'Kernel', u'J. Random Bozo'),
525]
526
527# kernel-doc extension configuration for running Sphinx directly (e.g. by Read
528# the Docs). In a normal build, these are supplied from the Makefile via command
529# line arguments.
530kerneldoc_bin = '../scripts/kernel-doc'
531kerneldoc_srctree = '..'
532
533# ------------------------------------------------------------------------------
534# Since loadConfig overwrites settings from the global namespace, it has to be
535# the last statement in the conf.py file
536# ------------------------------------------------------------------------------
537loadConfig(globals())
538