1# Copyright 2014 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.
4
5import("//build/config/arm.gni")
6import("//build/config/android/config.gni")
7import("//third_party/libvpx/libvpx_srcs.gni")
8import("//third_party/yasm/yasm_assemble.gni")
9
10if (is_posix && !is_mac) {
11  os_category = "linux"
12} else {
13  os_category = os
14}
15
16# Sets the architecture name for building libvpx.
17if (cpu_arch == "x86") {
18  cpu_arch_full = "ia32"
19} else if (cpu_arch == "x64") {
20  if (is_msan) {
21    cpu_arch_full = "generic"
22  } else {
23    cpu_arch_full = "x64"
24  }
25} else if (cpu_arch == "arm") {
26  if (arm_use_neon) {
27    cpu_arch_full = "arm-neon"
28  } else if (is_android) {
29    cpu_arch_full = "arm-neon-cpu-detect"
30  } else {
31    cpu_arch_full = "arm"
32  }
33} else {
34  cpu_arch_full = cpu_arch
35}
36
37config("libvpx_config") {
38  include_dirs = [
39    "//third_party/libvpx/source/config",
40    "//third_party/libvpx/source/config/$os_category/$cpu_arch_full",
41    "//third_party/libvpx/source/libvpx",
42    "$root_gen_dir/third_party/libvpx", # Provides vpx_rtcd.h.
43  ]
44  cflags = [ "-Wno-unused-function", "-Wno-sign-compare" ]
45}
46
47# This config is applied to targets that depend on libvpx.
48config("libvpx_external_config") {
49  include_dirs = [
50    "//third_party/libvpx/source/libvpx",
51  ]
52}
53
54executable("libvpx_obj_int_extract") {
55  sources = [
56    "//third_party/libvpx/source/libvpx/build/make/obj_int_extract.c"
57  ]
58  configs += [ ":libvpx_config" ]
59  if (is_android_webview_build) {
60    defines += [ "FORCE_PARSE_ELF" ]
61    include_dirs += [ "//third_party/libvpx/include" ]
62  }
63}
64
65# A library whose object files contain integers to be extracted.
66static_library("libvpx_asm_offsets") {
67  sources = [
68    "//third_party/libvpx/source/libvpx/vp8/encoder/vp8_asm_enc_offsets.c",
69    "//third_party/libvpx/source/libvpx/vpx_scale/vpx_scale_asm_offsets.c"
70  ]
71  configs += [ ":libvpx_config" ]
72  if (is_clang) {
73    cflags = [ "-Wno-unused-function" ]
74  }
75}
76
77# This works only on POSIX to extract integer values from an object file.
78template("obj_int_extract") {
79  action(target_name) {
80    script = "//third_party/libvpx/obj_int_extract.py"
81    bin_label = "//third_party/libvpx($host_toolchain)"
82
83    args = [
84      "-e",
85      "./" + rebase_path(get_label_info(bin_label, "root_out_dir") +
86                         "/libvpx_obj_int_extract",
87                         root_build_dir)
88    ]
89
90    if (cpu_arch == "arm") {
91      args += [ "-f", "gas" ]
92    } else {
93      args += [ "-f", "rvds" ]
94    }
95
96    args += [
97      "-b",
98      rebase_path(get_label_info(":libvpx_asm_offsets", "target_out_dir")) +
99          "/" + invoker.src_dir + "/libvpx_asm_offsets." +
100          invoker.obj_file_root + ".o"
101    ]
102    out_file = "$target_gen_dir/" + invoker.obj_file_root + ".asm"
103    args += [ "-o", rebase_path(out_file) ]
104    outputs = [ out_file ]
105    deps = [
106      ":libvpx_asm_offsets",
107      ":libvpx_obj_int_extract($host_toolchain)"
108    ]
109  }
110}
111
112obj_int_extract("gen_asm_offsets_vp8") {
113  src_dir = "source/libvpx/vp8/encoder"
114  obj_file_root = "vp8_asm_enc_offsets"
115}
116
117obj_int_extract("gen_asm_offsets_scale") {
118  src_dir = "source/libvpx/vpx_scale"
119  obj_file_root = "vpx_scale_asm_offsets"
120}
121
122if (cpu_arch == "x86" || cpu_arch == "x64") {
123  yasm_assemble("libvpx_yasm") {
124    if (cpu_arch == "x86") {
125      sources = libvpx_srcs_x86_assembly
126    } else if (cpu_arch == "x64") {
127      sources = libvpx_srcs_x86_64_assembly
128    }
129
130    defines = [ "CHROMIUM" ]
131    include_dirs = [
132      "//third_party/libvpx/source/config/$os_category/$cpu_arch_full",
133      "//third_party/libvpx/source/config",
134     "//third_party/libvpx/source/libvpx",
135      target_gen_dir
136    ]
137    deps = [
138      ":gen_asm_offsets_vp8",
139      ":gen_asm_offsets_scale",
140    ]
141  }
142}
143
144static_library("libvpx_intrinsics_mmx") {
145  configs += [ ":libvpx_config" ]
146  cflags = [ "-mmmx" ]
147  if (cpu_arch == "x86") {
148    sources = libvpx_srcs_x86_mmx
149  } else if (cpu_arch == "x64") {
150    sources = libvpx_srcs_x86_64_mmx
151  }
152}
153
154static_library("libvpx_intrinsics_sse2") {
155  configs += [ ":libvpx_config" ]
156  cflags = [ "-msse2" ]
157  if (cpu_arch == "x86") {
158    sources = libvpx_srcs_x86_sse2
159  } else if (cpu_arch == "x64") {
160    sources = libvpx_srcs_x86_64_sse2
161  }
162}
163
164static_library("libvpx_intrinsics_ssse3") {
165  configs += [ ":libvpx_config" ]
166  cflags = [ "-mssse3" ]
167  if (cpu_arch == "x86") {
168    sources = libvpx_srcs_x86_ssse3
169  } else if (cpu_arch == "x64") {
170    sources = libvpx_srcs_x86_64_ssse3
171  }
172}
173
174static_library("libvpx_intrinsics_sse4_1") {
175  configs += [ ":libvpx_config" ]
176  cflags = [ "-msse4.1" ]
177  if (cpu_arch == "x86") {
178    sources = libvpx_srcs_x86_sse4_1
179  } else if (cpu_arch == "x64") {
180    sources = libvpx_srcs_x86_64_sse4_1
181  }
182}
183
184if (cpu_arch_full == "arm-neon-cpu-detect") {
185  static_library("libvpx_intrinsics_neon") {
186    configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
187    configs += [ ":libvpx_config" ]
188    cflags = [ "-mfpu=neon" ]
189    sources = libvpx_srcs_arm_neon_cpu_detect_neon
190  }
191}
192
193# Converts ARM assembly files to GAS style.
194if (cpu_arch == "arm") {
195  action_foreach("convert_arm_assembly") {
196    script = "//third_party/libvpx/run_perl.py"
197    if (cpu_arch_full == "arm-neon") {
198      sources = libvpx_srcs_arm_neon_assembly
199    } else if (cpu_arch_full == "arm-neon-cpu-detect") {
200      sources = libvpx_srcs_arm_neon_cpu_detect_assembly
201    } else {
202      sources = libvpx_srcs_arm_assembly
203    }
204    outputs = [ "$target_gen_dir/{{source_name_part}}.S" ]
205    args = [
206      "-s",
207      rebase_path("//third_party/libvpx/source/libvpx/build/make/ads2gas.pl",
208                  root_build_dir),
209      "-i", "{{source}}",
210      "-o", rebase_path("$target_gen_dir/{{source_name_part}}.S")
211    ]
212  }
213
214  static_library("libvpx_assembly_arm") {
215    sources = get_target_outputs(":convert_arm_assembly")
216    configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
217    configs += [ ":libvpx_config" ]
218    if (cpu_arch_full == "arm-neon" ||
219        cpu_arch_full == "arm-neon-cpu-detect") {
220      cflags = [ "-mfpu=neon" ]
221    }
222    deps = [
223      ":convert_arm_assembly",
224      ":gen_asm_offsets_vp8",
225      ":gen_asm_offsets_scale",
226    ]
227  }
228}
229
230static_library("libvpx") {
231  if (!is_debug && is_win && is_official_build) {
232    configs -= [ "//build/config/compiler:optimize" ]
233    configs += [ "//build/config/compiler:optimize_max" ]
234  }
235
236  if (cpu_arch == "x86") {
237    sources = libvpx_srcs_x86
238  } else if (cpu_arch == "x64") {
239    if (is_msan) {
240      sources = libvpx_srcs_generic
241    } else {
242      sources = libvpx_srcs_x86_64
243    }
244  } else if (cpu_arch == "mipsel") {
245    sources = libvpx_srcs_generic
246  } else if (cpu_arch == "arm") {
247    if (arm_use_neon) {
248      sources = libvpx_srcs_arm_neon
249    } else if (is_android) {
250      sources = libvpx_srcs_arm_neon_cpu_detect
251    } else {
252      sources = libvpx_srcs_arm
253    }
254  } else if (cpu_arch == "arm64") {
255    sources = libvpx_srcs_arm64
256  }
257  configs += [ ":libvpx_config" ]
258  deps = []
259  if (cpu_arch == "x86" || (cpu_arch == "x64" && !is_msan)) {
260    deps += [
261      ":libvpx_yasm",
262      ":libvpx_intrinsics_mmx",
263      ":libvpx_intrinsics_sse2",
264      ":libvpx_intrinsics_ssse3",
265      ":libvpx_intrinsics_sse4_1",
266    ]
267  }
268  if (cpu_arch_full == "arm-neon-cpu-detect") {
269    deps += [ ":libvpx_intrinsics_neon" ]
270  }
271  if (is_android) {
272    deps += [ "//third_party/android_tools:cpu_features" ]
273  }
274  if (cpu_arch == "arm") {
275    deps += [ ":libvpx_assembly_arm" ]
276  }
277
278  public_configs = [ ":libvpx_external_config" ]
279}
280