Skip to content

Commit ba869f6

Browse files
committed
doc: update documentation for APPDIRS makefile variable feature
- Add comprehensive documentation for the new APPDIRS variable in buildsystem.rst, including its usage and behavior with APP_*FLAGS. - Update appdev.rst with practical usage examples and reference the demo_profiling application. - Update changelog.rst to document the new feature. Signed-off-by: Huaqi Fang <578567190@qq.com>
1 parent 19b1d81 commit ba869f6

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

doc/source/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ This is release version of ``0.9.0`` of Nuclei SDK, which is still under develop
8686
- Add :ref:`design_app_demo_ecc` to demonstrate ECC error injection feature on Nuclei RISC-V CPU.
8787
- Disable ECLIC v2 hardware context auto save/restore feature in ``demo_clint_timer``, ``demo_plic``, ``demo_smode_clint`` and ``demo_smode_plic`` applications when using CLINT/PLIC interrupt modes to ensure proper interrupt handling
8888
- Add :ref:`design_app_demo_smode_clint` to demonstrate timer interrupt handling in S-Mode with CLINT interrupt mode.
89+
- Update :ref:`design_app_demo_profiling` to demonstrate the usage of ``APPDIRS`` variable for application-specific compilation flags.
8990
- Remove ``nuclei_cache`` npk configuration from ``demo_cache``, ``demo_cidu``, ``demo_ecc``, ``demo_pma``, ``demo_smpcc``, and ``smphello`` applications ``npk.yml`` since it is now deprecated
9091
- Add ``get_cpu_feature`` in ``cpuinfo`` to list CPU features for the future hardware ci testing.
9192

@@ -116,6 +117,7 @@ This is release version of ``0.9.0`` of Nuclei SDK, which is still under develop
116117

117118
* Build System
118119

120+
- Add new ``APPDIRS`` variable to apply application-specific compilation flags only to specified source directories. When defined, ``APP_XXXFLAGS`` and ``APP_COMMON_FLAGS`` are applied only to source code in ``APPDIRS`` directories, enabling fine-grained control for profiling, coverage, and other app-specific optimizations. See :ref:`develop_buildsystem_var_appdirs` for details.
119121
- Add new ``n300e`` CPU core support in build system and npk.yml for evalsoc
120122
- Add ``-isystem=/include/libncrt`` for nuclei llvm toolchain when using libncrt_xxx library, but ``-isystem=`` feature is not
121123
the same as gcc, see report here https://github.com/llvm/llvm-project/pull/82084#discussion_r2387373311, so when you use libncrt library with llvm toolchain, the header file could be wrongly included using newlib ones

doc/source/develop/appdev.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ To develop a Nuclei SDK application from scratch, you can do the following steps
3838

3939
4. Follow :ref:`develop_buildsystem` to change your application Makefile.
4040

41+
.. note::
42+
43+
* Starting from version 0.9.0, you can use :ref:`develop_buildsystem_var_appdirs` to apply compilation flags specifically to your application source code.
44+
4145
.. _develop_appdev_addsrc:
4246

4347
Add Extra Source Code
@@ -154,4 +158,48 @@ If you want to change the application level Make options,
154158
you can add the :ref:`develop_buildsystem_makefile_local`.
155159

156160

161+
.. _develop_appdev_appdirs_usage:
162+
163+
Application-Specific Compilation Flags with APPDIRS
164+
---------------------------------------------------
165+
166+
Starting from Nuclei SDK version 0.9.0, you can use the :ref:`develop_buildsystem_var_appdirs` variable to apply compilation flags specifically to your application source code, without affecting the SDK library code. This is particularly useful for features like profiling, code coverage, or other application-specific optimizations.
167+
168+
The **APPDIRS** variable allows you to specify directories that need application-specific compilation flags. It can support multiple directories separated by space, e.g. ``APPDIRS = . src``.
169+
170+
If **APPDIRS** is not defined or empty, the **APP_XXXFLAGS** and **APP_COMMON_FLAGS** will be added to global flags and applied to all source files in the project.
171+
172+
If **APPDIRS** is defined, the **APP_XXXFLAGS** and **APP_COMMON_FLAGS** will be applied only to source code located in the directories specified by **APPDIRS**.
173+
174+
The following flags can be used with **APPDIRS**:
175+
176+
* :ref:`develop_buildsystem_var_app_common_flags`: Common flags for C/C++/ASM compilation
177+
* :ref:`develop_buildsystem_var_app_cflags`: Flags specific to C compilation
178+
* :ref:`develop_buildsystem_var_app_cxxflags`: Flags specific to C++ compilation
179+
* :ref:`develop_buildsystem_var_app_asmflags`: Flags specific to ASM compilation
180+
181+
For example, if you want to append specific profiling or coverage flags only to your application source code while keeping the SDK source code compiled with default flags, you can set ``APPDIRS`` to point to your application source directories.
182+
183+
A practical example of this feature can be found in the ``application/baremetal/demo_profiling`` application, which uses ``APPDIRS`` to enable profiling instrumentation only for the application code:
184+
185+
.. code-block:: makefile
186+
187+
# Application-specific compilation options that can be used for
188+
# profiling, coverage, and other app-specific settings
189+
# -pg enables profiling instrumentation
190+
APP_COMMON_FLAGS := -pg
191+
192+
# App-specific C compilation flags
193+
APP_CFLAGS :=
194+
# App-specific C++ compilation flags
195+
APP_CXXFLAGS :=
196+
# App-specific Assembly compilation flags
197+
APP_ASMFLAGS :=
198+
199+
# Specify directories that need app-specific compilation flags
200+
# If left empty, APP_XXXFLAGS will be applied to all source files
201+
APPDIRS := . src
202+
203+
This approach allows for fine-grained control of compilation flags for specific parts of an application while maintaining clean separation from SDK source code.
204+
157205
.. _Options That Control Optimization in GCC: https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Optimize-Options.html#Optimize-Options

