• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("$build_root/config/aosp/config.gni")
15import("$build_root/config/clang/clang.gni")
16import("$build_root/config/compiler/compiler.gni")
17
18assert(is_android)
19
20config("compiler") {
21  if (current_cpu == "arm64") {
22    abi_target = "aarch64-linux-android"
23    compile_api_level = aosp64_ndk_api_level
24  } else {
25    assert(false, "Architecture not supported")
26  }
27
28  cflags = [
29    "--target=$abi_target",
30    "-isystem" + rebase_path("$aosp_ndk_root/sysroot/usr/include/$abi_target",
31                             root_build_dir),
32    "-D__ANDROID_API__=$compile_api_level",
33  ]
34  if (compile_api_level < 20) {
35    cflags += [ "-DHAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC=1" ]
36  }
37
38  asmflags = cflags
39
40  ldflags = [
41    "--target=$abi_target",
42    "-Wl,--no-undefined",
43    "-Wl,--exclude-libs=libgcc.a",
44    "-Wl,--exclude-libs=libc++_static.a",
45    "-Wl,--exclude-libs=libvpx_assembly_arm.a",
46  ]
47}
48
49config("runtime_config") {
50  cflags_cc = []
51  cflags_cc = []
52  if (aosp_ndk_major_version >= 13) {
53    libcxx_include_path =
54        rebase_path("$aosp_libcpp_root/include", root_build_dir)
55    libcxxabi_include_path =
56        rebase_path("$aosp_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
57                    root_build_dir)
58  } else {
59    libcxx_include_path =
60        rebase_path("$aosp_libcpp_root/libcxx/include", root_build_dir)
61    libcxxabi_include_path = rebase_path(
62            "$aosp_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
63            root_build_dir)
64  }
65  cflags_cc += [
66    "-isystem" + libcxx_include_path,
67    "-isystem" + libcxxabi_include_path,
68  ]
69
70  defines = [
71    "__GNU_SOURCE=1",  # Necessary for clone().
72  ]
73  ldflags = [ "-nostdlib" ]
74  lib_dirs = [ aosp_libcpp_lib_dir ]
75
76  libs = []
77  libs += [ "c++_static" ]
78  libs += [ "c++abi" ]
79
80  # Manually link the libgcc.a that the cross compiler uses. This is
81  # absolute because the linker will look inside the sysroot if it's not.
82  libs += [
83    rebase_path(aosp_libgcc_file),
84    "c",
85  ]
86
87  ldflags += [ "-Wl,--warn-shared-textrel" ]
88}
89
90config("executable_config") {
91  cflags = [ "-fPIE" ]
92  asmflags = [ "-fPIE" ]
93  ldflags = [ "-pie" ]
94}
95