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