doc/source/develop/buildsystem.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,7 @@ APP_COMMON_FLAGS
15101510
.. note::
15111511

15121512
* Added in 0.4.0 release.
1513+
* Behavior changed in 0.9.0 with introduction of APPDIRS - the behavior of this variable now depends on the :ref:`develop_buildsystem_var_appdirs` setting.
15131514

15141515
This variable is used to define app common compiler flags to all c/asm/cpp compiler.
15151516
You can pass it via make command to define extra flags to compile application.
@@ -1520,6 +1521,10 @@ You can pass it via make command to define extra flags to compile application.
15201521
APP_ASMFLAGS
15211522
~~~~~~~~~~~~
15221523

1524+
.. note::
1525+
1526+
* Behavior changed in 0.9.0 with introduction of APPDIRS - the behavior of this variable now depends on the :ref:`develop_buildsystem_var_appdirs` setting.
1527+
15231528
This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app asm flags.
15241529

15251530

@@ -1528,13 +1533,21 @@ This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app asm
15281533
APP_CFLAGS
15291534
~~~~~~~~~~
15301535

1536+
.. note::
1537+
1538+
* Behavior changed in 0.9.0 with introduction of APPDIRS - the behavior of this variable now depends on the :ref:`develop_buildsystem_var_appdirs` setting.
1539+
15311540
This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app c flags.
15321541

15331542
.. _develop_buildsystem_var_app_cxxflags:
15341543

15351544
APP_CXXFLAGS
15361545
~~~~~~~~~~~~
15371546

1547+
.. note::
1548+
1549+
* Behavior changed in 0.9.0 with introduction of APPDIRS - the behavior of this variable now depends on the :ref:`develop_buildsystem_var_appdirs` setting.
1550+
15381551
This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app cxx flags.
15391552

15401553
.. _develop_buildsystem_var_app_ldflags:
@@ -1544,6 +1557,36 @@ APP_LDFLAGS
15441557

15451558
This variable is similiar to **APP_COMMON_FLAGS** but used to pass extra app linker flags.
15461559

1560+
.. _develop_buildsystem_var_appdirs:
1561+
1562+
APPDIRS
1563+
~~~~~~~
1564+
1565+
.. note::
1566+
1567+
* This variable is introduced in version 0.9.0
1568+
1569+
This variable is used to specify directories that need application-specific compilation flags.
1570+
It can support multiple directories separated by space, e.g. ``APPDIRS = . src``.
1571+
1572+
If **APPDIRS** is not defined or empty, the **APP_XXXFLAGS** and **APP_COMMON_FLAGS** will be added to global flags
1573+
and applied to all source files in the project.
1574+
1575+
If **APPDIRS** is defined, the **APP_XXXFLAGS** and **APP_COMMON_FLAGS** will be applied only to source code
1576+
located in the directories specified by **APPDIRS**. This allows for fine-grained control of compilation flags
1577+
for specific parts of an application.
1578+
1579+
For example, if you want to apply specific profiling or coverage flags only to your application source code
1580+
while keeping the SDK library code compiled with default flags, you can set ``APPDIRS`` to point to your
1581+
application source directories.
1582+
1583+
When **APPDIRS** is defined, the following flags will be applied only to source files in those directories:
1584+
1585+
* **APP_COMMON_FLAGS**: Common flags for C/C++/ASM compilation
1586+
* **APP_CFLAGS**: Flags specific to C compilation
1587+
* **APP_CXXFLAGS**: Flags specific to C++ compilation
1588+
* **APP_ASMFLAGS**: Flags specific to ASM compilation
1589+
15471590
.. _develop_buildsystem_var_nogc:
15481591

15491592
NOGC

0 commit comments

Comments
 (0)