• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
2# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without modification,
5# are permitted provided that the following conditions are met:
6#
7# 1. Redistributions of source code must retain the above copyright notice, this list of
8#    conditions and the following disclaimer.
9#
10# 2. Redistributions in binary form must reproduce the above copyright notice, this list
11#    of conditions and the following disclaimer in the documentation and/or other materials
12#    provided with the distribution.
13#
14# 3. Neither the name of the copyright holder nor the names of its contributors may be used
15#    to endorse or promote products derived from this software without specific prior written
16#    permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30import("//build/lite/config/component/lite_component.gni")
31
32LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
33
34import("liteos.gni")
35
36if (defined(LOSCFG_COMPILER_ICCARM)) {
37  import("config_iccarm.gni")
38} else {
39  import("config.gni")
40
41  cc = "$ohos_current_cc_command " + string_join(" ", liteos_arch_config_cflags)
42  if (ohos_build_compiler == "clang") {
43    cc += " --target=$target_triple"
44  }
45}
46
47declare_args() {
48  liteos_build_asm = true
49}
50
51config("arch_config") {
52  cflags = arch_config_cflags
53  asmflags = arch_config_asmflags
54  ldflags = arch_config_ldflags
55}
56
57config("stdinc_config") {
58  cflags = stdinc_config_cflags
59  asmflags = stdinc_config_asmflags
60  if (!defined(LOSCFG_COMPILER_ICCARM)) {
61    std_include = exec_script("//build/lite/run_shell_cmd.py",
62                              [ "$cc -print-file-name=include" ],
63                              "trim string")
64    cflags += [
65      "-isystem",
66      std_include,
67    ]
68  }
69}
70
71config("ssp_config") {
72  cflags = ssp_config_cflags
73  asmflags = ssp_config_asmflags
74}
75
76config("optimize_config") {
77  cflags = optimize_config_cflags
78  asmflags = optimize_config_asmflags
79}
80
81config("kconfig_config") {
82  cflags = kconfig_config_cflags
83  asmflags = kconfig_config_asmflags
84}
85
86config("warn_config") {
87  cflags = warn_config_cflags
88  asmflags = warn_config_asmflags
89}
90
91config("dialect_config") {
92  cflags_c = dialect_config_cflags
93  cflags_cc = dialect_config_ccflags
94  asmflags = dialect_config_asmflags
95}
96
97config("misc_config") {
98  defines = []
99  if (!defined(LOSCFG_COMPILER_ICCARM)) {
100    defines += [ "__LITEOS__" ]
101    defines += [ "__LITEOS_M__" ]
102  }
103  if (!defined(LOSCFG_DEBUG_VERSION)) {
104    defines += [ "NDEBUG" ]
105  }
106  cflags = misc_config_cflags
107  asmflags = misc_config_asmflags
108}
109
110config("los_config") {
111  configs = [
112    #":arch_config",
113    ":kconfig_config",
114
115    ":stdinc_config",
116    ":dialect_config",
117    ":optimize_config",
118    ":ssp_config",
119
120    #":warn_config",
121    ":misc_config",
122  ]
123}
124
125cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
126HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
127
128# If device_path points to vendor, use device_path directly,
129# otherwise board is decoupled from soc, device_path should contain board
130BOARD_SOC_FEATURE =
131    device_path == string_replace(device_path, "/vendor/", "") &&
132    device_path != string_replace(device_path, "/board/", "")
133
134config("public") {
135  configs = [
136    "arch:public",
137    "kernel:public",
138    "kal:public",
139    "components:public",
140    "utils:public",
141  ]
142
143  if (BOARD_SOC_FEATURE) {
144    configs += [ "$DEVICE_BOARD_DIR/$device_company:public" ]
145    configs += [ "$DEVICE_SOC_DIR/$LOSCFG_SOC_COMPANY:public" ]
146  } else {
147    if (HAVE_DEVICE_SDK) {
148      configs += [ "$device_path:public" ]
149    }
150  }
151}
152
153group("modules") {
154  deps = [
155    "arch",
156    "components",
157    "kal",
158    "kernel",
159    "testsuites",
160    "utils",
161    HDFTOPDIR,
162  ]
163
164  if (BOARD_SOC_FEATURE) {
165    deps += [ "$DEVICE_BOARD_DIR/$device_company" ]
166    deps += [ "$DEVICE_SOC_DIR/$LOSCFG_SOC_COMPANY" ]
167  } else {
168    if (HAVE_DEVICE_SDK) {
169      deps += [ device_path ]
170    }
171  }
172}
173
174# when HAVE_DEVICE_SDK is not reached, gn raises an error. so we just use it as
175# not needed
176not_needed([ "HAVE_DEVICE_SDK" ])
177
178static_library("libkernel") {
179  deps = [ ":modules" ]
180  if (defined(LOSCFG_COMPILER_ICCARM)) {
181    complete_static_lib = true
182  } else {
183    complete_static_lib = false
184  }
185}
186
187group("kernel") {
188  deps = [ ":libkernel" ]
189}
190
191group("liteos_m") {
192}
193
194executable("liteos") {
195  configs += [
196    ":public",
197    ":los_config",
198  ]
199
200  ldflags = executable_config_ldflags
201
202  output_dir = target_out_dir
203
204  if (liteos_kernel_only) {
205    deps = [ ":kernel" ]
206  } else {
207    deps = [ "//build/lite:ohos" ]
208  }
209}
210
211copy("copy_liteos") {
212  deps = [ ":liteos" ]
213  sources = [ "$target_out_dir/unstripped/bin/liteos" ]
214  outputs = [ "$root_out_dir/$liteos_name" ]
215}
216
217build_ext_component("build_kernel_image") {
218  deps = [ ":copy_liteos" ]
219  exec_path = rebase_path(root_out_dir)
220
221  command = toochain_config_command
222  if (liteos_build_asm) {
223    command += toochain_asm_command
224  }
225}
226