Skip to content

Commit 9a3f5d0

Browse files
committed
Documentation/Makefile: add make_build_system.rst
1 parent abf7a74 commit 9a3f5d0

File tree

4 files changed

+271
-0
lines changed

4 files changed

+271
-0
lines changed

Documentation/components/tools/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ these problems::
740740
- option env="APPSDIR"
741741
+ default "../apps"
742742

743+
.. _build_system_linking:
744+
743745
link.sh, link.bat, copydir.sh, copydir.bat, unlink.sh, and unlink.bat
744746
---------------------------------------------------------------------
745747

@@ -780,6 +782,8 @@ this case. link.bat will attempt to create a symbolic link using the
780782
NTFS mklink.exe command instead of copying files. That logic, however,
781783
has not been verified as of this writing.
782784

785+
.. _makefile_host:
786+
783787
Makefile.host
784788
-------------
785789

Documentation/guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Guides
5252
fully_linked_elf.rst
5353
building_nuttx_with_app_out_of_src_tree.rst
5454
building_uclibcpp.rst
55+
make_build_system.rst
5556
custom_app_directories.rst
5657
multiple_nsh_sessions.rst
5758
nsh_network_link_management.rst
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one or more
2+
.. contributor license agreements. See the NOTICE file distributed with
3+
.. this work for additional information regarding copyright ownership. The
4+
.. ASF licenses this file to you under the Apache License, Version 2.0 (the
5+
.. "License"); you may not use this file except in compliance with the
6+
.. License. You may obtain a copy of the License at
7+
..
8+
.. http://www.apache.org/licenses/LICENSE-2.0
9+
..
10+
.. Unless required by applicable law or agreed to in writing, software
11+
.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
.. License for the specific language governing permissions and limitations
14+
.. under the License.
15+
16+
.. _make_build_system:
17+
18+
=================
19+
Make Build System
20+
=================
21+
22+
Currently, NuttX supports both CMake and Make build systems.
23+
This guide explains the NuttX `make`-based build system.
24+
25+
Due to *requirements, constraints, and the complexity of the build process*, NuttX divides
26+
this work into multiple files, each handling specific parts of the build process.
27+
28+
Stated in :doc:`/introduction/inviolables`, multiple platforms should be supported:
29+
30+
- :ref:`win_mk`: handles windows platform support.
31+
- :ref:`unix_mk`: handles unix-like platforms support.
32+
33+
NuttX supports multiple build modes. See :doc:`protected_build`:
34+
35+
- :ref:`flatlibs_mk`: Kernel and user-space built into a single `blob`.
36+
- :ref:`protectedlibs_mk`: Kernel and user-space built as two separate `blobs`.
37+
- :ref:`kernelibs_mk`: Kernel build into single `blob`. User apps must be loaded
38+
into memory for execution.
39+
40+
NuttX targets multiple libs, or `silos`, each handling it's own compilation:
41+
42+
.. note::
43+
44+
Gregory Nutt have a nice presetation about
45+
`NuttX architecture <https://cwiki.apache.org/confluence/pages/viewpage.action?
46+
pageId=139629399&preview=/139629402/140774623/nuttx-3-archoverview.pdf>`_
47+
48+
There the `silo` concept is explained. Only the `silos` there are listed below as libs.
49+
The build modes influences the needed libs.
50+
51+
.. code-block:: console
52+
53+
$ ls -l staging/
54+
drwxr-xr-x 2 xxx xxx 4096 Oct 6 16:02 .
55+
drwxr-xr-x 27 xxx xxx 4096 Oct 6 16:02 ..
56+
-rw-r--r-- 1 xxx xxx 323640 Oct 6 16:02 libapps.a
57+
-rw-r--r-- 1 xxx xxx 384352 Oct 6 16:02 libarch.a
58+
-rw-r--r-- 1 xxx xxx 62182 Oct 6 16:02 libbinfmt.a
59+
-rw-r--r-- 1 xxx xxx 6468 Oct 6 16:01 libboards.a
60+
-rw-r--r-- 1 xxx xxx 2820054 Oct 6 16:02 libc.a
61+
-rw-r--r-- 1 xxx xxx 161486 Oct 6 16:01 libdrivers.a
62+
-rw-r--r-- 1 xxx xxx 981638 Oct 6 16:02 libfs.a
63+
-rw-r--r-- 1 xxx xxx 224446 Oct 6 16:02 libmm.a
64+
-rw-r--r-- 1 xxx xxx 2435746 Oct 6 16:01 libsched.a
65+
-rw-r--r-- 1 xxx xxx 51768 Oct 6 16:02 libxx.a
66+
67+
Verbosity
68+
---------
69+
70+
The ``V`` variable can be passed to make to control the build verbosity.
71+
72+
- **Quiet (Default):** The build output is minimal.
73+
- **Verbose (`V=1 V=2`):** Shows the full compiler commands *(enables command echo)*.
74+
- **Verbose Tools (`V=2`):** Enables verbose output for tools and scripts.
75+
76+
.. code-block:: console
77+
78+
# V=1,2: Enable echo of commands
79+
$ make V=1
80+
81+
# V=2: Enable bug/verbose options in tools and scripts
82+
$ make V=2
83+
84+
Build Flow
85+
----------
86+
87+
The root **Makefile** is the build process entrypoint. Its main job is
88+
to check for a ``.config`` file and include the appropriate **host-specific Makefile**.
89+
90+
.. _win_mk:
91+
92+
Win.mk
93+
------
94+
95+
Although targeting different platforms, both **Win.mk** and **Unix.mk** aims the same output.
96+
The need for independent files is due to the differences in the platforms approaches.
97+
98+
forward vs back slashes
99+
^^^^^^^^^^^^^^^^^^^^^^^
100+
101+
One of the main differences is the use of forward slashes
102+
(``/``) on unix-like platforms versus backslashes (``\``) on windows
103+
104+
${HOSTEXEEXT} ${HOSTDYNEXT}
105+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
106+
107+
These variables are used by the build system to configure the executable suffix required
108+
by the used platform. They are defined in :ref:`config_mk`.
109+
110+
For windows platform:
111+
112+
- ``${HOSTEXEEXT}`` is set to ``.exe``.
113+
- ``${HOSTDYNEXT}`` is set to ``.dll``.
114+
115+
Symbolic Linking
116+
^^^^^^^^^^^^^^^^
117+
118+
For the windows platform, the build system handles symbolic links differently.
119+
120+
The differences and drawbacks of the windows platform are explained in
121+
:ref:`build_system_linking`.
122+
123+
.. _unix_mk:
124+
125+
Unix.mk
126+
-------
127+
128+
Versioning
129+
^^^^^^^^^^
130+
131+
The build system will impact versioning if NuttX is cloned as a repo. See :ref:`versioning`.
132+
133+
config.h .config mkconfig
134+
^^^^^^^^^^^^^^^^^^^^^^^^^
135+
136+
NuttX's build system defers the ``config.h`` generation to a separate tool called
137+
``mkconfig``. See :ref:`makefile_host`.
138+
139+
.. code-block:: makefile
140+
141+
tools/mkconfig$(HOSTEXEEXT): prebuild
142+
$(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT)
143+
144+
The ``include/nuttx/config.h`` recipe calls the ``mkconfig`` executable generated by the
145+
rule above to create the ``config.h`` file from the current ``.config`` file.
146+
147+
Symlinks & dirlinks
148+
^^^^^^^^^^^^^^^^^^^
149+
150+
Dirlinks are symbolic links that allow the build system to use generic paths while pointing
151+
to architecture-specific, chip-specific, or board-specific directories. This enables a single
152+
build system workflow across many different hardware configurations.
153+
154+
- Symlink ``arch/<arch-name>/include`` to ``include/arch``
155+
- Symlink ``boards/<arch>/<chip>/<board>/include`` to ``include/arch/board``
156+
- Symlink ``arch/<arch-name>/include/<chip-name>`` to ``include/arch/chip``
157+
- Symlink ``boards/<arch>/<chip>/<board>`` to ``arch/<arch-name>/src/board/<board>``
158+
159+
.. note::
160+
161+
Some boards make use of a ``common`` directory. In that case:
162+
163+
- ``boards/<arch>/<chip>/common`` is symlinked to ``arch/<arch-name>/src/bb oard``
164+
- ``boards/<arch>/<chip>/<board>`` is symlinked to ``arch/<arch-name>/src/board/<board>``
165+
166+
- Symlink ``arch/<arch-name>/src/<chip-name>`` to ``arch/<arch-name>/src/chip``
167+
168+
The ``.dirlinks`` file itself is just a timestamp marker that indicates all dirlinks have been
169+
created.
170+
171+
Dummies
172+
^^^^^^^
173+
174+
The main reason for the use of dummies is to handle some specific scenarios, such as external
175+
code bases, custom chips and boards or overcome tooling limitation. If any of the features below
176+
are not used, the build system will fallback to a dummy.
177+
178+
- **${EXTERNALDIR}**
179+
180+
Possible values for ``$(EXTERNALDIR)`` are ``external`` or ``dummy``.
181+
182+
NuttX code base can be extended by using ``$(TOPDIR)/external/`` directory.
183+
The build system searches for a ``Kconfig`` file in that directory. If found,
184+
the build system defines the ``EXTERNALDIR`` variable to ``external`` and also
185+
appends another lib (``libexternal``) to the build process.
186+
187+
.. code-block:: makefile
188+
189+
# External code support
190+
# If external/ contains a Kconfig, we define the EXTERNALDIR variable to 'external'
191+
# so that main Kconfig can find it. Otherwise, we redirect it to a dummy Kconfig
192+
# This is due to kconfig inability to do conditional inclusion.
193+
194+
EXTERNALDIR := $(shell if [ -r $(TOPDIR)/external/Kconfig ]; then echo 'external'; else echo 'dummy'; fi)
195+
196+
- **dummy/Kconfig**
197+
198+
The ``dummy/Kconfig`` is used to handle custom chips and boards.
199+
200+
If in-tree chip/board is used, the build system will resolve to dummy_kconfig files.
201+
- ``$(CHIP_KCONFIG)`` is set to ``$(TOPDIR)$(DELIM)arch$(DELIM)dummy$(DELIM)dummy_kconfig``
202+
- ``$(BOARD_KCONFIG)`` is set to ``$(TOPDIR)$(DELIM)boards$(DELIM)dummy$(DELIM)dummy_kconfig``
203+
204+
If custom chip/board is used, the build system will resolve to their custom paths.
205+
206+
.. code-block:: makefile
207+
208+
# Copy $(CHIP_KCONFIG) to arch/dummy/Kconfig
209+
210+
arch/dummy/Kconfig:
211+
@echo "CP: $@ to $(CHIP_KCONFIG)"
212+
$(Q) cp -f $(CHIP_KCONFIG) $@
213+
214+
# Copy $(BOARD_KCONFIG) to boards/dummy/Kconfig
215+
216+
boards/dummy/Kconfig:
217+
@echo "CP: $@ to $(BOARD_KCONFIG)"
218+
$(Q) cp -f $(BOARD_KCONFIG) $@
219+
220+
- **boards/dummy.c**
221+
222+
A special ``boards/dummy.c`` file is used by the build system to generate a useless object.
223+
The purpose of the useless object is to assure that libboards.a/lib is created. Some archivers
224+
(ZDS-II, SDCC) require a non-empty library or they will generate errors.
225+
226+
.. _flatlibs_mk:
227+
228+
FlatLibs.mk
229+
-----------
230+
231+
placeholder
232+
233+
.. _protectedlibs_mk:
234+
235+
ProtectedLibs.mk
236+
----------------
237+
238+
placeholder
239+
240+
.. _kernelibs_mk:
241+
242+
KernelLibs.mk
243+
-------------
244+
245+
placeholder
246+
247+
.. _directories_mk:
248+
249+
Directories.mk
250+
--------------
251+
252+
placeholder
253+
254+
.. _libtargets_mk:
255+
256+
LibTargets.mk
257+
-------------
258+
259+
placeholder
260+
261+
.. _config_mk:
262+
263+
Config.mk
264+
---------

Documentation/guides/versioning_and_task_names.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Answer
3333

3434
This is probably normal behavior. There are two separate, unrelated issues here.
3535

36+
.. _versioning:
37+
3638
Versioning
3739
----------
3840

0 commit comments

Comments
 (0)