1e509ee18Sopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd.
2e509ee18Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3e509ee18Sopenharmony_ci# you may not use this file except in compliance with the License.
4e509ee18Sopenharmony_ci# You may obtain a copy of the License at
5e509ee18Sopenharmony_ci#
6e509ee18Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
7e509ee18Sopenharmony_ci#
8e509ee18Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9e509ee18Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10e509ee18Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11e509ee18Sopenharmony_ci# See the License for the specific language governing permissions and
12e509ee18Sopenharmony_ci# limitations under the License.
13e509ee18Sopenharmony_ci
14e509ee18Sopenharmony_ciassert(is_android)
15e509ee18Sopenharmony_ci
16e509ee18Sopenharmony_ciimport("abi.gni")
17e509ee18Sopenharmony_ci
18e509ee18Sopenharmony_ci# Get Android Env used to build Android Library.
19e509ee18Sopenharmony_ciANDROID_HOME = getenv("ANDROID_HOME")
20e509ee18Sopenharmony_ciif (ANDROID_HOME == "") {
21e509ee18Sopenharmony_ci  assert(
22e509ee18Sopenharmony_ci      false,
23e509ee18Sopenharmony_ci      "Maybe you have not set up android development environment." +
24e509ee18Sopenharmony_ci          " Or some environment variable is named differently. Check, please!" +
25e509ee18Sopenharmony_ci          " Get set-up steps from https://gitee.com/ark_standalone_build/docs")
26e509ee18Sopenharmony_ci} else {
27e509ee18Sopenharmony_ci  print("ANDROID_HOME=$ANDROID_HOME")
28e509ee18Sopenharmony_ci}
29e509ee18Sopenharmony_ci
30e509ee18Sopenharmony_ci# Using a separate declare_args block for only these arguments, so that
31e509ee18Sopenharmony_ci# we can decide if we have to pull in definitions from the internal config
32e509ee18Sopenharmony_ci# early.
33e509ee18Sopenharmony_cideclare_args() {
34e509ee18Sopenharmony_ci  # AOSP API level for 64 bits platforms
35e509ee18Sopenharmony_ci  aosp64_ndk_api_level = 29
36e509ee18Sopenharmony_ci}
37e509ee18Sopenharmony_ci
38e509ee18Sopenharmony_ciif (!defined(default_aosp_ndk_root)) {
39e509ee18Sopenharmony_ci  default_aosp_ndk_root = "${ANDROID_HOME}/ndk/21.3.6528147"
40e509ee18Sopenharmony_ci  default_aosp_ndk_major_version = 16
41e509ee18Sopenharmony_ci} else {
42e509ee18Sopenharmony_ci  assert(defined(default_aosp_ndk_major_version))
43e509ee18Sopenharmony_ci}
44e509ee18Sopenharmony_ci
45e509ee18Sopenharmony_cideclare_args() {
46e509ee18Sopenharmony_ci  aosp_ndk_root = default_aosp_ndk_root
47e509ee18Sopenharmony_ci  aosp_ndk_major_version = default_aosp_ndk_major_version
48e509ee18Sopenharmony_ci
49e509ee18Sopenharmony_ci  # Libc++ library directory. Override to use a custom libc++ binary.
50e509ee18Sopenharmony_ci  aosp_libcpp_lib_dir = ""
51e509ee18Sopenharmony_ci}
52e509ee18Sopenharmony_ci
53e509ee18Sopenharmony_ci# Defines the name the AOSP build gives to the current host CPU
54e509ee18Sopenharmony_ci# architecture, which is different than the names GN uses.
55e509ee18Sopenharmony_ciif (host_cpu == "x64") {
56e509ee18Sopenharmony_ci  aosp_host_arch = "x86_64"
57e509ee18Sopenharmony_ci} else if (host_cpu == "x86") {
58e509ee18Sopenharmony_ci  aosp_host_arch = "x86"
59e509ee18Sopenharmony_ci} else {
60e509ee18Sopenharmony_ci  assert(false, "Need AOSP toolchain support for your build CPU arch.")
61e509ee18Sopenharmony_ci}
62e509ee18Sopenharmony_ci
63e509ee18Sopenharmony_ci# Defines the name the aosp build gives to the current host CPU
64e509ee18Sopenharmony_ci# architecture, which is different than the names GN uses.
65e509ee18Sopenharmony_ciif (host_os == "linux") {
66e509ee18Sopenharmony_ci  aosp_host_os = "linux"
67e509ee18Sopenharmony_ci} else if (host_os == "mac") {
68e509ee18Sopenharmony_ci  aosp_host_os = "darwin"
69e509ee18Sopenharmony_ci} else {
70e509ee18Sopenharmony_ci  assert(false, "Need AOSP toolchain support for your build OS.")
71e509ee18Sopenharmony_ci}
72e509ee18Sopenharmony_ci
73e509ee18Sopenharmony_ci# Directories and files
74e509ee18Sopenharmony_ciarm64_aosp_sysroot_subdir =
75e509ee18Sopenharmony_ci    "platforms/android-${aosp64_ndk_api_level}/arch-arm64"
76e509ee18Sopenharmony_ci
77e509ee18Sopenharmony_ci# # Toolchain root directory for each build. The actual binaries are inside
78e509ee18Sopenharmony_ci# # a "bin" directory inside of these.
79e509ee18Sopenharmony_ci_aosp_toolchain_version = "4.9"
80e509ee18Sopenharmony_ci_aosp_toolchain_detailed_version = "4.9.x"
81e509ee18Sopenharmony_ciarm64_aosp_toolchain_root = "$aosp_ndk_root/toolchains/aarch64-linux-android-${_aosp_toolchain_version}/prebuilt/${aosp_host_os}-${aosp_host_arch}"
82e509ee18Sopenharmony_ci
83e509ee18Sopenharmony_ci# Location of libgcc. This is only needed for the current GN toolchain, so we
84e509ee18Sopenharmony_ci# only need to define the current one, rather than one for every platform
85e509ee18Sopenharmony_ci# like the toolchain roots.
86e509ee18Sopenharmony_ciif (current_cpu == "arm64") {
87e509ee18Sopenharmony_ci  aosp_prebuilt_arch = "android-arm64"
88e509ee18Sopenharmony_ci  _binary_prefix = "aarch64-linux-android"
89e509ee18Sopenharmony_ci  aosp_toolchain_root = "$arm64_aosp_toolchain_root"
90e509ee18Sopenharmony_ci  aosp_libgcc_file = "$aosp_toolchain_root/lib/gcc/aarch64-linux-android/${_aosp_toolchain_detailed_version}/libgcc.a"
91e509ee18Sopenharmony_ci  aosp_log_file = "$aosp_ndk_root/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/30/liblog.so"
92e509ee18Sopenharmony_ci}
93e509ee18Sopenharmony_ci
94e509ee18Sopenharmony_ciaosp_libcpp_root = "$aosp_ndk_root/sources/cxx-stl/llvm-libc++"
95e509ee18Sopenharmony_ciif (aosp_libcpp_lib_dir == "") {
96e509ee18Sopenharmony_ci  aosp_libcpp_lib_dir = "${aosp_libcpp_root}/libs/${aosp_app_abi}"
97e509ee18Sopenharmony_ci}
98