Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / BUILD.gn
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
5 import("ffmpeg_options.gni")
6 import("ffmpeg_generated.gni")
7
8 # Path to platform configuration files.
9 platform_config_root =
10     "chromium/config/$ffmpeg_branding/$os_config/$ffmpeg_arch"
11
12 # Stub generator script and signatures of all functions used by Chrome.
13 generate_stubs_script = "//tools/generate_stubs/generate_stubs.py"
14
15 # Used by ffmpeg_generate_stubs and ffmpeg_generate_def
16 sig_files = [ "chromium/ffmpegsumo.sigs" ]
17
18 # TODO(ajwong): Should be in ffmpeg_generate_stubs if we could grab the
19 # outputs of an action via a function.
20 stubs_filename_root = "ffmpeg_stubs"
21
22 if (cpu_arch != "arm" && os_config != "linux-noasm") {
23   import("//third_party/yasm/yasm_assemble.gni")
24   yasm_assemble("ffmpeg_yasm") {
25     sources = ffmpeg_yasm_sources
26
27     # Ensure the architecture defines go in the command line before the -P
28     # file below, so don't use defines.
29     yasm_flags = []
30     if (cpu_arch == "x86") {
31       yasm_flags += [ "-DARCH_X86_32" ]
32     } else if (cpu_arch == "x64") {
33       yasm_flags += [ "-DARCH_X86_64" ]
34     }
35
36     defines = [ "PIC" ]
37     include_dirs = [
38       platform_config_root,
39       "libavcodec/x86",
40       "libavutil/x86",
41       ".",
42     ]
43
44     # Disable warnings, prevents log spam for things we won't fix.
45     yasm_flags += [
46       "-w",
47       "-P", rebase_path("$platform_config_root/config.asm", root_build_dir),
48     ]
49
50     if (is_mac) {
51       # Necessary to ensure symbols end up with a _ prefix; added by
52       # yasm_compile.gypi for Windows, but not Mac.
53       defines += [ "PREFIX" ]
54     }
55   }
56 }
57
58 # FFMpeg is dynamically loaded on all platforms but our code calls it
59 # as if it were directly linked. To make this work, the build system needs
60 # to generate stubs that indirect into the library calls.
61 #
62 # On Windows, this script calls the windows stub generator. Otherwise, assume
63 # this is a POSIX platform and generate our own wrapper stubs.
64 action("ffmpeg_generate_stubs") {
65   extra_header = "chromium/ffmpeg_stub_headers.fragment"
66
67   script = generate_stubs_script
68   sources = sig_files
69   inputs = [ extra_header ]
70
71   if (is_win) {
72     if (build_cpu_arch == "x64") {
73       outfile_type = "windows_lib_x64"
74     } else {
75       outfile_type = "windows_lib"
76     }
77
78     # TODO(ajwong): these need to be in the ffmpeg build.
79     outputs = [
80       "$target_gen_dir/$stubs_filename_root.lib",
81     ]
82
83     args = [
84       # TODO(ajwong): In gyp, this uses different directories for the
85       # windows build. We should think this through.
86       "-i", rebase_path(target_gen_dir, root_build_dir),
87       "-o", rebase_path(target_gen_dir, root_build_dir),
88       "-t", outfile_type,
89     ]
90   } else {
91     # If it's not windows, clearly it must be posix.
92
93     # TODO(ajwong): these need to be included in the ffmpeg build.
94     outputs = [
95       "$target_gen_dir/$stubs_filename_root.cc",
96       "$target_gen_dir/$stubs_filename_root.h",
97     ]
98     args = [
99       # TODO(ajwong): IN gyp, this used to output the .h file into a shared
100       # directory that other targets could reference. The .cc ends up in a
101       # special generated directory that gyp would guaranteed that no one else
102       # could look at. Now we're dumping both into the generated directory.
103       # Verify what the best + simplest behavior is here and use that.
104       "-i", rebase_path(target_gen_dir, root_build_dir),
105       "-o", rebase_path(target_gen_dir, root_build_dir),
106       "-t", "posix_stubs",
107       "-e", rebase_path(extra_header, root_build_dir),
108       "-s", stubs_filename_root,
109       "-p", "third_party/ffmpeg",
110     ]
111   }
112
113   args += rebase_path(sources, root_build_dir)
114 }
115
116 if (build_ffmpegsumo) {
117   shared_library("ffmpegsumo") {
118     # TODO(gyp): Add version number to dll.
119     sources = ffmpeg_c_sources + ffmpeg_gas_sources + [
120       "$platform_config_root/config.h",
121       "$platform_config_root/libavutil/avconfig.h",
122     ]
123     include_dirs = [
124       platform_config_root,
125       ".",
126     ]
127     defines = [
128       "HAVE_AV_CONFIG_H",
129       "_POSIX_C_SOURCE=200112",
130       "_XOPEN_SOURCE=600",
131       "PIC",
132       # Disable deprecated features which generate spammy warnings.
133       "FF_API_PIX_FMT_DESC=0",
134       "FF_API_OLD_DECODE_AUDIO=0",
135       "FF_API_DESTRUCT_PACKET=0",
136       "FF_API_GET_BUFFER=0",
137     ]
138
139     # So we can append below and assume they're defined.
140     cflags = []
141     ldflags = []
142     libs = []
143     deps = []
144
145     configs -= [ "//build/config/compiler:chromium_code" ]
146     configs += [ "//build/config/compiler:no_chromium_code" ]
147
148     # Since we are not often debugging FFmpeg, and performance is
149     # unacceptable without optimization, freeze the optimizations to -O2.
150     # If someone really wants -O1 , they can change these in their checkout.
151     # If you want -O0, see the Gotchas in README.Chromium for why that
152     # won't work.
153     #
154     # In addition to the above reasons, /Od optimization won't remove symbols
155     # that are under "if (0)" style sections.  Which lead to link time errors
156     # when for example it tries to link an ARM symbol on X86.
157     if (is_debug) {
158       configs -= [ "//build/config/compiler:no_optimize" ]
159     } else {
160       configs -= [ "//build/config/compiler:optimize" ]
161     }
162     if (is_win) {
163       # Setting the optimizations to 'speed' or to 'max' on Windows results in
164       # a lot of unresolved symbols. The only supported mode is 'size' (see
165       # crbug.com/264459).
166       configs += [ "//build/config/compiler:optimize" ]
167     } else {
168       configs += [ "//build/config/compiler:optimize_max" ]
169     }
170
171     if (is_posix) {
172       cflags += [
173         "-fPIC",
174         "-fomit-frame-pointer",
175         # ffmpeg uses its own deprecated functions.
176         "-Wno-deprecated-declarations",
177       ]
178
179       if (is_clang) {
180         cflags += [
181           "-Wno-absolute-value",
182           "-Wno-incompatible-pointer-types",
183           "-Wno-logical-op-parentheses",
184           "-Wno-parentheses",
185           "-Wno-pointer-sign",
186           "-Wno-switch",
187         ]
188       } else {
189         # gcc doesn't have flags for specific warnings, so disable them
190         # all.
191         cflags += [ "-w" ]
192       }
193       if (cpu_arch == "x86") {
194         # Turn off valgrind build option that breaks ffmpeg builds.
195         # TODO(ajwong): The gyp file had special removals for
196         # debug_extra_cflags and release_extra_cflags. Do we care?
197 #cflags -= [ "-fno-omit-frame-pointer" ]
198       } else if (cpu_arch == "arm") {
199         # TODO(ihf): See the long comment in build_ffmpeg.sh
200         # We want to be consistent with CrOS and have configured
201         # ffmpeg for thumb. Protect yourself from -marm.
202         if (is_chromeos) {
203           cflags += [ "-marm" ]
204         }
205         cflags += [
206           "-mthumb",
207           "-march=armv7-a",
208           "-mtune=cortex-a8",
209           "-mfpu=${arm_fpu}"
210         ]
211         if (arm_float_abi == "hard") {
212           cflags += [ "-DHAVE_VFP_ARGS=1" ]
213         } else {
214           cflags += [ "-DHAVE_VFP_ARGS=0" ]
215         }
216       } else if (cpu_arch == "mipsel") {
217         cflags += [
218           "-mips32",
219           "-EL -Wl,-EL",
220         ]
221       }
222     }
223
224     if (is_posix && !is_mac) {
225       defines += [
226         "_ISOC99_SOURCE",
227         "_LARGEFILE_SOURCE",
228         # BUG(ihf): ffmpeg compiles with this define. But according to
229         # ajwong: I wouldn't change _FILE_OFFSET_BITS.  That's a scary change
230         # cause it affects the default length of off_t, and fpos_t,
231         # which can cause strange problems if the loading code doesn't
232         # have it set and you start passing FILE*s or file descriptors
233         # between symbol contexts.
234         # "_FILE_OFFSET_BITS=64",
235       ]
236       cflags += [
237         "-std=c99",
238         "-pthread",
239         "-fno-math-errno",
240         "-fno-signed-zeros",
241         "-fno-tree-vectorize",
242         "-fomit-frame-pointer",
243       ]
244       # Ensure the symbols are exported.
245       #
246       # TODO(ajwong): Manually tag the API that we use to be
247       # exported.
248       configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
249       ldflags = [
250         "-Wl,-Bsymbolic",
251         "-L", rebase_path(target_gen_dir, root_build_dir),
252       ]
253       libs = [ "z" ]
254 # TODO(ajwong): How to handle openbsd? Especially w/o the is_posix?
255 #      if (is_openbsd) {
256 #       # OpenBSD's gcc (4.2.1) does not support this flag
257 #       cflags -= [ "-fno-signed-zeros" ]
258 #      }
259     }
260     if (is_mac) {
261       defines += [ "_DARWIN_C_SOURCE" ]
262
263 # TODO(ajwong): What does this do in mac? There isn't anything in ffmpeg.gyp that
264 # uses mac_real_dsym
265 #                ['mac_breakpad == 1', {
266 #                  'variables': {
267 #                    # A real .dSYM is needed for dump_syms to operate on.
268 #                    'mac_real_dsym': 1,
269 #                  },
270 #              }],
271       if (cpu_arch != "x64") {
272         # This is needed because even though FFmpeg now builds
273         # with -fPIC, it's not quite a complete PIC build, only
274         # partial :( Thus we need to instruct the linker to allow
275         # relocations for read-only segments for this target to be
276         # able to generated the shared library on Mac.
277         #
278 #TODO(ajwong): Check if this can be cpu_arch == "x86"
279         # Note -read_only_relocs cannot be used in x86_64
280         #
281         # This makes Mark sad, but he's okay with it since it is
282         # isolated to this module. When Mark finds this in the
283         # future, and has forgotten this conversation, this
284         # comment should remind him that the world is still nice
285         # and butterflies still exist...as do rainbows, sunshine,
286         # tulips, etc., etc...but not kittens. Those went away
287         # with this flag.
288         ldflags = [
289           "-Wl,-read_only_relocs,suppress",
290         ]
291       }
292 # TODO(ajwong): How to handle SDKROOT?
293 #                'libraries': [
294 #                  '$(SDKROOT)/usr/lib/libz.dylib',
295 #                ],
296       # Ensure the symbols are exported.
297       #
298       # TODO(ajwong): Manually tag the API that we use to be exported.
299       if (!is_win) {
300         configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
301       }
302 # TODO(ajwong): How to handle @loader_path?
303 #              'xcode_settings': {
304 #                'DYLIB_INSTALL_NAME_BASE': '@loader_path',
305 #              }
306       lib_dirs = [ target_gen_dir ]
307     } else if (is_win) {
308       defines += [
309         "inline=__inline",
310         "strtoll=_strtoi64",
311         "_ISOC99_SOURCE",
312         "_LARGEFILE_SOURCE",
313         "HAVE_AV_CONFIG_H",
314         "strtod=avpriv_strtod",
315         "snprintf=avpriv_snprintf",
316         "_snprintf=avpriv_snprintf",
317         "vsnprintf=avpriv_vsnprintf",
318       ]
319
320       include_dirs += [
321         "chromium/include/win"
322       ]
323       # TODO(dalecurtis): We should fix these.  http://crbug.com/154421
324       cflags += [
325         "/wd4996", # 'function': was declared deprecated
326         "/wd4018", # 'expression': signed/unsigned mismatch
327         "/wd4090", # 'operation' : different 'modifier' qualifiers
328         "/wd4305", # 'identifier': truncation from 'type1' to 'type2'
329         "/wd4133", # 'type' : incompatible types - from 'type1' to 'type2'
330         "/wd4146", # unary minus operator applied to unsigned type, result
331                    #   still unsigned
332         "/wd4554", # 'operator' : check operator precedence for possible
333                    #   error; use parentheses to clarify precedence
334         "/wd4028", # formal parameter 'number' different from declaration
335         "/wd4334", # 'operator' : result of 32-bit shift implicitly
336                    #   converted to 64 bits (was 64-bit shift intended?)
337         "/wd4101", # 'identifier' : unreferenced local variable
338         "/wd4102", # 'label' : unreferenced label
339         "/wd4116", # unnamed type definition in parentheses
340         "/wd4307", # 'operator' : integral constant overflow
341         "/wd4273", # 'function' : inconsistent DLL linkage
342         "/wd4005", # 'identifier' : macro redefinition
343         "/wd4056", # overflow in floating point constant arithmetic
344         "/wd4756", # overflow in constant arithmetic
345       ]
346 # TODO(ajwong): Verify this is true.
347       # Ignore warnings about a local symbol being inefficiently imported,
348       # upstream is working on a fix.
349       ldflags += [
350         "/ignore:4049", # locally defined symbol 'symbol' imported
351         "/ignore:4217", # locally defined symbol 'symbol' imported in
352                         #   function 'function'
353       ]
354       if (cpu_arch == "x64") {
355         # TODO(wolenetz): We should fix this.  http://crbug.com/171009
356         cflags += [
357           "/wd4267"  # Conversion from size_t to 'type'.
358         ]
359       }
360       deps += [ ":ffmpeg_generate_def" ]
361     }
362
363     if (cpu_arch != "arm" && cpu_arch != "mipsel" && os_config != "linux-noasm") {
364       deps += [ ":ffmpeg_yasm" ]
365     }
366   }
367 }
368
369 if (is_win) {
370   config("ffmpeg_win_dependent_config") {
371     include_dirs = [
372       platform_config_root,
373       "chromium/include/win",
374       ".",
375     ]
376     libs = [ "$target_out_dir/ffmpegsumo.lib" ]
377     ldflags = [ "/DELAYLOAD:ffmpegsumo.dll" ]
378   }
379
380   action("ffmpeg_generate_def") {
381     script = generate_stubs_script
382     sources = sig_files
383     outputs = [ "$target_gen_dir/ffmpegsumo.def" ]
384     args = [
385 # TODO(ajwong): This was -i <(INTERMEDIATE_DIR). What next?
386       "-i", rebase_path(target_out_dir, root_build_dir),
387       "-o", rebase_path(target_gen_dir, root_build_dir),
388       "-t", "windows_def",
389       "-m", "ffmpegsumo.dll",
390     ] + rebase_path(sources, root_build_dir)
391   }
392
393   group("ffmpeg") {
394     public_configs = [ ":ffmpeg_win_dependent_config" ]
395     public_deps = [
396       ":ffmpeg_generate_stubs",
397       ":ffmpegsumo",
398     ]
399   }
400 } else {
401   config("ffmpeg_posix_dependent_config") {
402     include_dirs = [
403       platform_config_root,
404       ".",
405     ]
406   }
407   component("ffmpeg") {
408     sources = [
409       "$target_gen_dir/$stubs_filename_root.cc",
410       "$target_gen_dir/$stubs_filename_root.h",
411     ]
412     configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
413     defines = [
414       "__STDC_CONSTANT_MACROS",  # FFmpeg uses INT64_C.
415     ]
416
417     include_dirs = [
418       platform_config_root,
419       ".",
420     ]
421
422     public_configs = [ ":ffmpeg_posix_dependent_config" ]
423     deps = [ ":ffmpeg_generate_stubs", ":ffmpegsumo" ]
424   }
425 }