1e41f4b71Sopenharmony_ci# Compilation and Building 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe compilation and building subsystem provides a framework based on Generate Ninja (GN) and Ninja. This subsystem allows you to: 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci- Build products based on different chipset platforms, for example, Hi3516D V300. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- Package capabilities required by a product by assembling modules based on the product configuration. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Introduction 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciIt is considered best practice to learn the following basic concepts before you start building: 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci- Platform 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci A combination of development boards and kernels. Supported subsystems and components vary with the platform. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci- Subsystem 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci OpenHarmony is designed with a layered architecture, which consists of the kernel layer, system service layer, framework layer, and application layer from the bottom up. System functions are developed by the level of system, subsystem, and component. In a multi-device deployment scenario, you can customize subsystems and components as required. A subsystem is a logical system consisting of components. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci- Component 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci A component is a reusable software unit that contains source code, configuration files, resource files, and build scripts. A component can be built independently, integrated in binary mode, and then tested independently. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci- GN 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci GN is a system used to generate build files for Ninja. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci- Ninja 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci Ninja is a small high-speed build system. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## Directory Structure 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci```text 37e41f4b71Sopenharmony_ci/build # Main directory 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci├── __pycache__ 40e41f4b71Sopenharmony_ci├── build_scripts/ # Python scripts for build 41e41f4b71Sopenharmony_ci├── common/ 42e41f4b71Sopenharmony_ci├── config/ # Build-related configuration 43e41f4b71Sopenharmony_ci├── core 44e41f4b71Sopenharmony_ci│ └── gn/ # BUILD.gn configuration 45e41f4b71Sopenharmony_ci│ └── build_scripts/ 46e41f4b71Sopenharmony_ci├── docs 47e41f4b71Sopenharmony_ci├── gn_helpers.py* 48e41f4b71Sopenharmony_ci├── lite/ # hb and preloader entry 49e41f4b71Sopenharmony_ci├── misc/ 50e41f4b71Sopenharmony_ci├── ohos # OpenHarmony building and packaging configuration 51e41f4b71Sopenharmony_ci│ ├── kits # Kits build and packaging templates and processing 52e41f4b71Sopenharmony_ci│ ├── ndk # NDK templates and processing 53e41f4b71Sopenharmony_ci│ ├── notice # Notice templates and processing 54e41f4b71Sopenharmony_ci│ ├── packages # Distribution packaging templates and processing 55e41f4b71Sopenharmony_ci│ ├── sa_profile # SA profiles and processing 56e41f4b71Sopenharmony_ci│ ├── sdk # SDK templates and processing, which contains the module configuration in the SDK 57e41f4b71Sopenharmony_ci│ └── testfwk # Testing-related processing 58e41f4b71Sopenharmony_ci├── ohos.gni* # Common .gni files (facilitating one-time import of each module) 59e41f4b71Sopenharmony_ci├── ohos_system.prop 60e41f4b71Sopenharmony_ci├── ohos_var.gni* 61e41f4b71Sopenharmony_ci├── prebuilts_download.sh* # Prebuilt script 62e41f4b71Sopenharmony_ci├── print_python_deps.py* 63e41f4b71Sopenharmony_ci├── scripts/ 64e41f4b71Sopenharmony_ci├── subsystem_config.json 65e41f4b71Sopenharmony_ci├── subsystem_config_example.json 66e41f4b71Sopenharmony_ci├── templates/ # C/C++ build templates 67e41f4b71Sopenharmony_ci├── test.gni* 68e41f4b71Sopenharmony_ci├── toolchain # Build toolchain configuration 69e41f4b71Sopenharmony_ci├── tools # Common tools 70e41f4b71Sopenharmony_ci├── version.gni 71e41f4b71Sopenharmony_ci├── zip.py* 72e41f4b71Sopenharmony_ci``` 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Figure 1** Architecture of the compilation and building subsystem 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci## Working Principles 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciThe compilation and build process of OpenHarmony is as follows: 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci1. Parsing commands: Parse the name of the product to build and load related configurations. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci2. Running GN: Configure the toolchain and global options based on the parsed product name and compilation type. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci3. Running Ninja: Start building and generate a product distribution. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci## Building a Mini or Small System 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ciSee [build\_lite](https://gitee.com/openharmony/build_lite/blob/master/README.md). 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## Building a Standard System 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciSee [build](https://gitee.com/openharmony/build). 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci## Repositories Involved 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci[build\_lite](https://gitee.com/openharmony/build_lite) 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci[build](https://gitee.com/openharmony/build) 102