• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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
15import("//gn/standalone/android.gni")
16import("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}
32
33declare_args() {
34  host_ar = ar
35  if (is_linux_host && is_clang) {
36    host_cc = linux_clang_bin
37    host_cxx = linux_clangxx_bin
38  } else {
39    host_cc = cc
40    host_cxx = cxx
41  }
42
43  if (is_android) {
44    target_ar = "$android_toolchain_root/bin/$android_abi_target-ar"
45    target_cc = "$android_llvm_dir/bin/clang"
46    target_cxx = "$android_llvm_dir/bin/clang++"
47  } 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") {
97      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      }
104      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") {
138      command = "touch {{output}}"
139      description = "stamp {{output}}"
140    }
141
142    tool("copy") {
143      command = "cp -af {{source}} {{output}}"
144      description = "COPY {{source}} {{output}}"
145    }
146
147    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}
169