1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/sysroot.gni") # Imports android/config.gni.
6 import("//build/toolchain/ccache.gni")
7 import("//build/toolchain/clang.gni")
8 import("//build/toolchain/goma.gni")
9 import("//build/toolchain/gcc_toolchain.gni")
11 # The Android GCC toolchains share most of the same parameters, so we have this
12 # wrapper around gcc_toolchain to avoid duplication of logic.
15 # - android_ndk_sysroot
16 # Sysroot for this architecture.
17 # - android_ndk_lib_dir
18 # Subdirectory inside of android_ndk_sysroot where libs go.
20 # Prefix to be added to the tool names.
22 # Same as gcc_toolchain
23 template("android_gcc_toolchain") {
24 gcc_toolchain(target_name) {
25 # Make our manually injected libs relative to the build dir.
26 android_ndk_lib = rebase_path(
27 invoker.android_ndk_sysroot + "/" + invoker.android_ndk_lib_dir,
30 libs_section_prefix = "$android_ndk_lib/crtbegin_dynamic.o"
31 libs_section_postfix = "$android_ndk_lib/crtend_android.o"
33 solink_libs_section_prefix = "$android_ndk_lib/crtbegin_so.o"
34 solink_libs_section_postfix = "$android_ndk_lib/crtend_so.o"
36 # The tools should be run relative to the build dir.
37 tool_prefix = rebase_path(invoker.tool_prefix, root_build_dir)
40 assert(!use_ccache, "Goma and ccache can't be used together.")
41 compiler_prefix = "$goma_dir/gomacc "
42 } else if (use_ccache) {
43 compiler_prefix = "ccache "
48 is_clang = invoker.is_clang
50 if (use_clang_type_profiler) {
51 prefix = rebase_path("//third_party/llvm-allocated-type/Linux_x64/bin",
54 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
57 cc = "${compiler_prefix}$prefix/clang"
58 cxx = "${compiler_prefix}$prefix/clang++"
60 cc = "${compiler_prefix}${tool_prefix}gcc"
61 cxx = "${compiler_prefix}${tool_prefix}g++"
63 ar = tool_prefix + "ar"
65 readelf = compiler_prefix + tool_prefix + "readelf"
66 nm = compiler_prefix + tool_prefix + "nm"
68 toolchain_os = "android"
69 toolchain_cpu = invoker.toolchain_cpu
71 # We make the assumption that the gcc_toolchain will produce a soname with
72 # the following definition.
73 soname = "{{target_output_name}}{{output_extension}}"
75 stripped_soname = "lib.stripped/${soname}"
76 temp_stripped_soname = "${stripped_soname}.tmp"
78 android_strip = "${tool_prefix}strip"
81 "$android_strip --strip-unneeded -o $temp_stripped_soname $soname"
82 replace_command = "if ! cmp -s $temp_stripped_soname $stripped_soname; then mv $temp_stripped_soname $stripped_soname; fi"
83 postsolink = "$strip_command && $replace_command"
84 solink_outputs = [ stripped_soname ]
85 default_output_extension = android_product_extension
87 # We make the assumption that the gcc_toolchain will produce an exe with
88 # the following definition.
89 exe = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
90 stripped_exe = "exe.stripped/$exe"
91 postlink = "$android_strip --strip-unneeded -o $stripped_exe $exe"
92 link_outputs = [ stripped_exe ]
96 template("android_gcc_toolchains_helper") {
97 android_gcc_toolchain(target_name) {
98 android_ndk_sysroot = invoker.android_ndk_sysroot
99 android_ndk_lib_dir = invoker.android_ndk_lib_dir
100 tool_prefix = invoker.tool_prefix
101 toolchain_cpu = invoker.toolchain_cpu
104 android_gcc_toolchain("clang_$target_name") {
105 android_ndk_sysroot = invoker.android_ndk_sysroot
106 android_ndk_lib_dir = invoker.android_ndk_lib_dir
107 tool_prefix = invoker.tool_prefix
108 toolchain_cpu = invoker.toolchain_cpu
113 android_gcc_toolchains_helper("x86") {
114 android_ndk_sysroot = "$android_ndk_root/$x86_android_sysroot_subdir"
115 android_ndk_lib_dir = "usr/lib"
117 tool_prefix = "$x86_android_toolchain_root/bin/i686-linux-android-"
118 toolchain_cpu = "x86"
121 android_gcc_toolchains_helper("arm") {
122 android_ndk_sysroot = "$android_ndk_root/$arm_android_sysroot_subdir"
123 android_ndk_lib_dir = "usr/lib"
125 tool_prefix = "$arm_android_toolchain_root/bin/arm-linux-androideabi-"
126 toolchain_cpu = "arm"
129 android_gcc_toolchains_helper("mipsel") {
130 android_ndk_sysroot = "$android_ndk_root/$mips_android_sysroot_subdir"
131 android_ndk_lib_dir = "usr/lib"
133 tool_prefix = "$mips_android_toolchain_root/bin/mipsel-linux-android-"
134 toolchain_cpu = "mipsel"
137 android_gcc_toolchains_helper("x64") {
138 android_ndk_sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir"
139 android_ndk_lib_dir = "usr/lib64"
141 tool_prefix = "$x86_64_android_toolchain_root/bin/x86_64-linux-android-"
142 toolchain_cpu = "x86_64"
145 android_gcc_toolchains_helper("arm64") {
146 android_ndk_sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir"
147 android_ndk_lib_dir = "usr/lib"
149 tool_prefix = "$arm64_android_toolchain_root/bin/arm-linux-androideabi-"
150 toolchain_cpu = "aarch64"
153 android_gcc_toolchains_helper("mips64el") {
154 android_ndk_sysroot = "$android_ndk_root/$mips64_android_sysroot_subdir"
155 android_ndk_lib_dir = "usr/lib64"
157 tool_prefix = "$mips64_android_toolchain_root/bin/mipsel-linux-android-"
158 toolchain_cpu = "mipsel64el"