OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/clang/clang.gni") | 5 import("//build/config/clang/clang.gni") |
6 import("//build/config/sysroot.gni") # Imports android/config.gni. | 6 import("//build/config/sysroot.gni") # Imports android/config.gni. |
7 import("//build/toolchain/gcc_toolchain.gni") | 7 import("//build/toolchain/gcc_toolchain.gni") |
8 | 8 |
9 # The Android GCC toolchains share most of the same parameters, so we have this | 9 # The Android GCC toolchains share most of the same parameters, so we have this |
10 # wrapper around gcc_toolchain to avoid duplication of logic. | 10 # wrapper around gcc_toolchain to avoid duplication of logic. |
11 # | 11 # |
12 # Parameters: | 12 # Parameters: |
13 # - toolchain_cpu | |
14 # Same as gcc_toolchain. | |
15 # - toolchain_root | 13 # - toolchain_root |
16 # Path to cpu-specific toolchain within the ndk. | 14 # Path to cpu-specific toolchain within the ndk. |
17 # - sysroot | 15 # - sysroot |
18 # Sysroot for this architecture. | 16 # Sysroot for this architecture. |
19 # - lib_dir | 17 # - lib_dir |
20 # Subdirectory inside of sysroot where libs go. | 18 # Subdirectory inside of sysroot where libs go. |
21 # - binary_prefix | 19 # - binary_prefix |
22 # Prefix of compiler executables. | 20 # Prefix of compiler executables. |
23 template("android_gcc_toolchain") { | 21 template("android_gcc_toolchain") { |
24 gcc_toolchain(target_name) { | 22 gcc_toolchain(target_name) { |
25 is_clang = invoker.is_clang | 23 assert(defined(invoker.toolchain_args), |
26 toolchain_cpu = invoker.toolchain_cpu | 24 "toolchain_args must be defined for android_gcc_toolchain()") |
27 toolchain_os = "android" | 25 toolchain_args = invoker.toolchain_args |
| 26 toolchain_args.current_os = "android" |
28 | 27 |
29 # Make our manually injected libs relative to the build dir. | 28 # Make our manually injected libs relative to the build dir. |
30 _ndk_lib = | 29 _ndk_lib = |
31 rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir) | 30 rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir) |
32 | 31 |
33 libs_section_prefix = "$_ndk_lib/crtbegin_dynamic.o" | 32 libs_section_prefix = "$_ndk_lib/crtbegin_dynamic.o" |
34 libs_section_postfix = "$_ndk_lib/crtend_android.o" | 33 libs_section_postfix = "$_ndk_lib/crtend_android.o" |
35 | 34 |
36 solink_libs_section_prefix = "$_ndk_lib/crtbegin_so.o" | 35 solink_libs_section_prefix = "$_ndk_lib/crtbegin_so.o" |
37 solink_libs_section_postfix = "$_ndk_lib/crtend_so.o" | 36 solink_libs_section_postfix = "$_ndk_lib/crtend_so.o" |
38 | 37 |
39 _android_tool_prefix = | 38 _android_tool_prefix = |
40 "${invoker.toolchain_root}/bin/${invoker.binary_prefix}-" | 39 "${invoker.toolchain_root}/bin/${invoker.binary_prefix}-" |
41 | 40 |
42 # The tools should be run relative to the build dir. | 41 # The tools should be run relative to the build dir. |
43 _tool_prefix = rebase_path("$_android_tool_prefix", root_build_dir) | 42 _tool_prefix = rebase_path("$_android_tool_prefix", root_build_dir) |
44 | 43 |
45 if (is_clang) { | 44 # Use the clang specified by the toolchain if there is one. Otherwise fall |
| 45 # back to the global flag. |
| 46 if (defined(toolchain_args.is_clang)) { |
| 47 toolchain_uses_clang = toolchain_args.is_clang |
| 48 } else { |
| 49 toolchain_uses_clang = is_clang |
| 50 } |
| 51 |
| 52 if (toolchain_uses_clang) { |
46 _prefix = rebase_path("$clang_base_path/bin", root_build_dir) | 53 _prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
47 cc = "$_prefix/clang" | 54 cc = "$_prefix/clang" |
48 cxx = "$_prefix/clang++" | 55 cxx = "$_prefix/clang++" |
49 } else { | 56 } else { |
50 cc = "${_tool_prefix}gcc" | 57 cc = "${_tool_prefix}gcc" |
51 cxx = "${_tool_prefix}g++" | 58 cxx = "${_tool_prefix}g++" |
52 } | 59 } |
53 ar = _tool_prefix + "ar" | 60 ar = _tool_prefix + "ar" |
54 ld = cxx | 61 ld = cxx |
55 readelf = _tool_prefix + "readelf" | 62 readelf = _tool_prefix + "readelf" |
56 nm = _tool_prefix + "nm" | 63 nm = _tool_prefix + "nm" |
57 strip = "${_tool_prefix}strip" | 64 strip = "${_tool_prefix}strip" |
58 | 65 |
59 # Don't use .cr.so for loadable_modules since they are always loaded via | 66 # Don't use .cr.so for loadable_modules since they are always loaded via |
60 # absolute path. | 67 # absolute path. |
61 loadable_module_extension = ".so" | 68 loadable_module_extension = ".so" |
62 } | 69 } |
63 } | 70 } |
64 | 71 |
65 template("android_gcc_toolchains_helper") { | 72 template("android_gcc_toolchains_helper") { |
66 android_gcc_toolchain(target_name) { | 73 android_gcc_toolchain(target_name) { |
67 forward_variables_from(invoker, "*") | 74 forward_variables_from(invoker, "*") |
| 75 toolchain_args.is_clang = false |
68 } | 76 } |
69 | 77 |
70 android_gcc_toolchain("clang_$target_name") { | 78 android_gcc_toolchain("clang_$target_name") { |
71 forward_variables_from(invoker, "*") | 79 forward_variables_from(invoker, "*") |
72 is_clang = true | 80 toolchain_args.is_clang = true |
73 } | 81 } |
74 } | 82 } |
75 | 83 |
76 android_gcc_toolchains_helper("x86") { | 84 android_gcc_toolchains_helper("x86") { |
77 toolchain_cpu = "x86" | |
78 toolchain_root = x86_android_toolchain_root | 85 toolchain_root = x86_android_toolchain_root |
79 sysroot = "$android_ndk_root/$x86_android_sysroot_subdir" | 86 sysroot = "$android_ndk_root/$x86_android_sysroot_subdir" |
80 lib_dir = "usr/lib" | 87 lib_dir = "usr/lib" |
81 binary_prefix = "i686-linux-android" | 88 binary_prefix = "i686-linux-android" |
| 89 toolchain_args = { |
| 90 current_cpu = "x86" |
| 91 } |
82 } | 92 } |
83 | 93 |
84 android_gcc_toolchains_helper("arm") { | 94 android_gcc_toolchains_helper("arm") { |
85 toolchain_cpu = "arm" | |
86 toolchain_root = arm_android_toolchain_root | 95 toolchain_root = arm_android_toolchain_root |
87 sysroot = "$android_ndk_root/$arm_android_sysroot_subdir" | 96 sysroot = "$android_ndk_root/$arm_android_sysroot_subdir" |
88 lib_dir = "usr/lib" | 97 lib_dir = "usr/lib" |
89 binary_prefix = "arm-linux-androideabi" | 98 binary_prefix = "arm-linux-androideabi" |
| 99 toolchain_args = { |
| 100 current_cpu = "arm" |
| 101 } |
90 } | 102 } |
91 | 103 |
92 android_gcc_toolchains_helper("mipsel") { | 104 android_gcc_toolchains_helper("mipsel") { |
93 toolchain_cpu = "mipsel" | |
94 toolchain_root = mips_android_toolchain_root | 105 toolchain_root = mips_android_toolchain_root |
95 sysroot = "$android_ndk_root/$mips_android_sysroot_subdir" | 106 sysroot = "$android_ndk_root/$mips_android_sysroot_subdir" |
96 lib_dir = "usr/lib" | 107 lib_dir = "usr/lib" |
97 binary_prefix = "mipsel-linux-android" | 108 binary_prefix = "mipsel-linux-android" |
| 109 toolchain_args = { |
| 110 current_cpu = "mipsel" |
| 111 } |
98 } | 112 } |
99 | 113 |
100 android_gcc_toolchains_helper("x64") { | 114 android_gcc_toolchains_helper("x64") { |
101 toolchain_cpu = "x64" | |
102 toolchain_root = x86_64_android_toolchain_root | 115 toolchain_root = x86_64_android_toolchain_root |
103 sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir" | 116 sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir" |
104 lib_dir = "usr/lib64" | 117 lib_dir = "usr/lib64" |
105 binary_prefix = "x86_64-linux-android" | 118 binary_prefix = "x86_64-linux-android" |
| 119 toolchain_args = { |
| 120 current_cpu = "x64" |
| 121 } |
106 } | 122 } |
107 | 123 |
108 android_gcc_toolchains_helper("arm64") { | 124 android_gcc_toolchains_helper("arm64") { |
109 toolchain_cpu = "arm64" | |
110 toolchain_root = arm64_android_toolchain_root | 125 toolchain_root = arm64_android_toolchain_root |
111 sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir" | 126 sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir" |
112 lib_dir = "usr/lib" | 127 lib_dir = "usr/lib" |
113 binary_prefix = "aarch64-linux-android" | 128 binary_prefix = "aarch64-linux-android" |
| 129 toolchain_args = { |
| 130 current_cpu = "arm64" |
| 131 } |
114 } | 132 } |
115 | 133 |
116 android_gcc_toolchains_helper("mips64el") { | 134 android_gcc_toolchains_helper("mips64el") { |
117 toolchain_cpu = "mips64el" | |
118 toolchain_root = mips64_android_toolchain_root | 135 toolchain_root = mips64_android_toolchain_root |
119 sysroot = "$android_ndk_root/$mips64_android_sysroot_subdir" | 136 sysroot = "$android_ndk_root/$mips64_android_sysroot_subdir" |
120 lib_dir = "usr/lib64" | 137 lib_dir = "usr/lib64" |
121 binary_prefix = "mips64el-linux-android" | 138 binary_prefix = "mips64el-linux-android" |
| 139 toolchain_args = { |
| 140 current_cpu = "mips64el" |
| 141 } |
122 } | 142 } |
OLD | NEW |