• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2020 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
14config("cpu_arch") {
15  cflags = []
16  if (target_cpu == "cortex-a7") {
17    cflags += [
18      "-mcpu=cortex-a7",
19      "-mfloat-abi=softfp",
20      "-mfpu=neon-vfpv4",
21    ]
22  } else if (target_cpu == "cortex-m4") {
23    cflags += [
24      "-mcpu=cortex-m4",
25      "-march=armv7e-m",
26      "-mthumb",
27    ]
28  }
29  asmflags = cflags
30  cflags_cc = cflags
31}
32
33config("base") {
34  defines = [ "_FORTIFY_SOURCE=2" ]
35
36  if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "liteos_m") {
37    defines += [ "__LITEOS__" ]
38  } else if (ohos_kernel_type == "linux_4_9") {
39    defines += [ "__LINUX__" ]
40  }
41
42  cflags = [
43    "-fno-omit-frame-pointer",
44    "-nostdlib",
45    "-mno-unaligned-access",
46    "-fno-builtin",
47    "-Werror",
48  ]
49
50  cflags_cc = cflags
51  cflags += [ "-std=c99" ]
52
53  ldflags = [
54    "-lc",
55    "-Wl,-z,now",
56    "-Wl,-z,relro",
57    "-Wl,-z,noexecstack",
58  ]
59}
60
61config("exceptions") {
62  cflags_cc = [ "-fexceptions" ]
63  cflags_objcc = cflags_cc
64}
65
66config("no_exceptions") {
67  cflags_cc = [ "-fno-exceptions" ]
68  cflags_objcc = cflags_cc
69  ldflags = cflags_cc
70}
71
72config("stack_protector") {
73  cflags = [ "-fstack-protector-all" ]
74  cflags_cc = cflags
75}
76
77config("static_pie_config") {
78  cflags = [ "-fPIE" ]
79  cflags_cc = cflags
80}
81
82config("shared_library_config") {
83  cflags = [ "-fPIC" ]
84  cflags_cc = cflags
85}
86
87config("pie_executable_config") {
88  ldflags = [ "-pie" ]
89}
90
91config("clang") {
92  include_dirs = [
93    "//clang/include/c++/v1",
94    "//sysroot/usr/include/arm-liteos-ohos",
95  ]
96
97  cflags = [
98    "--target=arm-liteos-ohos",
99    "-mcpu=cortex-a7",
100    "-march=armv7-a",
101    "-mfloat-abi=softfp",
102    "--sysroot=${root_out_dir}/sysroot",
103  ]
104  cflags_cc = cflags
105
106  ldflags = cflags
107
108  ldflags += [
109    "-L../clang/arm-liteos-ohos/c++",
110    "-L${root_out_dir}/sysroot/usr/lib/arm-liteos-ohos",
111    "-L../clang/current/lib/arm-liteos-ohos",
112    "-L../clang/arm-liteos-ohos/c++",
113    "-lclang_rt.builtins",
114    "-lc",
115    "-lc++",
116    "-lc++abi",
117    "--sysroot=${root_out_dir}/sysroot",
118  ]
119}
120
121config("clang_release") {
122  cflags = [
123    "-Oz",
124    "-flto",
125  ]
126  cflags_cc = cflags
127}
128
129config("release") {
130  defines = [ "OHOS_RELEASE" ]
131  cflags = [ "-O2" ]
132  cflags_cc = cflags
133}
134
135config("debug") {
136  defines = [ "OHOS_DEBUG" ]
137  cflags = [ "-g" ]
138  cflags_cc = cflags
139}
140
141config("gcc") {
142  include_dirs = []
143  if (ohos_kernel_type == "liteos_a") {
144    include_dirs += [ "//gcc/target/usr/include" ]
145    ldflags = [ "-L$ohos_root_path/gcc/target/usr/lib" ]
146  }
147}
148
149config("sysroot") {
150  include_dirs = [ "//sysroot/usr/include" ]
151  ldflags = [ "-L$ohos_root_path/sysroot/usr/lib" ]
152}
153
154config("ohos") {
155  configs = [
156    ":base",
157    ":cpu_arch",
158    ":stack_protector",
159    ":exceptions",
160  ]
161
162  if (ohos_build_type == "release") {
163    configs += [ ":release" ]
164  } else if (ohos_build_type == "debug") {
165    configs += [ ":debug" ]
166  }
167
168  if (ohos_build_compiler == "gcc") {
169    configs += [ ":gcc" ]
170  } else if (ohos_build_compiler == "clang") {
171    configs += [ ":clang" ]
172    configs += [ ":sysroot" ]
173    if (ohos_build_type == "release") {
174      configs += [ ":clang_release" ]
175    }
176  }
177}
178
179config("tools") {
180  # Add tools configs if any
181}
182