appdev.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. .. _develop_appdev:
  2. Application Development
  3. =======================
  4. .. _develop_appdev_overview:
  5. Overview
  6. --------
  7. Here will describe how to develop an Nuclei SDK application.
  8. To develop a Nuclei SDK application from scratch, you can do the following steps:
  9. 1. Create a directory to place your application code.
  10. 2. Create **Makefile** in the new created directory, the minimal **Makefile** should look like this
  11. .. code-block:: makefile
  12. :linenos:
  13. TARGET = your_target_name
  14. NUCLEI_SDK_ROOT = path/to/your_nuclei_sdk_root
  15. SRCDIRS = .
  16. INCDIRS = .
  17. include $(NUCLEI_SDK_ROOT)/Build/Makefile.base
  18. 3. Copy or create your application code in new created directory.
  19. 4. Follow :ref:`develop_buildsystem` to change your application Makefile.
  20. .. _develop_appdev_addsrc:
  21. Add Extra Source Code
  22. ---------------------
  23. If you want to add extra source code, you can use these makefile variables:
  24. To add all the source code in directories, recursive search is not supported.
  25. * :ref:`develop_buildsystem_var_srcdirs`: Add C/CPP/ASM source code located
  26. in the directories defined by this variable.
  27. * :ref:`develop_buildsystem_var_c_srcdirs`: Add C only source code located
  28. in the directories defined by this variable.
  29. * :ref:`develop_buildsystem_var_cxx_srcdirs`: Add CPP only source code located
  30. in the directories defined by this variable.
  31. * :ref:`develop_buildsystem_var_asm_srcdirs`: Add ASM only source code located
  32. in the directories defined by this variable.
  33. To add only selected source code in directory
  34. * :ref:`develop_buildsystem_var_c_srcs`: Add C only source code files defined by this variable.
  35. * :ref:`develop_buildsystem_var_cxx_srcs`: Add CPP only source code files defined by this variable.
  36. * :ref:`develop_buildsystem_var_asm_srcs`: Add ASM only source code files defined by this variable.
  37. .. _develop_appdev_addinc:
  38. Add Extra Include Directory
  39. ---------------------------
  40. If you want to add extra include directories, you can use these makefile variables:
  41. * :ref:`develop_buildsystem_var_incdirs`: Include the directories defined by
  42. this variable for C/ASM/CPP code during compiling.
  43. * :ref:`develop_buildsystem_var_c_incdirs`: Include the directories defined by
  44. this variable for C only code during compiling.
  45. * :ref:`develop_buildsystem_var_cxx_incdirs`: Include the directories defined by
  46. this variable for CPP only code during compiling.
  47. * :ref:`develop_buildsystem_var_asm_incdirs`: Include the directories defined by
  48. this variable for ASM only code during compiling.
  49. .. _develop_appdev_addoptions:
  50. Add Extra Build Options
  51. -----------------------
  52. If you want to add extra build options, you can use these makefile variables:
  53. * :ref:`develop_buildsystem_var_common_flags`: This will add compiling flags
  54. for C/CPP/ASM source code.
  55. * :ref:`develop_buildsystem_var_cflags`: This will add compiling flags
  56. for C source code.
  57. * :ref:`develop_buildsystem_var_cxxflags`: This will add compiling flags
  58. for CPP source code.
  59. * :ref:`develop_buildsystem_var_asmflags`: This will add compiling flags
  60. for ASM source code.
  61. * :ref:`develop_buildsystem_var_ldflags`: This will add linker flags when linking.
  62. * :ref:`develop_buildsystem_var_ldlibs`: This will add extra libraries need to be linked.
  63. * :ref:`develop_buildsystem_var_libdirs`: This will add extra library directories to be searched by linker.
  64. .. _develop_appdev_optimize_for_codesize:
  65. Optimize For Code Size
  66. ----------------------
  67. If you want to optimize your application for code size, you set ``COMMON_FLAGS``
  68. in your application Makefile like this:
  69. .. code-block:: makefile
  70. COMMON_FLAGS := -Os
  71. If you want to optimize code size even more, you use this link time optimization(LTO) as below:
  72. .. code-block:: makefile
  73. COMMON_FLAGS := -Os -flto
  74. see :ref:`design_app_demo_eclic` for example usage of optimize for code size.
  75. For more details about gcc optimization, please refer to `Options That Control Optimization in GCC`_.
  76. .. _develop_appdev_linkscript:
  77. Change Link Script
  78. ------------------
  79. If you want to change the default link script defined by your make configuration(SOC, BOARD, DOWNLOAD).
  80. You can use :ref:`develop_buildsystem_var_linker_script` variable to set your linker script.
  81. .. _develop_appdev_setdefaultmake:
  82. Set Default Make Options
  83. ------------------------
  84. Set Default Global Make Options For Nuclei SDK
  85. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. If you want to change the global Make options for the Nuclei SDK,
  87. you can add the :ref:`develop_buildsystem_makefile_global`.
  88. Set Local Make Options For Your Application
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. If you want to change the application level Make options,
  91. you can add the :ref:`develop_buildsystem_makefile_local`.
  92. .. _Options That Control Optimization in GCC: https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Optimize-Options.html#Optimize-Options