AliOS Things build system - Shaofa/AliOS-Things-Certification-Manual GitHub Wiki
EN | 中文
Generally speaking, the construction of a project contains following elements:
The so-called component-based thought means that all functional modules can be tailored and spliced at will. The realization of this idea is mainly dependent on the construction of system, where each component has its corresponding .mk file.
Because of the idea of component-based management, in order to isolate each component and configure each of them independently, a .mk file is placed in each component's directory to store its specific operation configuration, and association among components is defined through dependency relationship. The unified operating mechanism shared among all components of the system is placed in the .mk file under the build directory. In this way, isolation of components and flexibility of modification can be achieved at the same time.
Overall process
There are three steps in the overall construction process:
In short, all the information required in the elements mentioned above except tool chain is included in, for example config.mk, xx.c_opts and link.opts in the second steps, and the core of the construction is the generation and usage of these files.
More details are shown as followed:
A module's mk file basically describes how the component is build, so it's very important. In the following text, examples will be given to illustrate its main content:
In this list, the global is the settings used in compilation of all components, while the local is used only in compilation of a specific component. A mk file describes the configuration information of a component. All the configuration settings can be specified in _CFLAGS and _LDFLAGS, including link scripts used in links.
In the following part, detailed implementation process and corresponding key code will be illustrated according to the elements mentioned above:
The host platform is set in aos.py, while the auxiliary command tools are set in aos_host_cmd.mk, which currently mainly support two host platforms, windows and linux64.
The setting of compilation tool chain is set in aos_target_xx.mk and aos_library_xx.mk.
The compilation order is always the name of app @ the name of board. App and board are two entry components that the search process is relied on.
The dependency search is mainly implemented through recursion:
In fact, in addition to the source file, the search process will also find out information about the defined compilation options in mk file. The process is actually parsing the mk file of the component through recursion. It makes preparation for the later compilation and link steps.
Store the information getting from the above recursion parsing about mk file in config.mk:
Config.mk is actually the collection of information in mk file of all the components, while opts file is an independent file that reorganizes information in mk file based on each component.
compilation order
compilation option of each component is generated.
Link order
link option is generated.
Unified binary processing, such as strip.
Execute self-defined operations for each component.
FIND_COMPONENT --Find all the required component parameters: all basic components, recursive calls.
PREPROCESS_TEST_COMPONENT -- Add the components needed for tests with no parameter.
PROCESS_COMPONENT -- Parse the mk file of each component, parameters: all components.
PROCESS_ONE_COMPONENT -- Parse a component, parameter: a specific component.
WRITE_FILE_CREATE -- Write all the relevant information in config.mk and write compilation and link options in opts file.