1.. _zephyr_doc: 2 3Documentation Generation 4######################## 5 6These instructions will walk you through generating the Zephyr Project's 7documentation on your local system using the same documentation sources 8as we use to create the online documentation found at 9https://docs.zephyrproject.org 10 11.. _documentation-overview: 12 13Documentation overview 14********************** 15 16Zephyr Project content is written using the reStructuredText markup 17language (.rst file extension) with Sphinx extensions, and processed 18using Sphinx to create a formatted stand-alone website. Developers can 19view this content either in its raw form as .rst markup files, or you 20can generate the HTML content and view it with a web browser directly on 21your workstation. This same .rst content is also fed into the Zephyr 22Project's public website documentation area (with a different theme 23applied). 24 25You can read details about `reStructuredText`_, and `Sphinx`_ from 26their respective websites. 27 28The project's documentation contains the following items: 29 30* ReStructuredText source files used to generate documentation found at the 31 https://docs.zephyrproject.org website. Most of the reStructuredText sources 32 are found in the ``/doc`` directory, but others are stored within the 33 code source tree near their specific component (such as ``/samples`` and 34 ``/boards``) 35 36* Doxygen-generated material used to create all API-specific documents 37 also found at https://docs.zephyrproject.org 38 39* Script-generated material for kernel configuration options based on Kconfig 40 files found in the source code tree 41 42.. graphviz:: 43 :caption: Schematic of the documentation build process 44 45 digraph { 46 rankdir=LR 47 48 images [shape="rectangle" label=".png, .jpg\nimages"] 49 rst [shape="rectangle" label="restructuredText\nfiles"] 50 conf [shape="rectangle" label="conf.py\nconfiguration"] 51 rtd [shape="rectangle" label="read-the-docs\ntheme"] 52 header [shape="rectangle" label="c header\ncomments"] 53 xml [shape="rectangle" label="XML"] 54 html [shape="rectangle" label="HTML\nweb site"] 55 sphinx[shape="ellipse" label="sphinx +\nbreathe,\ndocutils"] 56 images -> sphinx 57 rst -> sphinx 58 conf -> sphinx 59 header -> doxygen 60 doxygen -> xml 61 xml-> sphinx 62 rtd -> sphinx 63 sphinx -> html 64 } 65 66 67The reStructuredText files are processed by the Sphinx documentation system, 68and make use of the breathe extension for including the doxygen-generated API 69material. Additional tools are required to generate the 70documentation locally, as described in the following sections. 71 72.. _documentation-processors: 73 74Installing the documentation processors 75*************************************** 76 77Our documentation processing has been tested to run with: 78 79* Doxygen version 1.8.13 80* Graphviz 2.43 81* Latexmk version 4.56 82* All Python dependencies listed in the repository file 83 ``scripts/requirements-doc.txt`` 84 85In order to install the documentation tools, first install Zephyr as 86described in :ref:`getting_started`. Then install additional tools 87that are only required to generate the documentation, 88as described below: 89 90.. doc_processors_installation_start 91 92.. tabs:: 93 94 .. group-tab:: Linux 95 96 On Ubuntu Linux: 97 98 .. code-block:: console 99 100 sudo apt-get install --no-install-recommends doxygen graphviz librsvg2-bin \ 101 texlive-latex-base texlive-latex-extra latexmk texlive-fonts-recommended 102 103 On Fedora Linux: 104 105 .. code-block:: console 106 107 sudo dnf install doxygen graphviz texlive-latex latexmk \ 108 texlive-collection-fontsrecommended librsvg2-tools 109 110 On Clear Linux: 111 112 .. code-block:: console 113 114 sudo swupd bundle-add texlive graphviz 115 116 On Arch Linux: 117 118 .. code-block:: console 119 120 sudo pacman -S graphviz doxygen librsvg texlive-core texlive-bin 121 122 .. group-tab:: macOS 123 124 Use ``brew`` and ``tlmgr`` to install the tools: 125 126 .. code-block:: console 127 128 brew install doxygen graphviz mactex librsvg 129 tlmgr install latexmk 130 tlmgr install collection-fontsrecommended 131 132 .. group-tab:: Windows 133 134 Open a ``cmd.exe`` window as **Administrator** and run the following command: 135 136 .. code-block:: console 137 138 choco install doxygen.install graphviz strawberryperl miktex rsvg-convert 139 140 .. note:: 141 On Windows, the Sphinx executable ``sphinx-build.exe`` is placed in 142 the ``Scripts`` folder of your Python installation path. 143 Dependending on how you have installed Python, you might need to 144 add this folder to your ``PATH`` environment variable. Follow 145 the instructions in `Windows Python Path`_ to add those if needed. 146 147.. doc_processors_installation_end 148 149Documentation presentation theme 150******************************** 151 152Sphinx supports easy customization of the generated documentation 153appearance through the use of themes. Replace the theme files and do 154another ``make htmldocs`` and the output layout and style is changed. 155The ``read-the-docs`` theme is installed as part of the 156:ref:`install_py_requirements` step you took in the getting started 157guide. 158 159Running the documentation processors 160************************************ 161 162The ``/doc`` directory in your cloned copy of the Zephyr project git 163repo has all the .rst source files, extra tools, and Makefile for 164generating a local copy of the Zephyr project's technical documentation. 165Assuming the local Zephyr project copy is in a folder ``zephyr`` in your home 166folder, here are the commands to generate the html content locally: 167 168.. code-block:: console 169 170 # On Linux/macOS 171 cd ~/zephyr/doc 172 # On Windows 173 cd %userprofile%\zephyr\doc 174 175 # Use cmake to configure a Ninja-based build system: 176 cmake -GNinja -B_build . 177 178 # Enter the build directory 179 cd _build 180 181 # To generate HTML output, run ninja on the generated build system: 182 ninja html 183 # If you modify or add .rst files, run ninja again: 184 ninja html 185 186 # To generate PDF output, run ninja on the generated build system: 187 ninja pdf 188 189.. warning:: 190 191 The documentation build system creates copies in the build 192 directory of every .rst file used to generate the documentation, 193 along with dependencies referenced by those .rst files. 194 195 This means that Sphinx warnings and errors refer to the **copies**, 196 and **not the version-controlled original files in Zephyr**. Be 197 careful to make sure you don't accidentally edit the copy of the 198 file in an error message, as these changes will not be saved. 199 200Depending on your development system, it will take up to 15 minutes to 201collect and generate the HTML content. When done, you can view the HTML 202output with your browser started at ``doc/_build/html/index.html`` and 203if generated, the PDF file is available at ``doc/_build/pdf/zephyr.pdf``. 204 205If you want to build the documentation from scratch just delete the contents 206of the build folder and run ``cmake`` and then ``ninja`` again. 207 208.. note:: 209 210 If you add or remove a file from the documentation, you need to re-run CMake. 211 212On Unix platforms a convenience :zephyr_file:`Makefile` at the ``doc`` folder 213of the Zephyr repository can be used to build the documentation directly from 214there: 215 216.. code-block:: console 217 218 cd ~/zephyr/doc 219 220 # To generate HTML output 221 make html 222 223 # To generate PDF output 224 make pdf 225 226Filtering expected warnings 227*************************** 228 229There are some known issues with Sphinx/Breathe that generate Sphinx warnings 230even though the input is valid C code. While these issues are being considered 231for fixing we have created a Sphinx extension that allows to filter them out 232based on a set of regular expressions. The extension is named 233``zephyr.warnings_filter`` and it is located at 234``doc/_extensions/zephyr/warnings_filter.py``. The warnings to be filtered out 235can be added to the ``doc/known-warnings.txt`` file. 236 237The most common warning reported by Sphinx/Breathe is related to duplicate C 238declarations. This warning may be caused by different Sphinx/Breathe issues: 239 240- Multiple declarations of the same object are not supported 241- Different objects (e.g. a struct and a function) can not share the same name 242- Nested elements (e.g. in a struct or union) can not share the same name 243 244Developer-mode Document Building 245******************************** 246 247Building the documentation for all the Kconfig options significantly 248adds to the total doc build time. When making and testing major changes 249to the documentation, we provide an option to temporarily stub-out 250the auto-generated configuration documentation so the doc build process 251runs much faster. 252 253To enable this mode, set the following option when invoking cmake:: 254 255 -DKCONFIG_TURBO_MODE=1 256 257or invoke make with the following target:: 258 259 cd ~/zephyr 260 261 # To generate HTML output without detailed Kconfig 262 make html-fast 263 264Linking external Doxygen projects against Zephyr 265************************************************ 266 267External projects that build upon Zephyr functionality and wish to refer to 268Zephyr documentation in Doxygen (through the use of @ref), can utilize the 269tag file exported at `zephyr.tag </doxygen/html/zephyr.tag>`_ 270 271Once downloaded, the tag file can be used in a custom ``doxyfile.in`` as follows:: 272 273 TAGFILES = "/path/to/zephyr.tag=https://docs.zephyrproject.org/latest/doxygen/html/" 274 275For additional information refer to `Doxygen External Documentation`_. 276 277 278.. _reStructuredText: http://sphinx-doc.org/rest.html 279.. _Sphinx: http://sphinx-doc.org/ 280.. _Windows Python Path: https://docs.python.org/3/using/windows.html#finding-the-python-executable 281.. _Doxygen External Documentation: https://www.doxygen.nl/manual/external.html 282