blob: d137ad8541170eb96ea3d764b028ff294a8b459a [file] [log] [blame]
Primiano Tucciae2879e2017-09-27 11:02:09 +09001# Copyright (C) 2017 The Android Open Source Project
2#
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
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14
Primiano Tucci7a40e4d2017-12-06 09:51:09 +000015import("//gn/standalone/android.gni")
Primiano Tucci7278dea2017-10-31 11:50:32 +000016import("llvm.gni")
17
18declare_args() {
19 if (is_clang) {
20 if (is_linux) {
21 cc = linux_clang_bin
22 cxx = linux_clangxx_bin
23 } else {
24 cc = "clang"
25 cxx = "clang++"
26 }
27 } else {
28 cc = "gcc"
29 cxx = "g++"
30 }
31}
Primiano Tucciae2879e2017-09-27 11:02:09 +090032
33declare_args() {
34 host_ar = ar
Primiano Tuccifffb1242017-11-27 09:41:36 +000035 if (is_linux_host && is_clang) {
Primiano Tucci7278dea2017-10-31 11:50:32 +000036 host_cc = linux_clang_bin
37 host_cxx = linux_clangxx_bin
38 } else {
39 host_cc = cc
40 host_cxx = cxx
41 }
Primiano Tucciae2879e2017-09-27 11:02:09 +090042
43 if (is_android) {
Sami Kyostilaebba0fe2017-12-19 14:01:52 +000044 target_ar = "$android_toolchain_root/bin/$android_abi_target-ar"
Primiano Tucci0825bc82017-09-28 18:50:23 +010045 target_cc = "$android_llvm_dir/bin/clang"
46 target_cxx = "$android_llvm_dir/bin/clang++"
Primiano Tucciae2879e2017-09-27 11:02:09 +090047 } else {
48 target_ar = ar
49 target_cc = cc
50 target_cxx = cxx
51 }
52 cc_wrapper = ""
53}
54
55python = "python"
56stamp = "touch"
57
58template("gcc_like_toolchain") {
59 toolchain(target_name) {
60 ar = invoker.ar
61 cc = invoker.cc
62 cxx = invoker.cxx
63 lib_switch = "-l"
64 lib_dir_switch = "-L"
65
66 tool("cc") {
67 depfile = "{{output}}.d"
68 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
69 depsformat = "gcc"
70 outputs = [
71 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
72 ]
73 description = "compile {{source}}"
74 }
75
76 tool("cxx") {
77 depfile = "{{output}}.d"
78 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
79 depsformat = "gcc"
80 outputs = [
81 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
82 ]
83 description = "compile {{source}}"
84 }
85
86 tool("asm") {
87 depfile = "{{output}}.d"
88 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
89 depsformat = "gcc"
90 outputs = [
91 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
92 ]
93 description = "assemble {{source}}"
94 }
95
96 tool("alink") {
Primiano Tuccia5ff2a82017-12-20 11:37:00 +010097 if (is_mac && ar != "suppress_unused_ar_variable_warning") {
98 command = "rm -f {{output}} && libtool -static {{arflags}} -o {{output}} {{inputs}}"
99 } else {
100 rspfile = "{{output}}.rsp"
101 rspfile_content = "{{inputs}}"
102 command = "$ar rcsD {{output}} @$rspfile"
103 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900104 outputs = [
105 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
106 ]
107 default_output_extension = ".a"
108 output_prefix = "lib"
109 description = "link {{output}}"
110 }
111
112 tool("solink") {
113 soname = "{{target_output_name}}{{output_extension}}"
114
115 rpath = "-Wl,-soname,$soname"
116 if (is_mac) {
117 rpath = "-Wl,-install_name,@rpath/$soname"
118 }
119
120 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
121 outputs = [
122 "{{root_out_dir}}/$soname",
123 ]
124 output_prefix = "lib"
125 default_output_extension = ".so"
126 description = "link {{output}}"
127 }
128
129 tool("link") {
130 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
131 outputs = [
132 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
133 ]
134 description = "link {{output}}"
135 }
136
137 tool("stamp") {
Primiano Tucciac3fd3e2017-09-29 14:29:15 +0100138 command = "touch {{output}}"
Primiano Tucciae2879e2017-09-27 11:02:09 +0900139 description = "stamp {{output}}"
140 }
141
Primiano Tucciac3fd3e2017-09-29 14:29:15 +0100142 tool("copy") {
143 command = "cp -af {{source}} {{output}}"
144 description = "COPY {{source}} {{output}}"
145 }
146
Primiano Tucciae2879e2017-09-27 11:02:09 +0900147 toolchain_args = {
148 current_cpu = invoker.cpu
149 current_os = invoker.os
150 }
151 }
152}
153
154gcc_like_toolchain("gcc_like") {
155 cpu = current_cpu
156 os = current_os
157 ar = target_ar
158 cc = target_cc
159 cxx = target_cxx
160}
161
162gcc_like_toolchain("gcc_like_host") {
163 cpu = host_cpu
164 os = host_os
165 ar = host_ar
166 cc = host_cc
167 cxx = host_cxx
168}