buildsystem.rst 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. .. _develop_buildsystem:
  2. Build System based on Makefile
  3. ==============================
  4. Nuclei SDK's build system is based on Makefile, user can build,
  5. run ordebug application in Windows and Linux.
  6. .. _develop_buildsystem_structure:
  7. Makefile Structure
  8. ------------------
  9. Nuclei SDK's Makefiles mainly placed in **<NUCLEI_SDK_ROOT>/Build** directory and
  10. an extra *Makefile* located in **<NUCLEI_SDK_ROOT>/Makefile**.
  11. This extra **<NUCLEI_SDK_ROOT>/Makefile** introduce a new Make variable called
  12. **PROGRAM** to provide the ability to build or run application in **<NUCLEI_SDK_ROOT>**.
  13. For example, if you want to *rebuild and upload* application **application/baremetal/timer_test**,
  14. you can run ``make PROGRAM=application/baremetal/timer_test clean upload`` to achieve it.
  15. The **<NUCLEI_SDK_ROOT>/Build** directory content list as below:
  16. .. code-block:: text
  17. gmsl/
  18. Makefile.base
  19. Makefile.conf
  20. Makefile.core
  21. Makefile.components
  22. Makefile.files
  23. Makefile.global -> Created by user
  24. Makefile.misc
  25. Makefile.rtos
  26. Makefile.rules
  27. Makefile.soc
  28. The file or directory is used explained as below:
  29. .. _develop_buildsystem_makefile_base:
  30. Makefile.base
  31. ~~~~~~~~~~~~~
  32. This **Makefile.base** file is used as Nuclei SDK build system entry file,
  33. application's Makefile need to include this file to use all the features of
  34. Nuclei SDK build system.
  35. It will expose Make variables or options such as **BOARD** or **SOC** passed
  36. by ``make`` command, click :ref:`develop_buildsystem_exposed_make_vars`
  37. to learn more.
  38. This file will include optional :ref:`develop_buildsystem_makefile_global`
  39. and :ref:`develop_buildsystem_makefile_local` which allow user to set custom
  40. global Makefile configurations and local application Makefile configurations.
  41. This file will include the following makefiles:
  42. * :ref:`develop_buildsystem_gmsl`: additional library functions provided via gmsl
  43. * :ref:`develop_buildsystem_makefile_misc`: misc functions and OS check helpers
  44. * :ref:`develop_buildsystem_makefile_conf`: main Makefile configuration entry
  45. * :ref:`develop_buildsystem_makefile_rules`: make rules of this build system
  46. .. _develop_buildsystem_gmsl:
  47. gmsl
  48. ~~~~
  49. The **gmsl** directory consist of the `GNU Make Standard Library (GMSL)`_,
  50. which is an a library of functions to be used with GNU Make's $(call) that
  51. provides functionality not available in standard GNU Make.
  52. We use this **gmsl** tool to make sure we help us achieve some linux command
  53. which is only supported in Linux.
  54. .. _develop_buildsystem_makefile_misc:
  55. Makefile.misc
  56. ~~~~~~~~~~~~~
  57. This **Makefile.misc** file mainly provide these functions:
  58. * Define **get_csrcs**, **get_asmsrcs**, **get_cxxsrcs** and **check_item_exist** make functions
  59. - **get_csrcs**: Function to get ``*.c or *.C`` source files from a list of directories, no ability to
  60. do recursive match. e.g. ``$(call get_csrcs, csrc csrc/abc)`` will return c source files in
  61. ``csrc`` and ``csrc/abc`` directories.
  62. - **get_asmsrcs**: Function to get ``*.s or *.S`` source files from a list of directories, no ability to
  63. do recursive match. e.g. ``$(call get_asmsrcs, asmsrc asmsrc/abc)`` will return asm source files in
  64. ``asmsrc`` and ``asmsrc/abc`` directories.
  65. - **get_cxxsrcs**: Function to get ``*.cpp or *.CPP`` source files from a list of directories, no ability
  66. to do recursive match. e.g. ``$(call get_cxxsrcs, cppsrc cppsrc/abc)`` will return cpp source files in
  67. ``cppsrc`` and ``cppsrc/abc`` directories.
  68. - **check_item_exist**: Function to check if item existed in a set of items. e.g.
  69. ``$(call check_item_exist, flash, flash ilm flashxip)`` will check ``flash`` whether existed in
  70. ``flash ilm flashxip``, if existed, return ``flash``, otherwise return empty.
  71. * Check and define OS related functions, and also a set of trace print functions.
  72. .. _develop_buildsystem_makefile_conf:
  73. Makefile.conf
  74. ~~~~~~~~~~~~~
  75. This **Makefile.conf** file will define the following items:
  76. * Toolchain related variables used during compiling
  77. * Debug related variables
  78. * Include :ref:`develop_buildsystem_makefile_files` and :ref:`develop_buildsystem_makefile_rtos`
  79. * Collect all the C/C++/ASM compiling and link options
  80. .. _develop_buildsystem_makefile_rules:
  81. Makefile.rules
  82. ~~~~~~~~~~~~~~
  83. This **Makefile.rules** file will do the following things:
  84. * Collect all the sources during compiling
  85. * Define all the rules used for building, uploading and debugging
  86. * Print help message for build system
  87. .. _develop_buildsystem_makefile_files:
  88. Makefile.files
  89. ~~~~~~~~~~~~~~
  90. This **Makefile.files** file will do the following things:
  91. * Define common C/C++/ASM source and include directories
  92. * Define common C/C++/ASM macros
  93. .. _develop_buildsystem_makefile_soc:
  94. Makefile.soc
  95. ~~~~~~~~~~~~
  96. This **Makefile.soc** will include valid makefiles located in
  97. **<NUCLEI_SDK_ROOT>/SoC/<SOC>/build.mk** according to
  98. the :ref:`develop_buildsystem_var_soc` makefile variable setting.
  99. It will define the following items:
  100. * **DOWNLOAD** and **CORE** variables
  101. - For :ref:`design_soc_demosoc`, we can support all the modes defined in
  102. :ref:`develop_buildsystem_var_download`, and **CORE** list defined in
  103. :ref:`develop_buildsystem_makefile_core`
  104. - For :ref:`design_soc_gd32vf103`, The **CORE** is fixed to N205, since
  105. it is a real SoC chip, and only **FlashXIP** download mode is supported
  106. * Linker script used according to the **DOWNLOAD** mode settings
  107. * OpenOCD debug configuration file used for the SoC and Board
  108. * Some extra compiling or debugging options
  109. A valid SoC should be organized like this, take ``demosoc`` as example:
  110. .. code-block::
  111. SoC/demosoc
  112. ├── Board
  113. │   └── nuclei_fpga_eval
  114. │   ├── Include
  115. │   │   ├── board_nuclei_fpga_eval.h
  116. │   │   └── nuclei_sdk_hal.h
  117. │   ├── Source
  118. │   │ └── GCC
  119. │   └── openocd_demosoc.cfg
  120. ├── build.mk
  121. └── Common
  122. ├── Include
  123. │   ├── demosoc.h
  124. │   ├── ... ...
  125. │   ├── demosoc_uart.h
  126. │   ├── nuclei_sdk_soc.h
  127. │   └── system_demosoc.h
  128. └── Source
  129. ├── Drivers
  130. │   ├── ... ...
  131. │   └── demosoc_uart.c
  132. ├── GCC
  133. │   ├── intexc_demosoc.S
  134. │   └── startup_demosoc.S
  135. ├── Stubs
  136. │   ├── read.c
  137. │   ├── ... ...
  138. │   └── write.c
  139. ├── demosoc_common.c
  140. └── system_demosoc.c
  141. .. _develop_buildsystem_makefile_rtos:
  142. Makefile.rtos
  143. ~~~~~~~~~~~~~
  144. This **Makefile.rtos** will include **<NUCLEI_SDK_ROOT>/OS/<RTOS>/build.mk**
  145. according to our :ref:`develop_buildsystem_var_rtos` variable.
  146. A valid rtos should be organized like this, take ``UCOSII`` as example:
  147. .. code-block::
  148. OS/UCOSII/
  149. ├── arch
  150. ├── build.mk
  151. ├── license.txt
  152. ├── readme.md
  153. └── source
  154. If no :ref:`develop_buildsystem_var_rtos` is chosen, then RTOS
  155. code will not be included during compiling, user will develop
  156. baremetal application.
  157. If **FreeRTOS**, **UCOSII** or **RTThread** RTOS is chosen, then FreeRTOS
  158. UCOSII, or RTThread source code will be included during compiling, and extra
  159. compiler option ``-DRTOS_$(RTOS_UPPER)`` will be passed, then user can develop RTOS application.
  160. For example, if ``FreeRTOS`` is selected, then ``-DRTOS_FREERTOS`` compiler option
  161. will be passed.
  162. .. _develop_buildsystem_makefile_components:
  163. Makefile.components
  164. ~~~~~~~~~~~~~~~~~~~
  165. This **Makefile.components** will include ``build.mk`` Makefiles of selected components defined
  166. via makefile variable :ref:`develop_buildsystem_var_middleware`, the Makefiles are placed in
  167. the sub-folders of **<NUCLEI_SDK_ROOT>/Components/**.
  168. A valid middleware component should be organized like this, take ``fatfs`` as example :
  169. .. code-block::
  170. Components/fatfs/
  171. ├── build.mk
  172. ├── documents
  173. ├── LICENSE.txt
  174. └── source
  175. For example, if there are two valid middleware components in **<NUCLEI_SDK_ROOT>/Components/**, called
  176. ``fatfs`` and ``tjpgd``, and you want to use them in your application, then you can set ``MIDDLEWARE``
  177. like this ``MIDDLEWARE := fatfs tjpgd``, then the application will include these two middlewares into
  178. build process.
  179. .. _develop_buildsystem_makefile_core:
  180. Makefile.core
  181. ~~~~~~~~~~~~~
  182. This **Makefile.core** is used to define the RISC-V ARCH and ABI used during
  183. compiling of the CORE list supported.
  184. If you want to add a new **CORE**, you need to add a new line before **SUPPORTED_CORES**,
  185. and append the new **CORE** to **SUPPORTED_CORES**.
  186. For example, if you want to add a new **CORE** called **n308**, and the **n308**'s
  187. **ARCH** and **ABI** are ``rv32imafdc`` and ``ilp32d``, then you can add a new line
  188. like this ``N308_CORE_ARCH_ABI = rv32imafdc ilp32d``, and append **n308** to **SUPPORTED_CORES**
  189. like this ``SUPPORTED_CORES = n201 n201e n203 n203e n205 n205e n305 n307 n307fd n308 nx600``
  190. .. note::
  191. * The appended new **CORE** need to lower-case, e.g. *n308*
  192. * The new defined variable **N308_CORE_ARCH_ABI** need to be all upper-case.
  193. .. _develop_buildsystem_makefile_global:
  194. Makefile.global
  195. ~~~~~~~~~~~~~~~
  196. This **Makefile.global** file is an optional file, and will not be tracked by git,
  197. user can create own **Makefile.global** in **<NUCLEI_SDK_ROOT>/Build** directory.
  198. In this file, user can define custom **SOC**, **BOARD**, **DOWNLOAD** options to
  199. overwrite the default configuration.
  200. For example, if you will use only the :ref:`design_board_gd32vf103v_rvstar`, you can
  201. create the **<NUCLEI_SDK_ROOT>/Build/Makefile.global** as below:
  202. .. code-block:: Makefile
  203. SOC ?= gd32vf103
  204. BOARD ?= gd32vf103v_rvstar
  205. DOWNLOAD ?= flashxip
  206. .. note::
  207. * If you add above file, then you can build, run, debug application without passing
  208. **SOC**, **BOARD** and **DOWNLOAD** variables using make command for
  209. :ref:`design_board_gd32vf103v_rvstar` board, e.g.
  210. - Build and run application for :ref:`design_board_gd32vf103v_rvstar`: ``make run``
  211. - Debug application for :ref:`design_board_gd32vf103v_rvstar`: ``make debug``
  212. * The :ref:`design_board_gd32vf103v_rvstar` only support ``FlashXIP`` download mode.
  213. * If you create the **Makefile.global** like above sample code, you will also be able
  214. to use Nuclei SDK build system as usually, it will only change the default **SOC**,
  215. **BOARD** and **DOWNLOAD**, but you can still override the default variable using
  216. make command, such as ``make SOC=demosoc BOARD=nuclei_fpga_eval DOWNLOAD=ilm``
  217. .. _develop_buildsystem_makefile_local:
  218. Makefile.local
  219. ~~~~~~~~~~~~~~
  220. As the :ref:`develop_buildsystem_makefile_global` is used to override the default Makefile
  221. configurations, and the **Makefile.local** is used to override application level Makefile
  222. configurations, and also this file will not be tracked by git.
  223. User can create ``Makefile.local`` file in any of the application folder, placed together with
  224. the application Makefile, for example, you can create ``Makefile.local`` in ``application/baremetal/helloworld``
  225. to override default make configuration for this **helloworld** application.
  226. If you want to change the default board for **helloworld** to use :ref:`design_board_gd32vf103v_rvstar`,
  227. you can create ``application/baremetal/helloworld/Makefile.local`` as below:
  228. .. code-block:: Makefile
  229. SOC ?= gd32vf103
  230. BOARD ?= gd32vf103v_rvstar
  231. DOWNLOAD ?= flashxip
  232. .. note::
  233. * This local make configuration will override global and default make configuration.
  234. * If you just want to change only some applications' makefile configuration, you can
  235. add and update ``Makefile.local`` for those applications.
  236. .. _develop_buildsystem_make_targets:
  237. Makefile targets of make command
  238. --------------------------------
  239. Here is a list of the :ref:`table_dev_buildsystem_4`.
  240. .. _table_dev_buildsystem_4:
  241. .. list-table:: Make targets supported by Nuclei SDK Build System
  242. :widths: 20 80
  243. :header-rows: 1
  244. :align: center
  245. * - target
  246. - description
  247. * - help
  248. - display help message of Nuclei SDK build system
  249. * - info
  250. - display selected configuration information
  251. * - all
  252. - build application with selected configuration
  253. * - clean
  254. - clean application with selected configuration
  255. * - dasm
  256. - build and dissemble application with selected configuration
  257. * - bin
  258. - build and generate application binary with selected configuration
  259. * - upload
  260. - build and upload application with selected configuration
  261. * - run_openocd
  262. - run openocd server with selected configuration, and wait for gdb at port specified by $(GDB_PORT)
  263. * - run_gdb
  264. - build and start gdb process with selected configuration, and connect to localhost:$(GDB_PORT)
  265. * - debug
  266. - build and debug application with selected configuration
  267. * - run_qemu
  268. - run application on qemu machine with selected configuration
  269. * - run_xlspike
  270. - run application on xlspike with selected configuration
  271. * - size
  272. - show program size
  273. .. note::
  274. * The selected configuration is controlled by
  275. :ref:`develop_buildsystem_exposed_make_vars`
  276. * For ``run_openocd`` and ``run_gdb`` target, if you want to
  277. change a new gdb port, you can pass the variable
  278. :ref:`develop_buildsystem_var_gdb_port`
  279. * For ``run_qemu``, only ``SOC=demosoc or SOC=gd32vf103`` supported,
  280. when do this target, you can pass ``SIMU=qemu`` to support auto-exit,
  281. project recompiling is required.
  282. * For ``run_xlspike``, only ``SOC=demosoc`` supported,
  283. when do this target, you can pass ``SIMU=xlspike`` to support auto-exit,
  284. project recompiling is required.
  285. .. _develop_buildsystem_exposed_make_vars:
  286. Makefile variables passed by make command
  287. -----------------------------------------
  288. In Nuclei SDK build system, we exposed the following Makefile variables
  289. which can be passed via make command.
  290. * :ref:`develop_buildsystem_var_soc`
  291. * :ref:`develop_buildsystem_var_board`
  292. * :ref:`develop_buildsystem_var_variant`
  293. * :ref:`develop_buildsystem_var_download`
  294. * :ref:`develop_buildsystem_var_core`
  295. * :ref:`develop_buildsystem_var_archext`
  296. * :ref:`develop_buildsystem_var_simulation`
  297. * :ref:`develop_buildsystem_var_gdb_port`
  298. * :ref:`develop_buildsystem_var_v`
  299. * :ref:`develop_buildsystem_var_silent`
  300. .. note::
  301. * These variables can also be used and defined in application Makefile
  302. * If you just want to fix your running board of your application, you can
  303. just define these variables in application Makefile, if defined, then
  304. you can simply use ``make clean``, ``make upload`` or ``make debug``, etc.
  305. .. _develop_buildsystem_var_soc:
  306. SOC
  307. ~~~
  308. **SOC** variable is used to declare which SoC is used in application during compiling.
  309. You can easily find the supported SoCs in the **<NUCLEI_SDK_ROOT>/SoC** directory.
  310. Currently we support the following SoCs, see :ref:`table_dev_buildsystem_1`.
  311. .. _table_dev_buildsystem_1:
  312. .. list-table:: Supported SoCs
  313. :widths: 10, 60
  314. :header-rows: 1
  315. :align: center
  316. * - **SOC**
  317. - Reference
  318. * - gd32vf103
  319. - :ref:`design_soc_gd32vf103`
  320. * - demosoc
  321. - :ref:`design_soc_demosoc`
  322. .. note::
  323. If you are our SoC subsystem customer, in the SDK delivered to you, you can find your soc name
  324. in this **<NUCLEI_SDK_ROOT>/SoC** directory, take ``gd32vf103`` SoC as example, when ``SOC=gd32vf103``,
  325. the SoC source code in **<NUCLEI_SDK_ROOT>/SoC/gd32vf103/Common** will be used.
  326. This documentation just document the open source version of Nuclei SDK's supported SOC and Board.
  327. .. _develop_buildsystem_var_board:
  328. BOARD
  329. ~~~~~
  330. **BOARD** variable is used to declare which Board is used in application during compiling.
  331. The **BOARD** variable should match the supported boards of chosen **SOC**.
  332. You can easily find the supported Boards in the **<NUCLEI_SDK_ROOT>/<SOC>/Board/** directory.
  333. * :ref:`table_dev_buildsystem_2`
  334. * :ref:`table_dev_buildsystem_3`
  335. Currently we support the following SoCs.
  336. .. _table_dev_buildsystem_2:
  337. .. list-table:: Supported Boards when SOC=gd32vf103
  338. :widths: 20, 60
  339. :header-rows: 1
  340. :align: center
  341. * - **BOARD**
  342. - Reference
  343. * - gd32vf103v_rvstar
  344. - :ref:`design_board_gd32vf103v_rvstar`
  345. * - gd32vf103v_eval
  346. - :ref:`design_board_gd32vf103v_eval`
  347. * - gd32vf103c_longan_nano
  348. - :ref:`design_board_sipeed_longan_nano`
  349. * - gd32vf103c_t_display
  350. - :ref:`design_board_sipeed_longan_nano`
  351. .. _table_dev_buildsystem_3:
  352. .. list-table:: Supported Boards when SOC=demosoc
  353. :widths: 10 60
  354. :header-rows: 1
  355. :align: center
  356. * - **BOARD**
  357. - Reference
  358. * - nuclei_fpga_eval
  359. - :ref:`design_board_nuclei_fpga_eval`
  360. .. note::
  361. * If you only specify **SOC** variable in make command, it will use default **BOARD**
  362. and **CORE** option defined in **<NUCLEI_SDK_ROOT>/SoC/<SOC>/build.mk**
  363. * If you are our SoC subsystem customer, in the SDK delivered to you, you can check
  364. the board supported list in **<NUCLEI_SDK_ROOT>/<SOC>/Board/**, take ``SOC=gd32vf103 BOARD=gd32vf103v_rvstar``
  365. as example, the board source code located **<NUCLEI_SDK_ROOT>/gd32vf103/Board/gd32vf103v_rvstar** will be used.
  366. .. _develop_buildsystem_var_variant:
  367. VARIANT
  368. ~~~~~~~
  369. **VARIANT** variable is used to declare which variant of board is used in application during compiling.
  370. It might only affect on only small piece of board, and this is SoC and Board dependent.
  371. This variable only affect the selected board or soc, and it is target dependent.
  372. .. _develop_buildsystem_var_download:
  373. DOWNLOAD
  374. ~~~~~~~~
  375. **DOWNLOAD** variable is used to declare the download mode of the application,
  376. currently it has these modes supported as described in table
  377. :ref:`table_dev_buildsystem_5`
  378. .. _table_dev_buildsystem_5:
  379. .. list-table:: Supported download modes
  380. :widths: 10 70
  381. :header-rows: 1
  382. :align: center
  383. * - **DOWNLOAD**
  384. - Description
  385. * - ilm
  386. - | Program will be download into ilm/ram and
  387. | run directly in ilm/ram, program will lost when poweroff
  388. * - flash
  389. - | Program will be download into flash, when running,
  390. | program will be copied to ilm/ram and run in ilm/ram
  391. * - flashxip
  392. - Program will to be download into flash and run directly in flash
  393. * - ddr
  394. - | Program will to be download into ddr and
  395. | run directly in ddr, program will lost when poweroff
  396. .. note::
  397. * This variable now target dependent, and its meaning depending on how this
  398. variable is implemented in SoC's build.mk
  399. * :ref:`design_soc_gd32vf103` only support **DOWNLOAD=flashxip**
  400. * :ref:`design_soc_demosoc` support all the download modes.
  401. * **flashxip** mode in :ref:`design_soc_demosoc` is very slow due to
  402. the CORE frequency is very slow, and flash execution speed is slow
  403. * **ddr** mode is introduced in release ``0.2.5`` of Nuclei SDK
  404. * macro ``DOWNLOAD_MODE`` and ``DOWNLOAD_MODE_STRING`` will be defined in Makefile,
  405. eg. when ``DOWNLOAD=flash``, macro will be defined as ``-DDOWNLOAD_MODE=DOWNLOAD_MODE_FLASH``,
  406. and ``-DDOWNLOAD_MODE_STRING=\"flash\"``, the ``flash`` will be in upper case,
  407. currently ``DOWNLOAD_MODE_STRING`` macro is used in ``system_<Device>.c`` when
  408. banner is print.
  409. * This download mode is also used to clarify whether in the link script,
  410. your eclic vector table is placed in ``.vtable_ilm`` or ``.vtable`` section, eg.
  411. for demosoc, when ``DOWNLOAD=flash``, vector table is placed in ``.vtable_ilm`` section,
  412. and an extra macro called ``VECTOR_TABLE_REMAPPED`` will be passed in Makefile.
  413. When ``VECTOR_TABLE_REMAPPED`` is defined, it means vector table's LMA and VMA are
  414. different, it is remapped.
  415. * From release ``0.3.2``, this ``DOWNLOAD_MODE`` should not be used, and macros
  416. ``DOWNLOAD_MODE_ILM``, ``DOWNLOAD_MODE_FLASH``, ``DOWNLOAD_MODE_FLASHXIP`` and
  417. ``DOWNLOAD_MODE_DDR`` previously defined in ``riscv_encoding.h`` now are moved to
  418. ``<Device.h>`` such as ``demosoc.h``, and should be deprecated in future.
  419. Now we are directly using ``DOWNLOAD_MODE_STRING`` to pass the download mode string,
  420. no longer need to define it in source code as before.
  421. * From release ``0.3.2``, you can define **DOWNLOAD** not just the download mode list above,
  422. you can use other download mode names specified by your customized SoC.
  423. .. _develop_buildsystem_var_core:
  424. CORE
  425. ~~~~
  426. **CORE** variable is used to declare the Nuclei processor core
  427. of the application.
  428. Currently it has these cores supported as described in table
  429. :ref:`table_dev_buildsystem_6`.
  430. .. _table_dev_buildsystem_6:
  431. .. table:: Supported Nuclei Processor cores
  432. :widths: 20 20 20
  433. :align: center
  434. ======== ========== ======= =================
  435. **CORE** **ARCH** **ABI** **TUNE**
  436. n201 rv32iac ilp32 nuclei-200-series
  437. n201e rv32eac ilp32e nuclei-200-series
  438. n203 rv32imac ilp32 nuclei-200-series
  439. n203e rv32emac ilp32e nuclei-200-series
  440. n205 rv32imac ilp32 nuclei-200-series
  441. n205e rv32emac ilp32e nuclei-200-series
  442. n300 rv32imac ilp32 nuclei-300-series
  443. n300f rv32imafc ilp32f nuclei-300-series
  444. n300fd rv32imafdc ilp32d nuclei-300-series
  445. n305 rv32imac ilp32 nuclei-300-series
  446. n307 rv32imafc ilp32f nuclei-300-series
  447. n307fd rv32imafdc ilp32d nuclei-300-series
  448. n600 rv32imac ilp32 nuclei-600-series
  449. n600f rv32imafc ilp32f nuclei-600-series
  450. n600fd rv32imafdc ilp32d nuclei-600-series
  451. nx600 rv64imac lp64 nuclei-600-series
  452. nx600f rv64imafc lp64f nuclei-600-series
  453. nx600fd rv64imafdc lp64d nuclei-600-series
  454. ux600 rv64imac lp64 nuclei-600-series
  455. ux600f rv64imafc lp64f nuclei-600-series
  456. ux600fd rv64imafdc lp64d nuclei-600-series
  457. n900 rv32imac ilp32 nuclei-900-series
  458. n900f rv32imafc ilp32f nuclei-900-series
  459. n900fd rv32imafdc ilp32d nuclei-900-series
  460. nx900 rv64imac lp64 nuclei-900-series
  461. nx900f rv64imafc lp64f nuclei-900-series
  462. nx900fd rv64imafdc lp64d nuclei-900-series
  463. ux900 rv64imac lp64 nuclei-900-series
  464. ux900f rv64imafc lp64f nuclei-900-series
  465. ux900fd rv64imafdc lp64d nuclei-900-series
  466. ======== ========== ======= =================
  467. When **CORE** is selected, the **ARCH**, **ABI** and **TUNE** (optional) are set,
  468. and it might affect the compiler options in combination with :ref:`develop_buildsystem_var_archext`
  469. depended on the implementation of SoC build.mk.
  470. Take ``SOC=demosoc`` as example.
  471. - If **CORE=n205 ARCH_EXT=**, then ``ARCH=rv32imac, ABI=ilp32 TUNE=nuclei-200-series``.
  472. riscv arch related compile and link options will be passed, for this case, it will be
  473. ``-march=rv32imac -mabi=ilp32 -mtune=nuclei-200-series``.
  474. - If **CORE=n205 ARCH_EXT=b**, it will be ``-march=rv32imacb -mabi=ilp32 -mtune=nuclei-200-series``.
  475. For riscv code model settings, the ``RISCV_CMODEL`` variable will be set to medlow
  476. for RV32 targets, otherwise it will be medany.
  477. The some SoCs, the CORE is fixed, so the ARCH and ABI will be fixed, such as
  478. ``gd32vf103`` SoC, in build system, the CORE is fixed to n205, and ARCH=rv32imac, ABI=ilp32.
  479. .. _develop_buildsystem_var_archext:
  480. ARCH_EXT
  481. ~~~~~~~~
  482. **ARCH_EXT** variable is used to select extra RISC-V arch extensions supported by Nuclei
  483. RISC-V Processor, except the ``iemafdc``.
  484. Currently, valid arch extension combination should match the order of ``bpv``.
  485. Here is a list of valid arch extensions:
  486. * **ARCH_EXT=b**: RISC-V bitmanipulation extension.
  487. * **ARCH_EXT=p**: RISC-V packed simd extension.
  488. * **ARCH_EXT=v**: RISC-V vector extension.
  489. * **ARCH_EXT=bp**: RISC-V bitmanipulation and packed simd extension.
  490. * **ARCH_EXT=pv**: RISC-V packed simd and vector extension.
  491. * **ARCH_EXT=bpv**: RISC-V bitmanipulation, packed simd and vector extension.
  492. It is suggested to use this ARCH_EXT with other arch options like this, can be found in
  493. ``SoC/demosoc/build.mk``:
  494. .. code-block:: makefile
  495. # Set RISCV_ARCH and RISCV_ABI
  496. CORE_UPPER := $(call uc, $(CORE))
  497. CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
  498. RISCV_ARCH ?= $(word 1, $(CORE_ARCH_ABI))$(ARCH_EXT)
  499. RISCV_ABI ?= $(word 2, $(CORE_ARCH_ABI))
  500. .. _develop_buildsystem_var_simulation:
  501. SIMULATION
  502. ~~~~~~~~~~
  503. If **SIMULATION=1**, it means the program is optimized for hardware simulation environment.
  504. Currently if **SIMULATION=1**, it will pass compile option **-DCFG_SIMULATION**,
  505. application can use this **CFG_SIMULATION** to optimize program for hardware
  506. simulation environment.
  507. .. note::
  508. * Currently the benchmark applications in **application/baremetal/benchmark** used this optimization
  509. .. _develop_buildsystem_var_gdb_port:
  510. GDB_PORT
  511. ~~~~~~~~
  512. .. note::
  513. * This new variable **GDB_PORT** is added in Nuclei SDK since version ``0.2.4``
  514. This variable is not used usually, by default the **GDB_PORT** variable is ``3333``.
  515. If you want to change a debug gdb port for openocd and gdb when run ``run_openocd`` and
  516. ``run_gdb`` target, you can pass a new port such as ``3344`` to this variable.
  517. For example, if you want to debug application using run_openocd and
  518. run_gdb and specify a different port other than ``3333``.
  519. You can do it like this, take ``nuclei_fpga_eval`` board for example, such as port ``3344``:
  520. * Open openocd server: ``make SOC=demosoc BOARD=nuclei_fpga_eval CORE=n307 GDB_PORT=3344 run_openocd``
  521. * connect gdb with openocd server: ``make SOC=demosoc BOARD=nuclei_fpga_eval CORE=n307 GDB_PORT=3344 run_gdb``
  522. .. _develop_buildsystem_var_banner:
  523. BANNER
  524. ~~~~~~
  525. If **BANNER=0**, when program is rebuilt, then the banner message print in console will not be print,
  526. banner print is default enabled via ``NUCLEI_BANNER=1`` in ``nuclei_sdk_hal.h``.
  527. when ``BANNER=0``, an macro ``-DNUCLEI_BANNER=0`` will be passed in Makefile.
  528. The banner message looks like this:
  529. .. code-block:: c
  530. Nuclei SDK Build Time: Jul 23 2021, 10:22:50
  531. Download Mode: ILM
  532. CPU Frequency 15999959 Hz
  533. .. _develop_buildsystem_var_v:
  534. V
  535. ~
  536. If **V=1**, it will display compiling message in verbose including compiling options.
  537. By default, no compiling options will be displayed in make console message just to print
  538. less message and make the console message cleaner. If you want to see what compiling option
  539. is used, please pass **V=1** in your make command.
  540. .. _develop_buildsystem_var_silent:
  541. SILENT
  542. ~~~~~~
  543. If **SILENT=1**, it will not display any compiling messsage.
  544. If you don't want to see any compiling message, you can pass **SILENT=1** in your make command.
  545. .. _develop_buildsystem_app_make_vars:
  546. Makefile variables used only in Application Makefile
  547. ----------------------------------------------------
  548. The following variables should be used in application Makefile at your demand,
  549. e.g. ``application/baremetal/demo_timer/Makefile``.
  550. * :ref:`develop_buildsystem_var_target`
  551. * :ref:`develop_buildsystem_var_nuclei_sdk_root`
  552. * :ref:`develop_buildsystem_var_middleware`
  553. * :ref:`develop_buildsystem_var_rtos`
  554. * :ref:`develop_buildsystem_var_stdclib`
  555. * :ref:`develop_buildsystem_var_nmsis_lib`
  556. * :ref:`develop_buildsystem_var_riscv_arch`
  557. * :ref:`develop_buildsystem_var_riscv_abi`
  558. * :ref:`develop_buildsystem_var_riscv_cmodel`
  559. * :ref:`develop_buildsystem_var_riscv_tune`
  560. * :ref:`develop_buildsystem_var_nogc`
  561. * :ref:`develop_buildsystem_var_rtthread_msh`
  562. .. _develop_buildsystem_var_target:
  563. TARGET
  564. ~~~~~~
  565. This is a necessary variable which must be defined in application Makefile.
  566. It is used to set the name of the application, it will affect the generated
  567. target filenames.
  568. .. warning::
  569. * Please don't put any spaces in TARGET variable
  570. * The variable shouldn't contain any space
  571. .. code-block:: Makefile
  572. # invalid case 1
  573. TARGET ?= hello world
  574. # invalid case 2
  575. TARGET ?= helloworld # before this # there is a extra space
  576. .. _develop_buildsystem_var_nuclei_sdk_root:
  577. NUCLEI_SDK_ROOT
  578. ~~~~~~~~~~~~~~~
  579. This is a necessary variable which must be defined in application Makefile.
  580. It is used to set the path of Nuclei SDK Root, usually it should be set as
  581. relative path, but you can also set absolute path to point to Nuclei SDK.
  582. .. _develop_buildsystem_var_rtos:
  583. RTOS
  584. ~~~~
  585. **RTOS** variable is used to choose which RTOS will be used in this application.
  586. You can easily find the supported RTOSes in the **<NUCLEI_SDK_ROOT>/OS** directory.
  587. * If **RTOS** is not defined, then baremetal service will be enabled with this application.
  588. See examples in ``application/baremetal``.
  589. * If **RTOS** is set the the following values, RTOS service will be enabled with this application.
  590. - ``FreeRTOS``: FreeRTOS service will be enabled, extra macro ``RTOS_FREERTOS`` will be defined,
  591. you can include FreeRTOS header files now, and use FreeRTOS API, for ``FreeRTOS`` application,
  592. you need to have an ``FreeRTOSConfig.h`` header file prepared in you application.
  593. See examples in ``application/freertos``.
  594. - ``UCOSII``: UCOSII service will be enabled, extra macro ``RTOS_UCOSII`` will be defined,
  595. you can include UCOSII header files now, and use UCOSII API, for ``UCOSII`` application,
  596. you need to have ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files prepared in you application.
  597. See examples in ``application/ucosii``.
  598. - ``RTThread``: RT-Thread service will be enabled, extra macro ``RTOS_RTTHREAD`` will be defined,
  599. you can include RT-Thread header files now, and use RT-Thread API, for ``UCOSII`` application,
  600. you need to have an ``rtconfig.h`` header file prepared in you application.
  601. See examples in ``application/rtthread``.
  602. .. _develop_buildsystem_var_middleware:
  603. MIDDLEWARE
  604. ~~~~~~~~~~
  605. **MIDDLEWARE** variable is used to select which middlewares should be used in this application.
  606. You can easily find the available middleware components in the **<NUCLEI_SDK_ROOT>/Components** directory.
  607. * If **MIDDLEWARE** is not defined, not leave empty, no middlware package will be selected.
  608. * If **MIDDLEWARE** is defined with more than 1 string, such as ``fatfs tjpgd``, then these two
  609. middlewares will be selected.
  610. .. _develop_buildsystem_var_nmsis_lib:
  611. NMSIS_LIB
  612. ~~~~~~~~~
  613. **NMSIS_LIB** variable is used to select which NMSIS libraries should be used in this application.
  614. Currently you can select the following libraries:
  615. * **nmsis_dsp**: NMSIS DSP prebuilt library.
  616. * **nmsis_nn**: NMSIS NN prebuilt library.
  617. You can select more than libraries of NMSIS. For example, if you want to use NMSIS NN library,
  618. NMSIS DSP library is also required. so you need to set **NMSIS_LIB** like this ``NMSIS_LIB := nmsis_nn nmsis_dsp``
  619. .. _develop_buildsystem_var_stdclib:
  620. STDCLIB
  621. ~~~~~~~
  622. **STDCLIB** variable is used to select which standard c runtime library will be used.
  623. If not defined, the default value will be ``newlib_small``.
  624. In Nuclei GNU Toolchain, we destributed newlib/newlib-nano/Nuclei c runtime library,
  625. so user can select different c runtime library according to their requirement.
  626. Newlib is a simple ANSI C library, math library, available for both RV32 and RV64.
  627. Nuclei C runtime library is a highly optimized c library designed for deeply embedded user cases,
  628. can provided smaller code size and highly optimized floating point support compared to Newlib.
  629. .. list-table:: Available STDCLIB choices
  630. :widths: 10 70
  631. :header-rows: 1
  632. :align: center
  633. * - **STDCLIB**
  634. - Description
  635. * - newlib_full
  636. - | Normal version of newlib, optimized for speed at cost of size.
  637. | It provided full feature of newlib, with file io supported.
  638. * - newlib_fast
  639. - Newlib nano version, with printf float and scanf float support.
  640. * - newlib_small
  641. - Newlib nano version, with printf float support.
  642. * - newlib_nano
  643. - Newlib nano version, without printf/scanf float support.
  644. * - libncrt_fast
  645. - Nuclei C runtime library optimized for speed, full feature
  646. * - libncrt_balanced
  647. - Nuclei C runtime library balanced at speed and code size, full feature
  648. * - libncrt_small
  649. - Nuclei C runtime library optimized for code size, full feature
  650. * - libncrt_nano
  651. - Nuclei C runtime library optimized for code size, without float/double support
  652. * - libncrt_pico
  653. - Nuclei C runtime library optimized for code size, without long/long long/float/double support
  654. * - nostd
  655. - no std c library will be used, and don't search the standard system directories for header files
  656. * - nospec
  657. - no std c library will be used, not pass any --specs options
  658. .. note::
  659. * About Newlib and Newlib nano difference, please check
  660. https://github.com/riscv-collab/riscv-newlib/blob/riscv-newlib-3.2.0/newlib/README
  661. * About Nuclei C runtime library, it didn't provided all the features that
  662. newlib can do, it is highly optimized for deeply embedded scenery
  663. * Nuclei C runtime library is only available in Nuclei GNU Toolchain released after Nov 2021.
  664. * Since there are different c runtime library can be chosen now, so developer
  665. need to provide different stub functions for different library, please check
  666. ``SoC/demosoc/Common/Source/Stubs/`` and ``SoC/demosoc/build.mk`` for example.
  667. .. _develop_buildsystem_var_smp:
  668. SMP
  669. ~~~
  670. **SMP** variable is used to control smp cpu core count, valid number must > 1.
  671. When **SMP** variable is defined, extra gcc options for ld is passed
  672. ``-Wl,--defsym=__SMP_CPU_CNT=$(SMP)``, and extra c macro ``-DSMP_CPU_CNT=$(SMP)``
  673. is defined this is passed in each SoC's build.mk, such as ``SoC/demosoc/build.mk``.
  674. And for demosoc, we use a different openocd configuration file for SMP named
  675. ``SoC/demosoc/Board/nuclei_fpga_eval/openocd_demosoc_smp.cfg``.
  676. When SMP variable is defined, extra openocd command ``set SMP $(SMP)`` will also
  677. be passed when run openocd upload or create a openocd server.
  678. .. _develop_buildsystem_var_stacksz:
  679. STACKSZ
  680. ~~~~~~~
  681. **STACKSZ** variable is used to control the per core stack size reserved in linker script,
  682. this need to cooperate with link script file and linker options.
  683. In link script file, ``__STACK_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  684. to define a weak version, such as ``PROVIDE(__STACK_SIZE = 2K);``, and gcc will pass
  685. ld options ``-Wl,--defsym=__STACK_SIZE=$(STACKSZ)`` to overwrite the default value if
  686. **STACKSZ** is defined.
  687. **STACKSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  688. For SMP version, stack size space need to reserve **STACKSZ** x SMP Core Count size.
  689. You can refer to ``SoC/demosoc/Board/nuclei_fpga_eval/Source/GCC/gcc_demosoc_ilm.ld`` for smp version.
  690. .. _develop_buildsystem_var_heapsz:
  691. HEAPSZ
  692. ~~~~~~
  693. **HEAPSZ** variable is used to control the heap size reserved in linker script,
  694. this need to cooperate with link script file and linker options.
  695. In link script file, ``__HEAP_SIZE`` symbol need to use ``PROVIDE`` feature of ld
  696. to define a weak version, such as ``PROVIDE(__HEAP_SIZE = 2K);``, and gcc will pass
  697. ld options ``-Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)`` to overwrite the default value if
  698. **HEAPSZ** is defined.
  699. **HEAPSZ** variable must be a valid value accepted by ld, such as 0x2000, 2K, 4K, 8192.
  700. .. _develop_buildsystem_var_riscv_arch:
  701. RISCV_ARCH
  702. ~~~~~~~~~~
  703. **RISCV_ARCH** variable is used to control compiler option ``-mcmodel=$(RISCV_ARCH)``.
  704. It might override RISCV_ARCH defined in SoC build.mk, according to your build.mk implementation.
  705. **RISCV_ARCH** might directly affect the gcc compiler option depended on the implementation of SoC build.mk.
  706. Take ``SOC=demosoc`` for example.
  707. * **CORE=n305 RISCV_ARCH=rv32imafdcp RISCV_ABI=ilp32d ARCH_EXT=bp**, then final compiler options will be
  708. ``-march=rv32imafdcp -mabi=ilp32d -mtune=nuclei-300-series``. The **ARCH_EXT** is ignored.
  709. .. _develop_buildsystem_var_riscv_abi:
  710. RISCV_ABI
  711. ~~~~~~~~~
  712. **RISCV_ABI** variable is used to control compiler option ``-mcmodel=$(RISCV_ABI)``.
  713. It might override RISCV_ABI defined in SoC build.mk, according to your build.mk implementation.
  714. .. _develop_buildsystem_var_riscv_cmodel:
  715. RISCV_CMODEL
  716. ~~~~~~~~~~~~
  717. **RISCV_CMODEL** is used to control compiler option ``-mcmodel=$(RISCV_CMODEL)``.
  718. For RV32, default value is ``medlow``, otherwise ``medany`` for RV64.
  719. You can set ``RISCV_CMODEL`` to override predefined value.
  720. .. _develop_buildsystem_var_riscv_tune:
  721. RISCV_TUNE
  722. ~~~~~~~~~~
  723. **RISCV_TUNE** is used to control compiler option ``-mtune=$(RISCV_TUNE)``.
  724. It is defined in SoC build.mk, you can override it if your implementation
  725. allow it.
  726. .. _develop_buildsystem_var_pfloat:
  727. PFLOAT
  728. ~~~~~~
  729. .. note::
  730. * **Deprecated** variable, please use :ref:`develop_buildsystem_var_stdclib` now
  731. * ``NEWLIB=nano PFLOAT=1`` can be replaced by ``STDCLIB=newlib_small`` now
  732. .. _develop_buildsystem_var_newlib:
  733. NEWLIB
  734. ~~~~~~
  735. .. note::
  736. * **Deprecated** variable, please use :ref:`develop_buildsystem_var_stdclib` now
  737. .. _develop_buildsystem_var_nogc:
  738. NOGC
  739. ~~~~
  740. **NOGC** variable is used to control whether to enable gc sections to reduce program
  741. code size or not, by default GC is enabled to reduce code size.
  742. When GC is enabled, these options will be added:
  743. * Adding to compiler options: ``-ffunction-sections -fdata-sections``
  744. * Adding to linker options: ``-Wl,--gc-sections -Wl,--check-sections``
  745. If you want to enable this GC feature, you can set **NOGC=0** (default), GC feature will
  746. remove sections for you, but sometimes it might remove sections that are useful,
  747. e.g. For Nuclei SDK test cases, we use ctest framework, and we need to set **NOGC=1**
  748. to disable GC feature.
  749. When ``NOGC=0``(default), extra compile options ``-ffunction-sections -fdata-sections``,
  750. and extra link options ``-Wl,--gc-sections -Wl,--check-sections`` will be passed.
  751. .. _develop_buildsystem_var_rtthread_msh:
  752. RTTHREAD_MSH
  753. ~~~~~~~~~~~~
  754. **RTTHREAD_MSH** variable is valid only when **RTOS** is set to **RTThread**.
  755. When **RTTHREAD_MSH** is set to **1**:
  756. * The RTThread MSH component source code will be included
  757. * The MSH thread will be enabled in the background
  758. * Currently the msh getchar implementation is using a weak function implemented
  759. in ``rt_hw_console_getchar`` in ``OS/RTTThread/libcpu/risc-v/nuclei/cpuport.c``
  760. .. _develop_buildsystem_app_build_vars:
  761. Build Related Makefile variables used only in Application Makefile
  762. ------------------------------------------------------------------
  763. If you want to specify additional compiler flags, please follow this guidance
  764. to modify your application Makefile.
  765. Nuclei SDK build system defined the following variables to control the
  766. build options or flags.
  767. * :ref:`develop_buildsystem_var_incdirs`
  768. * :ref:`develop_buildsystem_var_c_incdirs`
  769. * :ref:`develop_buildsystem_var_cxx_incdirs`
  770. * :ref:`develop_buildsystem_var_asm_incdirs`
  771. * :ref:`develop_buildsystem_var_srcdirs`
  772. * :ref:`develop_buildsystem_var_c_srcdirs`
  773. * :ref:`develop_buildsystem_var_cxx_srcdirs`
  774. * :ref:`develop_buildsystem_var_asm_srcdirs`
  775. * :ref:`develop_buildsystem_var_c_srcs`
  776. * :ref:`develop_buildsystem_var_cxx_srcs`
  777. * :ref:`develop_buildsystem_var_asm_srcs`
  778. * :ref:`develop_buildsystem_var_exclude_srcs`
  779. * :ref:`develop_buildsystem_var_common_flags`
  780. * :ref:`develop_buildsystem_var_cflags`
  781. * :ref:`develop_buildsystem_var_cxxflags`
  782. * :ref:`develop_buildsystem_var_asmflags`
  783. * :ref:`develop_buildsystem_var_ldflags`
  784. * :ref:`develop_buildsystem_var_ldlibs`
  785. * :ref:`develop_buildsystem_var_libdirs`
  786. * :ref:`develop_buildsystem_var_linker_script`
  787. .. _develop_buildsystem_var_incdirs:
  788. INCDIRS
  789. ~~~~~~~
  790. This **INCDIRS** is used to pass C/CPP/ASM include directories.
  791. e.g. To include current directory ``.`` and ``inc`` for C/CPP/ASM
  792. .. code-block:: makefile
  793. INCDIRS = . inc
  794. .. _develop_buildsystem_var_c_incdirs:
  795. C_INCDIRS
  796. ~~~~~~~~~
  797. This **C_INCDIRS** is used to pass C only include directories.
  798. e.g. To include current directory ``.`` and ``cinc`` for C only
  799. .. code-block:: makefile
  800. C_INCDIRS = . cinc
  801. .. _develop_buildsystem_var_cxx_incdirs:
  802. CXX_INCDIRS
  803. ~~~~~~~~~~~
  804. This **CXX_INCDIRS** is used to pass CPP only include directories.
  805. e.g. To include current directory ``.`` and ``cppinc`` for CPP only
  806. .. code-block:: makefile
  807. CXX_INCDIRS = . cppinc
  808. .. _develop_buildsystem_var_asm_incdirs:
  809. ASM_INCDIRS
  810. ~~~~~~~~~~~
  811. This **ASM_INCDIRS** is used to pass ASM only include directories.
  812. e.g. To include current directory ``.`` and ``asminc`` for ASM only
  813. .. code-block:: makefile
  814. ASM_INCDIRS = . asminc
  815. .. _develop_buildsystem_var_srcdirs:
  816. SRCDIRS
  817. ~~~~~~~
  818. This **SRCDIRS** is used to set the source directories used to search
  819. the C/CPP/ASM source code files, it will not do recursively.
  820. e.g. To search C/CPP/ASM source files in directory ``.`` and ``src``
  821. .. code-block:: makefile
  822. SRCDIRS = . src
  823. .. _develop_buildsystem_var_c_srcdirs:
  824. C_SRCDIRS
  825. ~~~~~~~~~
  826. This **C_SRCDIRS** is used to set the source directories used to search
  827. the C only source code files(*.c, *.C), it will not do recursively.
  828. e.g. To search C only source files in directory ``.`` and ``csrc``
  829. .. code-block:: makefile
  830. C_SRCDIRS = . csrc
  831. .. _develop_buildsystem_var_cxx_srcdirs:
  832. CXX_SRCDIRS
  833. ~~~~~~~~~~~
  834. This **CXX_SRCDIRS** is used to set the source directories used to search
  835. the CPP only source code files(*.cpp, *.CPP), it will not do recursively.
  836. e.g. To search CPP only source files in directory ``.`` and ``cppsrc``
  837. .. code-block:: makefile
  838. CXX_SRCDIRS = . cppsrc
  839. .. _develop_buildsystem_var_asm_srcdirs:
  840. ASM_SRCDIRS
  841. ~~~~~~~~~~~
  842. This **ASM_SRCDIRS** is used to set the source directories used to search
  843. the ASM only source code files(*.s, *.S), it will not do recursively.
  844. e.g. To search ASM only source files in directory ``.`` and ``asmsrc``
  845. .. code-block:: makefile
  846. ASM_SRCDIRS = . asmsrc
  847. .. _develop_buildsystem_var_c_srcs:
  848. C_SRCS
  849. ~~~~~~
  850. If you just want to include a few of C source files in directories, you can use this
  851. **C_SRCS** variable, makefile wildcard pattern supported.
  852. e.g. To include ``main.c`` and ``src/hello.c``
  853. .. code-block:: makefile
  854. C_SRCS = main.c src/hello.c
  855. .. _develop_buildsystem_var_cxx_srcs:
  856. CXX_SRCS
  857. ~~~~~~~~
  858. If you just want to include a few of CPP source files in directories, you can use this
  859. **CXX_SRCS** variable, makefile wildcard pattern supported.
  860. e.g. To include ``main.cpp`` and ``src/hello.cpp``
  861. .. code-block:: makefile
  862. CXX_SRCS = main.cpp src/hello.cpp
  863. .. _develop_buildsystem_var_asm_srcs:
  864. ASM_SRCS
  865. ~~~~~~~~
  866. If you just want to include a few of ASM source files in directories, you can use this
  867. **ASM_SRCS** variable, makefile wildcard pattern supported.
  868. e.g. To include ``asm.s`` and ``src/test.s``
  869. .. code-block:: makefile
  870. ASM_SRCS = asm.s src/test.s
  871. .. _develop_buildsystem_var_exclude_srcs:
  872. EXCLUDE_SRCS
  873. ~~~~~~~~~~~~
  874. If you just want to exclude a few of c/asm/cpp source files in directories,
  875. you can use this **EXCLUDE_SRCS** variable, makefile wildcard pattern supported.
  876. e.g. To exclude ``test2.c`` and ``src/test3.c``
  877. .. code-block:: makefile
  878. EXCLUDE_SRCS = test2.c src/test3.c
  879. .. _develop_buildsystem_var_common_flags:
  880. COMMON_FLAGS
  881. ~~~~~~~~~~~~
  882. This **COMMON_FLAGS** variable is used to define common compiler flags to all c/asm/cpp compiler.
  883. For example, you can add a newline ``COMMON_FLAGS += -O3 -funroll-loops -fpeel-loops``
  884. in your application Makefile and these options will be passed to C/ASM/CPP compiler.
  885. .. _develop_buildsystem_var_cflags:
  886. CFLAGS
  887. ~~~~~~
  888. Different to **COMMON_FLAGS**, this **CFLAGS** variable is used to define common compiler flags to C compiler only.
  889. For example, you can add a newline ``CFLAGS += -O3 -funroll-loops -fpeel-loops``
  890. in your application Makefile and these options will be passed to C compiler.
  891. .. _develop_buildsystem_var_cxxflags:
  892. CXXFLAGS
  893. ~~~~~~~~
  894. Different to **COMMON_FLAGS**, this **CXXFLAGS** variable is used to define common compiler flags to cpp compiler only.
  895. For example, you can add a newline ``CXXFLAGS += -O3 -funroll-loops -fpeel-loops``
  896. in your application Makefile and these options will be passed to cpp compiler.
  897. .. _develop_buildsystem_var_asmflags:
  898. ASMFLAGS
  899. ~~~~~~~~
  900. Different to **COMMON_FLAGS**, this **ASMFLAGS** variable is used to define common compiler flags to asm compiler only.
  901. For example, you can add a newline ``ASMFLAGS += -O3 -funroll-loops -fpeel-loops``
  902. in your application Makefile and these options will be passed to asm compiler.
  903. .. _develop_buildsystem_var_ldflags:
  904. LDFLAGS
  905. ~~~~~~~
  906. This **LDFLAGS** is used to pass extra linker flags, for example,
  907. if you want to link extra math library, you can add a newline
  908. ``LDFLAGS += -lm`` in you application Makefile.
  909. Libraries (-lfoo) could also be added to the LDLIBS variable instead.
  910. .. _develop_buildsystem_var_ldlibs:
  911. LDLIBS
  912. ~~~~~~
  913. This **LDLIBS** variable is library flags or names given to compilers
  914. when they are supposed to invoke the linker.
  915. Non-library linker flags, such as -L, should go in the **LDFLAGS** variable.
  916. .. _develop_buildsystem_var_libdirs:
  917. LIBDIRS
  918. ~~~~~~~
  919. This **LIBDIRS** variable is used to store the library directories, which could
  920. be used together with **LDLIBS**.
  921. For example, if you have a library located in **$(NUCLEI_SDK_ROOT)/Library/DSP/libnmsis_dsp_rv32imac.a**,
  922. and you want to link it, then you can define these lines:
  923. .. code-block:: makefile
  924. LDLIBS = -lnmsis_dsp_rv32imac
  925. LIBDIRS = $(NUCLEI_SDK_ROOT)/Library/DSP
  926. .. _develop_buildsystem_var_linker_script:
  927. LINKER_SCRIPT
  928. ~~~~~~~~~~~~~
  929. This **LINKER_SCRIPT** variable could be used to set the link script of the application.
  930. By default, there is no need to set this variable, since the build system will define
  931. a default linker script for application according to the build configuration. If you want
  932. to define your own linker script, you can set this variable.
  933. For example, ``LINKER_SCRIPT := gcc.ld``.
  934. .. _GNU Make Standard Library (GMSL): http://sourceforge.net/projects/gmsl/