1# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6is_skia_standalone = true
7
8# It's best to keep the names and defaults of is_foo flags consistent with Chrome.
9
10declare_args() {
11  is_official_build = false
12  is_component_build = false
13  ndk = ""
14  if (target_cpu == "x86" || target_cpu == "mipsel" || target_cpu == "arm") {
15    ndk_api = 18
16  } else {
17    ndk_api = 21
18  }
19  sanitize = ""
20}
21declare_args() {
22  is_debug = !is_official_build
23}
24
25assert(!(is_debug && is_official_build))
26
27# Platform detection
28if (target_os == "") {
29  target_os = host_os
30  if (ndk != "") {
31    target_os = "android"
32  }
33}
34if (current_os == "") {
35  current_os = target_os
36}
37
38is_android = current_os == "android"
39is_fuchsia = current_os == "fuchsia"
40is_ios = current_os == "ios" || current_os == "tvos"
41is_tvos = current_os == "tvos"
42is_linux = current_os == "linux"
43is_mac = current_os == "mac"
44is_win = current_os == "win"
45
46if (target_cpu == "") {
47  target_cpu = host_cpu
48  if (is_android || is_ios) {
49    target_cpu = "arm64"
50  }
51}
52if (target_cpu == "x86_64") {
53  target_cpu = "x64"
54}
55if (current_cpu == "") {
56  current_cpu = target_cpu
57}
58
59if (is_android) {
60  ndk_host = ""
61  ndk_target = ""
62  ndk_platform = ""
63  ndk_stdlib = ""
64  ndk_gccdir = ""
65  ndk_gdbserver = ""
66
67  if (host_os == "linux") {
68    ndk_host = "linux-x86_64"
69  } else if (host_os == "mac") {
70    ndk_host = "darwin-x86_64"
71  } else if (host_os == "win") {
72    ndk_host = "windows-x86_64"
73  }
74
75  if (target_cpu == "arm64") {
76    ndk_target = "aarch64-linux-android"
77    ndk_platform = "android-${ndk_api}/arch-arm64"
78    ndk_stdlib = "arm64-v8a"
79    ndk_gccdir = ndk_target
80    ndk_gdbserver = "prebuilt/android-arm64/gdbserver/gdbserver"
81  } else if (target_cpu == "arm") {
82    ndk_target = "arm-linux-androideabi"
83    ndk_platform = "android-${ndk_api}/arch-arm"
84    ndk_stdlib = "armeabi-v7a"
85    ndk_gccdir = ndk_target
86    ndk_gdbserver = "prebuilt/android-arm/gdbserver/gdbserver"
87  } else if (target_cpu == "mips64el") {
88    ndk_target = "mips64el-linux-android"
89    ndk_platform = "android-${ndk_api}/arch-mips64"
90    ndk_stdlib = "mips64"
91    ndk_gccdir = ndk_target
92    ndk_gdbserver = "prebuilt/android-mips64/gdbserver/gdbserver"
93  } else if (target_cpu == "mipsel") {
94    ndk_target = "mipsel-linux-android"
95    ndk_platform = "android-${ndk_api}/arch-mips"
96    ndk_stdlib = "mips"
97    ndk_gccdir = ndk_target
98    ndk_gdbserver = "prebuilt/android-mips/gdbserver/gdbserver"
99  } else if (target_cpu == "x64") {
100    ndk_target = "x86_64-linux-android"
101    ndk_platform = "android-${ndk_api}/arch-x86_64"
102    ndk_stdlib = "x86_64"
103    ndk_gccdir = ndk_stdlib
104    ndk_gdbserver = "prebuilt/android-x86_64/gdbserver/gdbserver"
105  } else if (target_cpu == "x86") {
106    ndk_target = "i686-linux-android"
107    ndk_platform = "android-${ndk_api}/arch-x86"
108    ndk_stdlib = "x86"
109    ndk_gccdir = ndk_stdlib
110    ndk_gdbserver = "prebuilt/android-x86/gdbserver/gdbserver"
111  }
112}
113
114# A component is either a static or a shared library.
115template("component") {
116  _component_mode = "static_library"
117  if (is_component_build) {
118    _component_mode = "shared_library"
119  }
120
121  target(_component_mode, target_name) {
122    forward_variables_from(invoker, "*")
123  }
124}
125
126# Default configs
127default_configs = [
128  "//gn:default",
129  "//gn:no_exceptions",
130  "//gn:no_rtti",
131  "//gn:warnings",
132  "//gn:warnings_except_public_headers",
133]
134if (!is_debug) {
135  default_configs += [ "//gn:release" ]
136}
137if (!is_official_build) {
138  default_configs += [ "//gn:debug_symbols" ]
139}
140default_configs += [ "//gn:extra_flags" ]
141
142set_defaults("executable") {
143  configs = [ "//gn:executable" ] + default_configs
144}
145
146set_defaults("source_set") {
147  configs = default_configs
148}
149
150set_defaults("static_library") {
151  configs = default_configs
152}
153
154set_defaults("shared_library") {
155  configs = default_configs
156}
157
158set_defaults("component") {
159  configs = default_configs
160  if (!is_component_build) {
161    complete_static_lib = true
162  }
163}
164
165if (is_win) {
166  # Windows tool chain
167  set_default_toolchain("//gn:msvc")
168} else {
169  # GCC-like toolchains, including Clang.
170  set_default_toolchain("//gn:gcc_like")
171}
172