1# Copyright (c) 2023 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("${device_path}/config.gni")
15
16config("gcc_cpu_arch") {
17  arch_cflags = board_cflags
18  if (board_arch != "") {
19    arch_cflags += [ "-march=$board_arch" ]
20  }
21  if (board_cpu != "") {
22    arch_cflags += [ "-mcpu=$board_cpu" ]
23  }
24  cflags = arch_cflags
25  cflags_cc = cflags
26  ldflags = cflags
27  asmflags = cflags
28}
29
30config("gcc_common") {
31  defines = [ "_XOPEN_SOURCE=700" ]
32  cflags = [
33    "-fno-common",
34    "-fno-builtin",
35    "-fno-strict-aliasing",
36    "-Wall",
37  ]
38  if (ohos_kernel_type == "linux") {
39    cflags += [
40      "-funwind-tables",
41      "-fasynchronous-unwind-tables",
42    ]
43  }
44  cflags_cc = cflags
45  cflags += [ "-fsigned-char" ]
46}
47
48config("gcc_security") {
49  defines = [ "_FORTIFY_SOURCE=2" ]
50  cflags = [ "-fstack-protector-all" ]
51  cflags_cc = cflags
52  ldflags = [
53    "-Wl,-z,now",
54    "-Wl,-z,relro",
55    "-Wl,-z,noexecstack",
56  ]
57}
58
59config("gcc_exceptions") {
60  cflags_cc = [ "-fexceptions" ]
61  cflags_objcc = cflags_cc
62}
63
64config("gcc_stack_protector") {
65  cflags = [ "-fstack-protector-all" ]
66  cflags_cc = cflags
67}
68
69config("gcc_static_pie_config") {
70  cflags = [ "-fPIE" ]
71  cflags_cc = cflags
72}
73
74config("gcc_shared_library_config") {
75  cflags = [ "-fPIC" ]
76  cflags_cc = cflags
77}
78
79config("gcc_pie_executable_config") {
80  ldflags = [ "-pie" ]
81}
82
83config("gcc_opt") {
84  cflags = [ "-Os" ]
85  cflags_cc = cflags
86}
87
88config("gcc_default_link_path") {
89  ldflags = [
90    "-L.",
91    "-Wl,-rpath-link=.",
92  ]
93}
94
95config("gcc_kernel_configs") {
96  configs = []
97  if (ohos_kernel_type == "liteos_a") {
98    configs += [
99      ":gcc_security",
100      ":gcc_exceptions",
101      "//build/lite/config/kernel/liteos/cortex_a:default",
102    ]
103  }
104  if (ohos_kernel_type == "linux") {
105    configs += [
106      ":gcc_security",
107      ":gcc_exceptions",
108    ]
109  }
110  if (ohos_kernel_type == "liteos_m") {
111    configs += [ ":gcc_stack_protector" ]
112  }
113}
114
115config("gcc_build_type_configs") {
116  configs = []
117  if (ohos_build_type == "debug") {
118    configs += [ "//build/config/compiler/lite/common:debug" ]
119  } else if (ohos_build_type == "release") {
120    configs += [ "//build/config/compiler/lite/common:release" ]
121  }
122}
123
124config("gcc_compiler_configs") {
125  configs = []
126  if (current_os == "ohos") {
127    configs += [
128      ":gcc_cpu_arch",
129      ":gcc_common",
130      ":gcc_default_link_path",
131      ":gcc_kernel_configs",
132      "//build/config/compiler/lite/common:board_config",
133      "//build/config/compiler/lite/common:kernel_macros",
134    ]
135  }
136  configs += [ ":gcc_build_type_configs" ]
137}
138
139config("gcc_shared_library_configs") {
140  configs = [
141    ":gcc_compiler_configs",
142    ":gcc_shared_library_config",
143  ]
144}
145
146config("gcc_static_library_configs") {
147  configs = [ ":gcc_compiler_configs" ]
148  if (ohos_kernel_type != "liteos_m") {
149    configs += [ ":gcc_static_pie_config" ]
150  }
151}
152
153config("gcc_executable_configs") {
154  configs = [ ":gcc_compiler_configs" ]
155  if (ohos_kernel_type != "liteos_m") {
156    configs += [
157      ":gcc_static_pie_config",
158      ":gcc_pie_executable_config",
159      "//build/config/compiler/lite/common:board_exe_ld_flags",
160    ]
161  }
162}
163