Skip to content

Commit 258ed5f

Browse files
committed
Documentation/Makefile: add make_build_system.rst
1 parent abf7a74 commit 258ed5f

File tree

4 files changed

+258
-0
lines changed

4 files changed

+258
-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: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
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+
One of the main differences is the use of forward slashes
101+
(``/``) on unix-like platforms versus backslashes (``\``) on windows
102+
103+
- **${HOSTEXEEXT} ${HOSTDYNEXT}**
104+
105+
These variables are used by the build system to configure the executable suffix required
106+
by the used platform. They are defined in :ref:`config_mk`.
107+
108+
For windows platform:
109+
110+
- ``${HOSTEXEEXT}`` is set to ``.exe``.
111+
- ``${HOSTDYNEXT}`` is set to ``.dll``.
112+
113+
- **Symbolic Linking**
114+
115+
For the windows platform, the build system handles symbolic links differently.
116+
117+
The differences and drawbacks of the windows platform are explained in
118+
:ref:`build_system_linking`.
119+
120+
.. _unix_mk:
121+
122+
Unix.mk
123+
-------
124+
125+
- **Versioning**
126+
127+
The build system will impact versioning if NuttX is cloned as a repo. See :ref:`versioning`.
128+
129+
- **config.h .config mkconfig**
130+
131+
NuttX's build system defers the ``config.h`` generation to a separate tool called
132+
``mkconfig``. See :ref:`makefile_host`.
133+
134+
.. code-block:: makefile
135+
136+
tools/mkconfig$(HOSTEXEEXT): prebuild
137+
$(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT)
138+
139+
The ``include/nuttx/config.h`` recipe calls the ``mkconfig`` executable generated by the
140+
rule above to create the ``config.h`` file from the current ``.config`` file.
141+
142+
- **Symlinking board and chip**
143+
144+
The build system always uses the same ``board`` and ``chip`` paths during
145+
build process to ease the build process. To achieve this, the build system will:
146+
147+
- Symlink ``arch/<arch-name>/include`` to ``include/arch``
148+
- Symlink ``boards/<arch>/<chip>/<board>/include`` to ``include/arch/board``
149+
- Symlink ``arch/<arch-name>/include/<chip-name>`` to ``include/arch/chip``
150+
- Symlink ``boards/<arch>/<chip>/<board>`` to ``arch/<arch-name>/src/board/<board>``
151+
152+
.. note::
153+
154+
Some boards make use of a ``common`` directory. In that case:
155+
156+
- ``boards/<arch>/<chip>/common`` is symlinked to ``arch/<arch-name>/src/board``
157+
- ``boards/<arch>/<chip>/<board>`` is symlinked to ``arch/<arch-name>/src/board/<board>``
158+
159+
- Symlink ``arch/<arch-name>/src/<chip-name>`` to ``arch/<arch-name>/src/chip``
160+
161+
This step is done also while running ``tools/configure.sh`` script.
162+
163+
- **Use of dummy**
164+
165+
NuttX make use of dummies to overcome some build limitations.
166+
167+
- *${EXTERNALDIR}*
168+
169+
NuttX code base can be extended by using ``$(TOPDIR)/external/`` directory.
170+
The build system scans the presence of a ``Kconfig`` file in that directory. If found,
171+
the build system defines the ``EXTERNALDIR`` variable to ``external`` so that the main Kconfig
172+
can find it. Otherwise, it redirects it to a dummy Kconfig file.
173+
174+
.. code-block:: makefile
175+
176+
# External code support
177+
# If external/ contains a Kconfig, we define the EXTERNALDIR variable to 'external'
178+
# so that main Kconfig can find it. Otherwise, we redirect it to a dummy Kconfig
179+
# This is due to kconfig inability to do conditional inclusion.
180+
181+
EXTERNALDIR := $(shell if [ -r $(TOPDIR)/external/Kconfig ]; then echo 'external'; else echo 'dummy'; fi)
182+
183+
- *dummy/Kconfig*
184+
185+
The ``dummy/Kconfig`` is used to handle custom chips and boards.
186+
187+
If in-tree chip/board is used, the build system will resolve to dummy_kconfig files.
188+
- ``$(CHIP_KCONFIG)`` is set to ``$(TOPDIR)$(DELIM)arch$(DELIM)dummy$(DELIM)dummy_kconfig``
189+
- ``$(BOARD_KCONFIG)`` is set to ``$(TOPDIR)$(DELIM)boards$(DELIM)dummy$(DELIM)dummy_kconfig``
190+
191+
If custom chip/board is used, the build system will resolve to their custom paths.
192+
193+
.. code-block:: makefile
194+
195+
# Copy $(CHIP_KCONFIG) to arch/dummy/Kconfig
196+
197+
arch/dummy/Kconfig:
198+
@echo "CP: $@ to $(CHIP_KCONFIG)"
199+
$(Q) cp -f $(CHIP_KCONFIG) $@
200+
201+
# Copy $(BOARD_KCONFIG) to boards/dummy/Kconfig
202+
203+
boards/dummy/Kconfig:
204+
@echo "CP: $@ to $(BOARD_KCONFIG)"
205+
$(Q) cp -f $(BOARD_KCONFIG) $@
206+
207+
- *boards/dummy.c*
208+
209+
NuttX includes a dummy.c used to generate a useless object. The purpose of the useless object
210+
is to assure that libboards.a/lib is created. Some archivers (ZDS-II, SDCC) require a non-empty
211+
library or they will generate errors
212+
213+
.. _flatlibs_mk:
214+
215+
FlatLibs.mk
216+
-----------
217+
218+
placeholder
219+
220+
.. _protectedlibs_mk:
221+
222+
ProtectedLibs.mk
223+
----------------
224+
225+
placeholder
226+
227+
.. _kernelibs_mk:
228+
229+
KernelLibs.mk
230+
-------------
231+
232+
placeholder
233+
234+
.. _directories_mk:
235+
236+
Directories.mk
237+
--------------
238+
239+
placeholder
240+
241+
.. _libtargets_mk:
242+
243+
LibTargets.mk
244+
-------------
245+
246+
placeholder
247+
248+
.. _config_mk:
249+
250+
Config.mk
251+
---------

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)