1 # Copyright (c) 2020 Project CHIP Authors
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 import("//build_overrides/build.gni")
17 import("${build_root}/config/android/config.gni")
18 import("${build_root}/toolchain/gcc_toolchain.gni")
20 template("android_clang_toolchain") {
21 _invoker_toolchain_args = invoker.toolchain_args
23 if (_invoker_toolchain_args.current_cpu == "arm") {
24 _tool_name_root = "armv7a-linux-androideabi${invoker.api_level}-"
25 } else if (_invoker_toolchain_args.current_cpu == "arm64") {
26 _tool_name_root = "aarch64-linux-android${invoker.api_level}-"
27 } else if (_invoker_toolchain_args.current_cpu == "x64") {
28 _tool_name_root = "x86_64-linux-android${invoker.api_level}-"
29 } else if (_invoker_toolchain_args.current_cpu == "x86") {
30 _tool_name_root = "i686-linux-android${invoker.api_level}-"
34 "Unknown/invalid current_cpu value in toolchain_args::current_cpu for android_clang_toolchain")
37 _android_toolchain_args = {
38 current_os = "android"
41 forward_variables_from(_invoker_toolchain_args, "*")
45 if (android_ndk_root != "") {
47 if (host_os == "linux") {
48 _ndk_host_os = "linux"
49 } else if (host_os == "mac") {
50 _ndk_host_os = "darwin"
51 } else if (host_os == "win") {
52 _ndk_host_os = "windows"
56 if (host_cpu == "x64") {
57 _ndk_host_cpu = "-x86_64"
60 _ndk_host = _ndk_host_os + _ndk_host_cpu
62 "${android_ndk_root}/toolchains/llvm/prebuilt/${_ndk_host}/bin/"
65 gcc_toolchain(target_name) {
66 toolchain_args = _android_toolchain_args
67 ar = _ndk_prefix + "llvm-ar"
68 cc = _ndk_prefix + _tool_name_root + "clang"
69 cxx = _ndk_prefix + _tool_name_root + "clang++"