• 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
47config("arch_config") {
48  cflags = arch_config_cflags
49  asmflags = arch_config_asmflags
50  ldflags = arch_config_ldflags
51}
52
53config("stdinc_config") {
54  cflags = stdinc_config_cflags
55  asmflags = stdinc_config_asmflags
56  if (!defined(LOSCFG_COMPILER_ICCARM)) {
57    std_include = exec_script("//build/lite/run_shell_cmd.py",
58                              [ "$cc -print-file-name=include" ],
59                              "trim string")
60    cflags += [
61      "-isystem",
62      std_include,
63    ]
64  }
65}
66
67config("ssp_config") {
68  cflags = ssp_config_cflags
69  asmflags = ssp_config_asmflags
70}
71
72config("optimize_config") {
73  cflags = optimize_config_cflags
74  asmflags = optimize_config_asmflags
75}
76
77config("kconfig_config") {
78  cflags = kconfig_config_cflags
79  asmflags = kconfig_config_asmflags
80}
81
82config("warn_config") {
83  cflags = warn_config_cflags
84  asmflags = warn_config_asmflags
85}
86
87config("dialect_config") {
88  cflags_c = dialect_config_cflags
89  cflags_cc = dialect_config_ccflags
90  asmflags = dialect_config_asmflags
91}
92
93config("misc_config") {
94  defines = []
95  if (!defined(LOSCFG_COMPILER_ICCARM)) {
96    defines += [ "__LITEOS__" ]
97    defines += [ "__LITEOS_M__" ]
98  }
99  if (!defined(LOSCFG_DEBUG_VERSION)) {
100    defines += [ "NDEBUG" ]
101  }
102  cflags = misc_config_cflags
103  asmflags = misc_config_asmflags
104}
105
106config("los_config") {
107  configs = [
108    #":arch_config",
109    ":kconfig_config",
110
111    ":stdinc_config",
112    ":dialect_config",
113    ":optimize_config",
114    ":ssp_config",
115
116    #":warn_config",
117    ":misc_config",
118  ]
119}
120
121cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
122HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
123
124# If device_path points to vendor, use device_path directly,
125# otherwise board is decoupled from soc, device_path should contain board
126BOARD_SOC_FEATURE =
127    device_path == string_replace(device_path, "/vendor/", "") &&
128    device_path != string_replace(device_path, "/board/", "")
129
130config("public") {
131  configs = [
132    "arch:public",
133    "kernel:public",
134    "kal:public",
135    "components:public",
136    "utils:public",
137  ]
138
139  if (BOARD_SOC_FEATURE) {
140    configs += [ "$DEVICE_BOARD_DIR/$device_company:public" ]
141    configs += [ "$DEVICE_SOC_DIR/$LOSCFG_SOC_COMPANY:public" ]
142  } else {
143    if (HAVE_DEVICE_SDK) {
144      configs += [ "$device_path:public" ]
145    }
146  }
147}
148
149group("modules") {
150  deps = [
151    "arch",
152    "components",
153    "kal",
154    "kernel",
155    "testsuites",
156    "utils",
157    HDFTOPDIR,
158  ]
159
160  if (BOARD_SOC_FEATURE) {
161    deps += [ "$DEVICE_BOARD_DIR/$device_company" ]
162    deps += [ "$DEVICE_SOC_DIR/$LOSCFG_SOC_COMPANY" ]
163  } else {
164    if (HAVE_DEVICE_SDK) {
165      deps += [ device_path ]
166    }
167  }
168}
169
170# when HAVE_DEVICE_SDK is not reached, gn raises an error. so we just use it as
171# not needed
172not_needed([ "HAVE_DEVICE_SDK" ])
173
174static_library("libkernel") {
175  deps = [ ":modules" ]
176  if (defined(LOSCFG_COMPILER_ICCARM)) {
177    complete_static_lib = true
178  } else {
179    complete_static_lib = false
180  }
181}
182
183group("kernel") {
184  deps = [ ":libkernel" ]
185}
186
187group("liteos_m") {
188}
189
190executable("liteos") {
191  configs += [
192    ":public",
193    ":los_config",
194  ]
195
196  ldflags = executable_config_ldflags
197
198  output_dir = target_out_dir
199
200  if (liteos_kernel_only) {
201    deps = [ ":kernel" ]
202  } else {
203    deps = [ "//build/lite:ohos" ]
204  }
205}
206
207copy("copy_liteos") {
208  deps = [ ":liteos" ]
209  sources = [ "$target_out_dir/unstripped/bin/liteos" ]
210  outputs = [ "$root_out_dir/$liteos_name" ]
211}
212
213build_ext_component("build_kernel_image") {
214  deps = [ ":copy_liteos" ]
215  exec_path = rebase_path(root_out_dir)
216
217  command = toochain_config_command
218}
219