| 1 | |
| 2 | |
| 3 |
|
| 4 | |
| 5 | The Linux Kernel documentation build configuration file.
|
| 6 |
|
| 7 |
|
| 8 | import os
|
| 9 | import shutil
|
| 10 | import sys
|
| 11 |
|
| 12 | from textwrap import dedent
|
| 13 |
|
| 14 | import sphinx
|
| 15 |
|
| 16 | |
| 17 | kern_doc_dir = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
|
| 19 | |
| 20 | sys.path.insert(0, os.path.join(kern_doc_dir, "sphinx"))
|
| 21 |
|
| 22 | |
| 23 | sys.path.append(os.path.join(kern_doc_dir, "..", "tools"))
|
| 24 | sys.path.append(os.path.join(kern_doc_dir, "..", "scripts"))
|
| 25 |
|
| 26 | |
| 27 | needs_sphinx = "3.4.3"
|
| 28 |
|
| 29 | |
| 30 | major, minor, patch = sphinx.version_info[:3] |
| 31 |
|
| 32 | |
| 33 | if (major < 5) or (major == 5 and minor < 1):
|
| 34 | has_include_patterns = False
|
| 35 | else:
|
| 36 | has_include_patterns = True
|
| 37 | |
| 38 | include_patterns = ["**.rst"]
|
| 39 |
|
| 40 | |
| 41 | exclude_patterns = []
|
| 42 |
|
| 43 | |
| 44 | dyn_include_patterns = []
|
| 45 | dyn_exclude_patterns = ["output", "sphinx-includes"]
|
| 46 |
|
| 47 | |
| 48 | |
| 49 | if has_include_patterns:
|
| 50 | dyn_include_patterns.append("netlink/specs/*.yaml")
|
| 51 | else:
|
| 52 | dyn_exclude_patterns.append("netlink/*.yaml")
|
| 53 | dyn_exclude_patterns.append("devicetree/bindings/**.yaml")
|
| 54 | dyn_exclude_patterns.append("core-api/kho/bindings/**.yaml")
|
| 55 |
|
| 56 | |
| 57 | manpages_url = 'https://man7.org/linux/man-pages/man{section}/{page}.{section}.html'
|
| 58 |
|
| 59 | |
| 60 | |
| 61 |
|
| 62 | def config_init(app, config):
|
| 63 | |
| 64 | Initialize path-dependent variables
|
| 65 |
|
| 66 | On Sphinx, all directories are relative to what it is passed as
|
| 67 | SOURCEDIR parameter for sphinx-build. Due to that, all patterns
|
| 68 | that have directory names on it need to be dynamically set, after
|
| 69 | converting them to a relative path.
|
| 70 |
|
| 71 | As Sphinx doesn't include any patterns outside SOURCEDIR, we should
|
| 72 | exclude relative patterns that start with "../".
|
| 73 |
|
| 74 |
|
| 75 | |
| 76 | if has_include_patterns:
|
| 77 | for p in dyn_include_patterns:
|
| 78 | full = os.path.join(kern_doc_dir, p)
|
| 79 |
|
| 80 | rel_path = os.path.relpath(full, start=app.srcdir)
|
| 81 | if rel_path.startswith("../"):
|
| 82 | continue
|
| 83 |
|
| 84 | config.include_patterns.append(rel_path)
|
| 85 |
|
| 86 | |
| 87 | for p in dyn_exclude_patterns:
|
| 88 | full = os.path.join(kern_doc_dir, p)
|
| 89 |
|
| 90 | rel_path = os.path.relpath(full, start=app.srcdir)
|
| 91 | if rel_path.startswith("../"):
|
| 92 | continue
|
| 93 |
|
| 94 | config.exclude_patterns.append(rel_path)
|
| 95 |
|
| 96 | |
| 97 | |
| 98 |
|
| 99 | |
| 100 | if not os.path.samefile(kern_doc_dir, app.srcdir):
|
| 101 | |
| 102 | tags.add("subproject")
|
| 103 |
|
| 104 | |
| 105 | doc = os.path.basename(app.srcdir)
|
| 106 | fname = "index"
|
| 107 | if os.path.exists(os.path.join(app.srcdir, fname + ".rst")):
|
| 108 | latex_documents.append((fname, doc + ".tex",
|
| 109 | "Linux %s Documentation" % doc.capitalize(),
|
| 110 | "The kernel development community",
|
| 111 | "manual"))
|
| 112 | return
|
| 113 |
|
| 114 | |
| 115 | |
| 116 | for doc in os.listdir(app.srcdir):
|
| 117 | fname = os.path.join(doc, "index")
|
| 118 | if not os.path.exists(os.path.join(app.srcdir, fname + ".rst")):
|
| 119 | continue
|
| 120 |
|
| 121 | has = False
|
| 122 | for l in latex_documents:
|
| 123 | if l[0] == fname:
|
| 124 | has = True
|
| 125 | break
|
| 126 |
|
| 127 | if not has:
|
| 128 | latex_documents.append((fname, doc + ".tex",
|
| 129 | "Linux %s Documentation" % doc.capitalize(),
|
| 130 | "The kernel development community",
|
| 131 | "manual"))
|
| 132 |
|
| 133 | |
| 134 | |
| 135 |
|
| 136 |
|
| 137 | def have_command(cmd):
|
| 138 | |
| 139 |
|
| 140 | If found, return True.
|
| 141 | If not found, return False.
|
| 142 |
|
| 143 | return shutil.which(cmd) is not None
|
| 144 |
|
| 145 |
|
| 146 | |
| 147 |
|
| 148 | |
| 149 | extensions = [
|
| 150 | "automarkup",
|
| 151 | "kernel_abi",
|
| 152 | "kerneldoc",
|
| 153 | "kernel_feat",
|
| 154 | "kernel_include",
|
| 155 | "kfigure",
|
| 156 | "maintainers_include",
|
| 157 | "parser_yaml",
|
| 158 | "rstFlatTable",
|
| 159 | "sphinx.ext.autodoc",
|
| 160 | "sphinx.ext.autosectionlabel",
|
| 161 | "sphinx.ext.ifconfig",
|
| 162 | "translations",
|
| 163 | ]
|
| 164 | |
| 165 | |
| 166 | |
| 167 | c_id_attributes = [
|
| 168 | |
| 169 | "__restrict__",
|
| 170 |
|
| 171 | |
| 172 | "__iomem",
|
| 173 | "__kernel",
|
| 174 | "noinstr",
|
| 175 | "notrace",
|
| 176 | "__percpu",
|
| 177 | "__rcu",
|
| 178 | "__user",
|
| 179 | "__force",
|
| 180 | "__counted_by_le",
|
| 181 | "__counted_by_be",
|
| 182 |
|
| 183 | |
| 184 | "__alias",
|
| 185 | "__aligned",
|
| 186 | "__aligned_largest",
|
| 187 | "__always_inline",
|
| 188 | "__assume_aligned",
|
| 189 | "__cold",
|
| 190 | "__attribute_const__",
|
| 191 | "__copy",
|
| 192 | "__pure",
|
| 193 | "__designated_init",
|
| 194 | "__visible",
|
| 195 | "__printf",
|
| 196 | "__scanf",
|
| 197 | "__gnu_inline",
|
| 198 | "__malloc",
|
| 199 | "__mode",
|
| 200 | "__no_caller_saved_registers",
|
| 201 | "__noclone",
|
| 202 | "__nonstring",
|
| 203 | "__noreturn",
|
| 204 | "__packed",
|
| 205 | "__pure",
|
| 206 | "__section",
|
| 207 | "__always_unused",
|
| 208 | "__maybe_unused",
|
| 209 | "__used",
|
| 210 | "__weak",
|
| 211 | "noinline",
|
| 212 | "__fix_address",
|
| 213 | "__counted_by",
|
| 214 |
|
| 215 | |
| 216 | "__init_memblock",
|
| 217 | "__meminit",
|
| 218 |
|
| 219 | |
| 220 | "__init",
|
| 221 | "__ref",
|
| 222 |
|
| 223 | |
| 224 | "asmlinkage",
|
| 225 |
|
| 226 | |
| 227 | "__bpf_kfunc",
|
| 228 | ]
|
| 229 |
|
| 230 | |
| 231 | autosectionlabel_prefix_document = True
|
| 232 | autosectionlabel_maxdepth = 2
|
| 233 |
|
| 234 | |
| 235 | |
| 236 | |
| 237 | have_latex = have_command("latex")
|
| 238 | have_dvipng = have_command("dvipng")
|
| 239 | load_imgmath = have_latex and have_dvipng
|
| 240 |
|
| 241 | |
| 242 | if "SPHINX_IMGMATH" in os.environ:
|
| 243 | env_sphinx_imgmath = os.environ["SPHINX_IMGMATH"]
|
| 244 | if "yes" in env_sphinx_imgmath:
|
| 245 | load_imgmath = True
|
| 246 | elif "no" in env_sphinx_imgmath:
|
| 247 | load_imgmath = False
|
| 248 | else:
|
| 249 | sys.stderr.write("Unknown env SPHINX_IMGMATH=%s ignored.\n" % env_sphinx_imgmath)
|
| 250 |
|
| 251 | if load_imgmath:
|
| 252 | extensions.append("sphinx.ext.imgmath")
|
| 253 | math_renderer = "imgmath"
|
| 254 | else:
|
| 255 | math_renderer = "mathjax"
|
| 256 |
|
| 257 | |
| 258 | templates_path = ["sphinx/templates"]
|
| 259 |
|
| 260 | |
| 261 | source_suffix = {
|
| 262 | ".rst": "restructuredtext",
|
| 263 | ".yaml": "yaml",
|
| 264 | }
|
| 265 |
|
| 266 | |
| 267 | |
| 268 |
|
| 269 | |
| 270 | master_doc = "index"
|
| 271 |
|
| 272 | |
| 273 | project = "The Linux Kernel"
|
| 274 | copyright = "The kernel development community" |
| 275 | author = "The kernel development community"
|
| 276 |
|
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | try:
|
| 288 | makefile_version = None
|
| 289 | makefile_patchlevel = None
|
| 290 | with open("../Makefile", encoding="utf-8") as fp:
|
| 291 | for line in fp:
|
| 292 | key, val = [x.strip() for x in line.split("=", 2)]
|
| 293 | if key == "VERSION":
|
| 294 | makefile_version = val
|
| 295 | elif key == "PATCHLEVEL":
|
| 296 | makefile_patchlevel = val
|
| 297 | if makefile_version and makefile_patchlevel:
|
| 298 | break
|
| 299 | except Exception:
|
| 300 | pass
|
| 301 | finally:
|
| 302 | if makefile_version and makefile_patchlevel:
|
| 303 | version = release = makefile_version + "." + makefile_patchlevel
|
| 304 | else:
|
| 305 | version = release = "unknown version"
|
| 306 |
|
| 307 |
|
| 308 | def get_cline_version():
|
| 309 | |
| 310 | HACK: There seems to be no easy way for us to get at the version and
|
| 311 | release information passed in from the makefile...so go pawing through the
|
| 312 | command-line options and find it for ourselves.
|
| 313 |
|
| 314 |
|
| 315 | c_version = c_release = ""
|
| 316 | for arg in sys.argv:
|
| 317 | if arg.startswith("version="):
|
| 318 | c_version = arg[8:]
|
| 319 | elif arg.startswith("release="):
|
| 320 | c_release = arg[8:]
|
| 321 | if c_version:
|
| 322 | if c_release:
|
| 323 | return c_version + "-" + c_release
|
| 324 | return c_version
|
| 325 | return version |
| 326 |
|
| 327 |
|
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | language = "en"
|
| 334 |
|
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 |
|
| 341 | |
| 342 | |
| 343 | |
| 344 |
|
| 345 | |
| 346 | |
| 347 |
|
| 348 | |
| 349 | |
| 350 | |
| 351 |
|
| 352 | |
| 353 | |
| 354 | |
| 355 |
|
| 356 | |
| 357 | pygments_style = "sphinx"
|
| 358 |
|
| 359 | |
| 360 | |
| 361 |
|
| 362 | |
| 363 | |
| 364 |
|
| 365 | |
| 366 | todo_include_todos = False
|
| 367 |
|
| 368 | primary_domain = "c"
|
| 369 | highlight_language = "none"
|
| 370 |
|
| 371 | |
| 372 |
|
| 373 | |
| 374 | |
| 375 |
|
| 376 | |
| 377 | html_theme = "alabaster"
|
| 378 | html_css_files = []
|
| 379 |
|
| 380 | if "DOCS_THEME" in os.environ:
|
| 381 | html_theme = os.environ["DOCS_THEME"]
|
| 382 |
|
| 383 | if html_theme in ["sphinx_rtd_theme", "sphinx_rtd_dark_mode"]:
|
| 384 | |
| 385 | try:
|
| 386 | import sphinx_rtd_theme
|
| 387 |
|
| 388 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
|
| 389 |
|
| 390 | |
| 391 | |
| 392 | |
| 393 | html_css_files = [
|
| 394 | "theme_overrides.css",
|
| 395 | ]
|
| 396 |
|
| 397 | |
| 398 | if html_theme == "sphinx_rtd_dark_mode":
|
| 399 | try:
|
| 400 | import sphinx_rtd_dark_mode |
| 401 |
|
| 402 | extensions.append("sphinx_rtd_dark_mode")
|
| 403 | except ImportError:
|
| 404 | html_theme = "sphinx_rtd_theme"
|
| 405 |
|
| 406 | if html_theme == "sphinx_rtd_theme":
|
| 407 | |
| 408 | html_css_files.append("theme_rtd_colors.css")
|
| 409 |
|
| 410 | html_theme_options = {
|
| 411 | "navigation_depth": -1,
|
| 412 | }
|
| 413 |
|
| 414 | except ImportError:
|
| 415 | html_theme = "alabaster"
|
| 416 |
|
| 417 | if "DOCS_CSS" in os.environ:
|
| 418 | css = os.environ["DOCS_CSS"].split(" ")
|
| 419 |
|
| 420 | for l in css:
|
| 421 | html_css_files.append(l)
|
| 422 |
|
| 423 | if html_theme == "alabaster":
|
| 424 | html_theme_options = {
|
| 425 | "description": get_cline_version(),
|
| 426 | "page_width": "65em",
|
| 427 | "sidebar_width": "15em",
|
| 428 | "fixed_sidebar": "true",
|
| 429 | "font_size": "inherit",
|
| 430 | "font_family": "serif",
|
| 431 | }
|
| 432 |
|
| 433 | sys.stderr.write("Using %s theme\n" % html_theme)
|
| 434 |
|
| 435 | |
| 436 | |
| 437 | |
| 438 | html_static_path = ["sphinx-static"]
|
| 439 |
|
| 440 | |
| 441 | |
| 442 | |
| 443 | smartquotes_action = "q"
|
| 444 |
|
| 445 | |
| 446 | |
| 447 | html_sidebars = {"**": ["searchbox.html",
|
| 448 | "kernel-toc.html",
|
| 449 | "sourcelink.html"]}
|
| 450 |
|
| 451 | |
| 452 | if html_theme == "alabaster":
|
| 453 | html_sidebars["**"].insert(0, "about.html")
|
| 454 |
|
| 455 | |
| 456 | |
| 457 | html_logo = "images/logo.svg"
|
| 458 | html_favicon = "images/logo.svg"
|
| 459 |
|
| 460 | |
| 461 | htmlhelp_basename = "TheLinuxKerneldoc"
|
| 462 |
|
| 463 | |
| 464 |
|
| 465 | latex_elements = {
|
| 466 | |
| 467 | "papersize": "a4paper",
|
| 468 | "passoptionstopackages": dedent(r"""
|
| 469 | \PassOptionsToPackage{svgnames}{xcolor}
|
| 470 | """),
|
| 471 | |
| 472 | "pointsize": "11pt",
|
| 473 | |
| 474 | "printindex": r"\footnotesize\raggedright\printindex",
|
| 475 | |
| 476 | |
| 477 | |
| 478 | "fontenc": "",
|
| 479 | "inputenc": "",
|
| 480 | "utf8extra": "",
|
| 481 | |
| 482 | "sphinxsetup": dedent(r"""
|
| 483 | hmargin=0.5in, vmargin=1in,
|
| 484 | parsedliteralwraps=true,
|
| 485 | verbatimhintsturnover=false,
|
| 486 | """),
|
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | "maxlistdepth": "10",
|
| 492 | |
| 493 | "extrapackages": r"\usepackage{setspace}",
|
| 494 | "fontpkg": dedent(r"""
|
| 495 | \usepackage{fontspec}
|
| 496 | \setmainfont{DejaVu Serif}
|
| 497 | \setsansfont{DejaVu Sans}
|
| 498 | \setmonofont{DejaVu Sans Mono}
|
| 499 | \newfontfamily\headingfont{DejaVu Serif}
|
| 500 | """),
|
| 501 | "preamble": dedent(r"""
|
| 502 | % Load kerneldoc specific LaTeX settings
|
| 503 | \input{kerneldoc-preamble.sty}
|
| 504 | """)
|
| 505 | }
|
| 506 |
|
| 507 | |
| 508 | latex_documents = []
|
| 509 |
|
| 510 | |
| 511 | |
| 512 | |
| 513 |
|
| 514 | |
| 515 | |
| 516 | |
| 517 |
|
| 518 | |
| 519 | |
| 520 |
|
| 521 | |
| 522 | |
| 523 |
|
| 524 | |
| 525 | |
| 526 |
|
| 527 | |
| 528 | |
| 529 |
|
| 530 | |
| 531 | latex_additional_files = [
|
| 532 | "sphinx/kerneldoc-preamble.sty",
|
| 533 | ]
|
| 534 |
|
| 535 |
|
| 536 | |
| 537 |
|
| 538 | |
| 539 | |
| 540 | man_pages = [
|
| 541 | (master_doc, "thelinuxkernel", "The Linux Kernel Documentation", [author], 1)
|
| 542 | ]
|
| 543 |
|
| 544 | |
| 545 | |
| 546 |
|
| 547 |
|
| 548 | |
| 549 |
|
| 550 | |
| 551 | |
| 552 | |
| 553 | texinfo_documents = [(
|
| 554 | master_doc,
|
| 555 | "TheLinuxKernel",
|
| 556 | "The Linux Kernel Documentation",
|
| 557 | author,
|
| 558 | "TheLinuxKernel",
|
| 559 | "One line description of project.",
|
| 560 | "Miscellaneous",
|
| 561 | ),]
|
| 562 |
|
| 563 | |
| 564 |
|
| 565 | |
| 566 | epub_title = project
|
| 567 | epub_author = author
|
| 568 | epub_publisher = author
|
| 569 | epub_copyright = copyright
|
| 570 |
|
| 571 | |
| 572 | epub_exclude_files = ["search.html"]
|
| 573 |
|
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | pdf_documents = [
|
| 586 | ("kernel-documentation", "Kernel", "Kernel", "J. Random Bozo"),
|
| 587 | ]
|
| 588 |
|
| 589 | kerneldoc_srctree = ".."
|
| 590 |
|
| 591 | |
| 592 | def add_subproject_index(app, docname, content):
|
| 593 | |
| 594 | if docname != master_doc:
|
| 595 | return
|
| 596 |
|
| 597 | |
| 598 | |
| 599 | rel = os.path.relpath(app.srcdir, start=kern_doc_dir).split('/')
|
| 600 | if rel[0] == 'translations' and len(rel) > 1:
|
| 601 | return
|
| 602 |
|
| 603 | |
| 604 | if not app.builder.tags.has('subproject') or not app.builder.tags.has('html'):
|
| 605 | return
|
| 606 |
|
| 607 | |
| 608 | rel = os.path.relpath(os.path.join(kern_doc_dir, 'sphinx-includes/subproject-index.rst'),
|
| 609 | start=app.srcdir)
|
| 610 |
|
| 611 | content[0] += f'\n.. include:: {rel}\n\n'
|
| 612 |
|
| 613 | def setup(app):
|
| 614 |
|
| 615 |
|
| 616 | app.connect('config-inited', config_init)
|
| 617 | app.connect('source-read', add_subproject_index)
|