Part 1
요약·해설
표준 Kconfig와 다른 Zephyr 확장의 의미와 include 경로 해석을 예제로 설명합니다.
configdefault
osource
rsource
orsource
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
313FF59056BDFFA5F707FE40408F71E8297483AED59C9C30A53221993890F690
.. _kconfig_extensions:
Kconfig extensions
##################
Zephyr uses the `Kconfiglib <https://github.com/ulfalizer/Kconfiglib>`__
implementation of `Kconfig
<https://docs.kernel.org/kbuild/kconfig-language.html>`__,
which includes some Kconfig extensions:
- Default values can be applied to existing symbols without
:ref:`weakening <multiple_symbol_definitions>` the symbols dependencies
through the use of ``configdefault``.
.. code-block:: none
config FOO
bool "FOO"
depends on BAR
configdefault FOO
default y if FIZZ
The statement above is equivalent to:
.. code-block:: none
config FOO
bool "Foo"
default y if FIZZ
depends on BAR
``configdefault`` symbols cannot contain any fields other than ``default``,
however they can be wrapped in ``if`` statements. The two statements below
are equivalent:
.. code-block:: none
configdefault FOO
default y if BAR
if BAR
configdefault FOO
default y
endif # BAR
- Environment variables in ``source`` statements are expanded directly, meaning
no "bounce" symbols with ``option env="ENV_VAR"`` need to be defined.
.. note::
``option env`` has been removed from the C tools as of Linux 4.18 as well.
The recommended syntax for referencing environment variables is ``$(FOO)``
rather than ``$FOO``. This uses the new `Kconfig preprocessor
<https://docs.kernel.org/kbuild/kconfig-macro-language.html>`__.
The ``$FOO`` syntax for expanding environment variables is only supported for
backwards compatibility.
- The ``source`` statement supports glob patterns and includes each matching
file. A pattern is required to match at least one file.
Consider the following example:
.. code-block:: kconfig
source "foo/bar/*/Kconfig"
If the pattern ``foo/bar/*/Kconfig`` matches the files
:file:`foo/bar/baz/Kconfig` and :file:`foo/bar/qaz/Kconfig`, the statement
above is equivalent to the following two ``source`` statements:
.. code-block:: kconfig
source "foo/bar/baz/Kconfig"
source "foo/bar/qaz/Kconfig"
If no files match the pattern, an error is generated.
The wildcard patterns accepted are the same as for the Python `glob
<https://docs.python.org/3/library/glob.html>`__ module.
For cases where it's okay for a pattern to match no files (or for a plain
filename to not exist), a separate ``osource`` (*optional source*) statement
is available. ``osource`` is a no-op if no file matches.
.. note::
``source`` and ``osource`` are analogous to ``include`` and
``-include`` in Make.
- An ``rsource`` statement is available for including files specified with a
relative path. The path is relative to the directory of the :file:`Kconfig`
file that contains the ``rsource`` statement.
As an example, assume that :file:`foo/Kconfig` is the top-level
:file:`Kconfig` file, and that :file:`foo/bar/Kconfig` has the following
statements:
.. code-block:: kconfig
source "qaz/Kconfig1"
rsource "qaz/Kconfig2"
This will include the two files :file:`foo/qaz/Kconfig1` and
:file:`foo/bar/qaz/Kconfig2`.
``rsource`` can be used to create :file:`Kconfig` "subtrees" that can be
moved around freely.
``rsource`` also supports glob patterns.
A drawback of ``rsource`` is that it can make it harder to figure out where a
file gets included, so only use it if you need it.
- An ``orsource`` statement is available that combines ``osource`` and
``rsource``.
For example, the following statement will include :file:`Kconfig1` and
:file:`Kconfig2` from the current directory (if they exist):
.. code-block:: kconfig
orsource "Kconfig[12]"
- ``def_int``, ``def_hex``, and ``def_string`` keywords are available,
analogous to ``def_bool``. These set the type and add a ``default`` at the
same time.
Part 3
한국어 전문 번역
Zephyr의 Kconfig 확장
Zephyr는 Linux kernel과 같은 Kconfig 언어를 Kconfiglib로 구현합니다. Kconfiglib에는 표준 언어에 더해 Zephyr가 사용하는 몇 가지 확장이 있습니다.
configdefault
기존 symbol의 dependency를 약화하지 않고 default 값을 추가합니다. 다음 FOO는 BAR에 의존하면서 FIZZ일 때 default가 y입니다.
config FOO
bool "FOO"
depends on BAR
configdefault FOO
default y if FIZZ의미상 다음 하나의 정의와 같습니다.
config FOO
bool "Foo"
default y if FIZZ
depends on BARconfigdefault에는 default 이외의 field를 넣을 수 없지만 if 문으로 감쌀 수 있습니다. 다음 두 표현은 같습니다.
configdefault FOO
default y if BAR
if BAR
configdefault FOO
default y
endif # BARsource의 environment variable
source statement 안의 environment variable은 직접 확장되므로 option env="ENV_VAR"를 가진 중간 symbol을 만들 필요가 없습니다. Linux 4.18부터 C tool에서도 option env가 제거되었습니다.
Environment variable은 예전 $FOO보다 새 Kconfig preprocessor 문법인 $(FOO)로 참조하는 것이 권장됩니다. $FOO는 backward compatibility 용도로만 지원합니다.
Glob을 지원하는 source
source는 glob pattern과 일치하는 file을 모두 include합니다. Pattern은 최소 한 file과 일치해야 합니다.
source "foo/bar/*/Kconfig"이 pattern이 foo/bar/baz/Kconfig와 foo/bar/qaz/Kconfig에 일치하면 다음 두 statement와 같습니다.
source "foo/bar/baz/Kconfig"
source "foo/bar/qaz/Kconfig"일치하는 file이 없으면 error가 발생하며 Python glob module과 같은 wildcard를 사용합니다.
osource
Pattern이 아무 file과 일치하지 않거나 일반 filename이 없어도 괜찮다면 optional source인 osource를 사용합니다. 일치 항목이 없을 때 아무 작업도 하지 않습니다. Make의 include와 -include 관계가 Kconfig의 source와 osource 관계와 비슷합니다.
상대 경로 rsource
rsource 경로는 statement가 들어 있는 Kconfig file의 directory를 기준으로 해석합니다. foo/Kconfig가 top-level이고 foo/bar/Kconfig에 다음 내용이 있다고 가정합니다.
source "qaz/Kconfig1"
rsource "qaz/Kconfig2"source는 top-level 기준의 foo/qaz/Kconfig1을, rsource는 현재 file 기준의 foo/bar/qaz/Kconfig2를 include합니다.
rsource는 위치를 자유롭게 옮길 수 있는 Kconfig subtree를 만들 때 유용하고 glob도 지원합니다. 다만 file이 어디서 include되었는지 추적하기 어려워질 수 있으므로 필요할 때만 사용합니다.
orsource
osource와 rsource를 결합합니다. 다음은 현재 directory에 file이 존재할 때 Kconfig1과 Kconfig2를 include합니다.
orsource "Kconfig[12]"Type과 default를 함께 지정
def_bool과 같은 방식으로 def_int, def_hex, def_string keyword를 사용할 수 있습니다. 이들은 symbol type을 지정하면서 동시에 default를 추가합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.