1Project Configuration 2********************* 3 4Introduction 5============ 6 7ESP-IDF uses kconfiglib_ which is a Python-based extension to the Kconfig_ system which provides a compile-time 8project configuration mechanism. Kconfig is based around options of several types: integer, string, boolean. Kconfig 9files specify dependencies between options, default values of the options, the way the options are grouped together, 10etc. 11 12For the complete list of available features please see Kconfig_ and `kconfiglib extentions`_. 13 14.. _project-configuration-menu: 15 16Project Configuration Menu 17========================== 18 19Application developers can open a terminal-based project configuration menu with the ``idf.py menuconfig`` build target. 20 21After being updated, this configuration is saved inside ``sdkconfig`` file in the project root directory. Based on ``sdkconfig``, application build targets will generate ``sdkconfig.h`` file in the build directory, and will make sdkconfig options available to the project build system and source files. 22 23(For the legacy GNU Make build system, the project configuration menu is opened with ``make menuconfig``.) 24 25Using sdkconfig.defaults 26======================== 27 28In some cases, such as when ``sdkconfig`` file is under revision control, the fact that ``sdkconfig`` file gets changed by the build system may be inconvenient. The build system offers a way to avoid this, in the form of ``sdkconfig.defaults`` file. This file is never touched by the build system, and must be created manually. It can contain all the options which matter for the given application. The format is the same as that of the ``sdkconfig`` file. Once ``sdkconfig.defaults`` is created, ``sdkconfig`` can be deleted and added to the ignore list of the revision control system (e.g. ``.gitignore`` file for git). Project build targets will automatically create ``sdkconfig`` file, populated with the settings from ``sdkconfig.defaults`` file, and the rest of the settings will be set to their default values. Note that the build process will not override settings that are already in ``sdkconfig`` by ones from ``sdkconfig.defaults``. For more information, see :ref:`custom-sdkconfig-defaults`. 29 30Kconfig Formatting Rules 31======================== 32 33The following attributes of ``Kconfig`` files are standardized: 34 35- Within any menu, option names should have a consistent prefix. The prefix length is currently set to at least 3 36 characters. 37- The indentation style is 4 characters created by spaces. All sub-items belonging to a parent item are indented by 38 one level deeper. For example, ``menu`` is indented by 0 characters, the ``config`` inside of the menu by 4 39 characters, the help of the ``config`` by 8 characters and the text of the ``help`` by 12 characters. 40- No trailing spaces are allowed at the end of the lines. 41- The maximum length of options is set to 40 characters. 42- The maximum length of lines is set to 120 characters. 43- Lines cannot be wrapped by backslash (because there is a bug in earlier versions of ``conf-idf`` which causes that 44 Windows line endings are not recognized after a backslash). 45 46Format checker 47-------------- 48 49``tools/check_kconfigs.py`` is provided for checking the ``Kconfig`` formatting 50rules. The checker checks all ``Kconfig`` and ``Kconfig.projbuild`` files in 51the ESP-IDF directory and generates a new file with suffix ``.new`` with some 52recommendations how to fix issues (if there are any). Please note that the 53checker cannot correct all rules and the responsibility of the developer is to 54check and make final corrections in order to pass the tests. For example, 55indentations will be corrected if there isn't some misleading previous 56formatting but it cannot come up with a common prefix for options inside a 57menu. 58 59.. _configuration-options-compatibility: 60 61Backward Compatibility of Kconfig Options 62========================================= 63 64The standard Kconfig_ tools ignore unknown options in ``sdkconfig``. So if a 65developer has custom settings for options which are renamed in newer ESP-IDF 66releases then the given setting for the option would be silently ignored. 67Therefore, several features have been adopted to avoid this: 68 691. ``confgen.py`` is used by the tool chain to pre-process ``sdkconfig`` files before anything else, for example 70 ``menuconfig``, would read them. As the consequence, the settings for old options will be kept and not ignored. 712. ``confgen.py`` recursively finds all ``sdkconfig.rename`` files in ESP-IDF directory which contain old and new 72 ``Kconfig`` option names. Old options are replaced by new ones in the ``sdkconfig`` file. 733. ``confgen.py`` post-processes ``sdkconfig`` files and generates all build 74 outputs (``sdkconfig.h``, ``sdkconfig.cmake``, ``auto.conf``) by adding a list 75 of compatibility statements, i.e. value of the old option is set the value of 76 the new option (after modification). This is done in order to not break 77 customer codes where old option might still be used. 784. :ref:`configuration-deprecated-options` are automatically generated by ``confgen.py``. 79 80.. _configuration-options-reference: 81 82Configuration Options Reference 83=============================== 84 85Subsequent sections contain the list of available ESP-IDF options, automatically generated from Kconfig files. Note that depending on the options selected, some options listed here may not be visible by default in the interface of menuconfig. 86 87By convention, all option names are upper case with underscores. When Kconfig generates sdkconfig and sdkconfig.h files, option names are prefixed with ``CONFIG_``. So if an option ``ENABLE_FOO`` is defined in a Kconfig file and selected in menuconfig, then sdkconfig and sdkconfig.h files will have ``CONFIG_ENABLE_FOO`` defined. In this reference, option names are also prefixed with ``CONFIG_``, same as in the source code. 88 89 90.. include-build-file:: inc/kconfig.inc 91 92Customisations 93============== 94 95Because IDF builds by default with :ref:`warn-undefined-variables`, when the Kconfig tool generates Makefiles (the ``auto.conf`` file) its behaviour has been customised. In normal Kconfig, a variable which is set to "no" is undefined. In IDF's version of Kconfig, this variable is defined in the Makefile but has an empty value. 96 97(Note that ``ifdef`` and ``ifndef`` can still be used in Makefiles, because they test if a variable is defined *and has a non-empty value*.) 98 99When generating header files for C & C++, the behaviour is not customised - so ``#ifdef`` can be used to test if a boolean config item is set or not. 100 101.. _Kconfig: https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt 102.. _kconfiglib: https://github.com/ulfalizer/Kconfiglib 103.. _kconfiglib extentions: https://pypi.org/project/kconfiglib/#kconfig-extensions 104