Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / ffmpeg.gyp
1 # Copyright (c) 2011 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 # There's a couple key GYP variables that control how FFmpeg is built:
6 #   ffmpeg_branding
7 #     Controls whether we build the Chromium or Google Chrome version of
8 #     FFmpeg.  The Google Chrome version contains additional codecs.
9 #     Typical values are Chromium, Chrome, ChromiumOS, and ChromeOS.
10 #   build_ffmpegsumo
11 #     When set to zero will build Chromium against Chrome's FFmpeg headers, but
12 #     not build ffmpegsumo itself.  Users are expected to build and provide
13 #     their own version of ffmpegsumo.  Default value is 1.
14 #
15
16 {
17   'target_defaults': {
18     'variables': {
19       # Since we are not often debugging FFmpeg, and performance is
20       # unacceptable without optimization, freeze the optimizations to -O2.
21       # If someone really wants -O1 , they can change these in their checkout.
22       # If you want -O0, see the Gotchas in README.Chromium for why that
23       # won't work.
24       'release_optimize': '2',
25       'debug_optimize': '2',
26       'mac_debug_optimization': '2',
27       # In addition to the above reasons, /Od optimization won't remove symbols
28       # that are under "if (0)" style sections.  Which lead to link time errors
29       # when for example it tries to link an ARM symbol on X86.
30       'win_debug_Optimization': '2',
31       # Run time checks are incompatible with any level of optimizations.
32       'win_debug_RuntimeChecks': '0',
33       'conditions': [
34         ['OS == "win"', {
35           # Setting the optimizations to 'speed' or to 'max' results in a lot of
36           # unresolved symbols. The only supported mode is 'size' (see
37           # crbug.com/264459).
38           'optimize' :'size',
39         }],
40       ],
41     },
42   },
43   'variables': {
44     # Make sure asm_sources is always defined even if an arch doesn't have any
45     # asm sources (e.g. mips or x86 with forcefully disabled asm).
46     'asm_sources': [
47     ],
48
49     # Allow overriding the selection of which FFmpeg binaries to copy via an
50     # environment variable.  Affects the ffmpeg_binaries target.
51     'conditions': [
52       ['target_arch == "arm" and arm_version == 7 and arm_neon == 1', {
53         # Need a separate config for arm+neon vs arm
54         'ffmpeg_config%': 'arm-neon',
55       }, {
56         'ffmpeg_config%': '<(target_arch)',
57       }],
58       ['OS == "mac" or OS == "win" or OS == "openbsd"', {
59         'os_config%': '<(OS)',
60       }, {  # all other Unix OS's use the linux config
61         'conditions': [
62           ['msan==1', {
63             # MemorySanitizer doesn't like assembly code.
64             'os_config%': 'linux-noasm',
65           }, {
66             'os_config%': 'linux',
67           }]
68         ],
69       }],
70       ['chromeos == 1', {
71         'ffmpeg_branding%': '<(branding)OS',
72       }, {  # otherwise, assume Chrome/Chromium.
73         'ffmpeg_branding%': '<(branding)',
74       }],
75     ],
76
77     'build_ffmpegsumo%': 1,
78
79     # Locations for generated artifacts.
80     'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/third_party/ffmpeg',
81
82     # Stub generator script and signatures of all functions used by Chrome.
83     'generate_stubs_script': '../../tools/generate_stubs/generate_stubs.py',
84     'sig_files': ['chromium/ffmpegsumo.sigs'],
85     'extra_header': 'chromium/ffmpeg_stub_headers.fragment',
86   },
87   'conditions': [
88     ['target_arch != "arm" and os_config != "linux-noasm"', {
89       'targets': [
90         {
91           'target_name': 'ffmpeg_yasm',
92           'type': 'static_library',
93           'includes': [
94             'ffmpeg_generated.gypi',
95             '../yasm/yasm_compile.gypi',
96           ],
97           'sources': [
98             '<@(asm_sources)',
99             # XCode doesn't want to link a pure assembly target and will fail
100             # to link when it creates an empty file list.  So add a dummy file
101             # keep the linker happy.  See http://crbug.com/157073
102             'xcode_hack.c',
103           ],
104           'variables': {
105             # Path to platform configuration files.
106             'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)',
107
108             'conditions': [
109               ['target_arch == "ia32"', {
110                 'more_yasm_flags': [
111                   '-DARCH_X86_32',
112                  ],
113               }, {
114                 'more_yasm_flags': [
115                   '-DARCH_X86_64',
116                 ],
117               }],
118               ['OS == "mac"', {
119                 'more_yasm_flags': [
120                   # Necessary to ensure symbols end up with a _ prefix; added by
121                   # yasm_compile.gypi for Windows, but not Mac.
122                   '-DPREFIX',
123                 ]
124               }],
125             ],
126             'yasm_flags': [
127               '-DPIC',
128               '>@(more_yasm_flags)',
129               '-I', '<(platform_config_root)',
130               '-I', 'libavcodec/x86/',
131               '-I', 'libavutil/x86/',
132               '-I', '.',
133               # Disable warnings, prevents log spam for things we won't fix.
134               '-w',
135               '-P', 'config.asm',
136             ],
137             'yasm_output_path': '<(shared_generated_dir)/yasm'
138           },
139         },
140       ] # targets
141     }], # arch != arm
142     ['build_ffmpegsumo != 0', {
143       'includes': [
144         'ffmpeg_generated.gypi',
145       ],
146       'variables': {
147         # Path to platform configuration files.
148         'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)',
149       },
150       'targets': [
151         {
152           'target_name': 'ffmpegsumo',
153           'type': 'loadable_module',
154           'sources': [
155             '<@(c_sources)',
156             '<(platform_config_root)/config.h',
157             '<(platform_config_root)/libavutil/avconfig.h',
158           ],
159           'include_dirs': [
160             '<(platform_config_root)',
161             '.',
162           ],
163           'defines': [
164             'HAVE_AV_CONFIG_H',
165             '_POSIX_C_SOURCE=200112',
166             '_XOPEN_SOURCE=600',
167             'PIC',
168             # Disable deprecated features which generate spammy warnings.
169             'FF_API_PIX_FMT_DESC=0',
170             'FF_API_OLD_DECODE_AUDIO=0',
171             'FF_API_DESTRUCT_PACKET=0',
172             'FF_API_GET_BUFFER=0',
173           ],
174           'variables': {
175             'clang_warning_flags': [
176               '-Wno-absolute-value',
177               # ffmpeg uses its own deprecated functions.
178               '-Wno-deprecated-declarations',
179               # ffmpeg doesn't care about pointer constness.
180               '-Wno-incompatible-pointer-types',
181               # ffmpeg doesn't follow usual parentheses conventions.
182               '-Wno-parentheses',
183               # ffmpeg doesn't care about pointer signedness.
184               '-Wno-pointer-sign',
185               # ffmpeg doesn't believe in exhaustive switch statements.
186               '-Wno-switch',
187             ],
188           },
189           'cflags': [
190             '-fPIC',
191             '-fomit-frame-pointer',
192             # ffmpeg uses its own deprecated functions.
193             '-Wno-deprecated-declarations',
194           ],
195           'conditions': [
196             ['target_arch != "arm" and target_arch != "mipsel" and os_config != "linux-noasm"', {
197               'dependencies': [
198                 'ffmpeg_yasm',
199               ],
200             }],
201             ['clang != 1', {
202               'cflags': [
203                 # gcc doesn't have flags for specific warnings, so disable them
204                 # all.
205                 '-w',
206               ],
207             }],
208             ['target_arch == "ia32"', {
209               # Turn off valgrind build option that breaks ffmpeg builds.
210               'cflags!': [
211                 '-fno-omit-frame-pointer',
212               ],
213               'debug_extra_cflags!': [
214                 '-fno-omit-frame-pointer',
215               ],
216               'release_extra_cflags!': [
217                 '-fno-omit-frame-pointer',
218               ],
219             }],  # target_arch == "ia32"
220             ['target_arch == "arm"', {
221               # TODO(ihf): See the long comment in build_ffmpeg.sh
222               # We want to be consistent with CrOS and have configured
223               # ffmpeg for thumb. Protect yourself from -marm.
224               'cflags!': [
225                 '-marm',
226               ],
227               'cflags': [
228                 '-mthumb',
229                 '-march=armv7-a',
230                 '-mtune=cortex-a8',
231               ],
232               # On arm we use gcc to compile the assembly.
233               'sources': [
234                 '<@(asm_sources)',
235               ],
236               'conditions': [
237                 ['arm_neon == 0', {
238                   'cflags': [
239                     '-mfpu=vfpv3-d16',
240                   ],
241                 }, {
242                   'cflags': [
243                     '-mfpu=neon',
244                   ],
245                 }],
246                 ['arm_float_abi == "hard"', {
247                   'cflags': [
248                     '-DHAVE_VFP_ARGS=1'
249                   ],
250                 }, {
251                   'cflags': [
252                     '-DHAVE_VFP_ARGS=0'
253                   ],
254                 }],
255               ],
256             }],
257             ['target_arch == "mipsel"', {
258               'cflags': [
259                 '-mips32',
260                 '-EL -Wl,-EL',
261               ],
262             }],  # target_arch == "mipsel"
263             ['os_posix == 1 and OS != "mac"', {
264               'defines': [
265                 '_ISOC99_SOURCE',
266                 '_LARGEFILE_SOURCE',
267                 # BUG(ihf): ffmpeg compiles with this define. But according to
268                 # ajwong: I wouldn't change _FILE_OFFSET_BITS.  That's a scary change
269                 # cause it affects the default length of off_t, and fpos_t,
270                 # which can cause strange problems if the loading code doesn't
271                 # have it set and you start passing FILE*s or file descriptors
272                 # between symbol contexts.
273                 # '_FILE_OFFSET_BITS=64',
274               ],
275               'cflags': [
276                 '-std=c99',
277                 '-pthread',
278                 '-fno-math-errno',
279                 '-fno-signed-zeros',
280                 '-fno-tree-vectorize',
281               ],
282               'cflags!': [
283                 # Ensure the symbols are exported.
284                 #
285                 # TODO(ajwong): Manually tag the API that we use to be
286                 # exported.
287                 '-fvisibility=hidden',
288               ],
289               'link_settings': {
290                 'ldflags': [
291                   '-Wl,-Bsymbolic',
292                   '-L<(shared_generated_dir)',
293                 ],
294                 'libraries': [
295                   '-lz',
296                 ],
297               },
298             }],  # os_posix == 1 and OS != "mac"
299             ['OS == "openbsd"', {
300               # OpenBSD's gcc (4.2.1) does not support this flag
301               'cflags!': [
302                 '-fno-signed-zeros',
303               ],
304             }],
305             ['OS == "mac"', {
306               'defines': [
307                 '_DARWIN_C_SOURCE',
308               ],
309               'conditions': [
310                 ['mac_breakpad == 1', {
311                   'variables': {
312                     # A real .dSYM is needed for dump_syms to operate on.
313                     'mac_real_dsym': 1,
314                   },
315                 }],
316                 ['target_arch != "x64"', {
317                   # -read_only_relocs cannot be used with x86_64
318                   'xcode_settings': {
319                     'OTHER_LDFLAGS': [
320                       # This is needed because even though FFmpeg now builds
321                       # with -fPIC, it's not quite a complete PIC build, only
322                       # partial :( Thus we need to instruct the linker to allow
323                       # relocations for read-only segments for this target to be
324                       # able to generated the shared library on Mac.
325                       #
326                       # This makes Mark sad, but he's okay with it since it is
327                       # isolated to this module. When Mark finds this in the
328                       # future, and has forgotten this conversation, this
329                       # comment should remind him that the world is still nice
330                       # and butterflies still exist...as do rainbows, sunshine,
331                       # tulips, etc., etc...but not kittens. Those went away
332                       # with this flag.
333                       '-Wl,-read_only_relocs,suppress',
334                     ],
335                   },
336                 }],
337               ],
338               'link_settings': {
339                 'libraries': [
340                   '$(SDKROOT)/usr/lib/libz.dylib',
341                 ],
342               },
343               'xcode_settings': {
344                 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',  # No -fvisibility=hidden
345                 'DYLIB_INSTALL_NAME_BASE': '@loader_path',
346                 'LIBRARY_SEARCH_PATHS': [
347                   '<(shared_generated_dir)'
348                 ],
349               },
350             }],  # OS == "mac"
351             ['OS == "win"', {
352               'sources': [
353                 '<(shared_generated_dir)/ffmpegsumo.def',
354               ],
355               'include_dirs': [
356                 'chromium/include/win',
357               ],
358               # TODO(dalecurtis): We should fix these.  http://crbug.com/154421
359               'msvs_disabled_warnings': [
360                 4996, 4018, 4090, 4305, 4133, 4146, 4554, 4028, 4334, 4101, 4102,
361                 4116, 4307, 4273, 4005, 4056, 4756,
362               ],
363               'conditions': [
364                 ['clang == 1 or (OS == "win" and (MSVS_VERSION == "2013" or MSVS_VERSION == "2013e"))', {
365                   'defines': [
366                     'inline=__inline',
367                     'strtoll=_strtoi64',
368                     '_ISOC99_SOURCE',
369                     '_LARGEFILE_SOURCE',
370                     'HAVE_AV_CONFIG_H',
371                     'strtod=avpriv_strtod',
372                     'snprintf=avpriv_snprintf',
373                     '_snprintf=avpriv_snprintf',
374                     'vsnprintf=avpriv_vsnprintf',
375                   ],
376                 }],
377                 ['target_arch == "x64"', {
378                   # TODO(wolenetz): We should fix this.  http://crbug.com/171009
379                   'msvs_disabled_warnings' : [
380                     4267
381                   ],
382                 }],
383               ],
384               'msvs_settings': {
385                 # Ignore warnings about a local symbol being inefficiently imported,
386                 # upstream is working on a fix.
387                 'VCLinkerTool': {
388                   'AdditionalOptions': ['/ignore:4049', '/ignore:4217'],
389                 }
390               },
391               'actions': [
392                 {
393                   'action_name': 'generate_def',
394                   'inputs': [
395                     '<(generate_stubs_script)',
396                     '<@(sig_files)',
397                   ],
398                   'outputs': [
399                     '<(shared_generated_dir)/ffmpegsumo.def',
400                   ],
401                   'action': ['python',
402                              '<(generate_stubs_script)',
403                              '-i', '<(INTERMEDIATE_DIR)',
404                              '-o', '<(shared_generated_dir)',
405                              '-t', 'windows_def',
406                              '-m', 'ffmpegsumo.dll',
407                              '<@(_inputs)',
408                   ],
409                   'message': 'Generating FFmpeg export definitions',
410                 },
411               ],
412             }],
413           ],
414         },
415       ],
416     }],
417   ],  # conditions
418   'targets': [
419     {
420       'target_name': 'ffmpeg',
421       'sources': [
422         # Files needed for stub generation rules.
423         '<@(sig_files)',
424       ],
425       'defines': [
426         '__STDC_CONSTANT_MACROS',  # FFmpeg uses INT64_C.
427       ],
428       'hard_dependency': 1,
429
430       # Do not fear the massive conditional blocks!  They do the following:
431       #   1) Use the Window stub generator on Windows
432       #   2) Else, use the POSIX stub generator on non-Windows
433       'conditions': [
434         ['OS == "win"', {
435           'msvs_guid': 'D7A94F58-576A-45D9-A45F-EB87C63ABBB0',
436           'variables': {
437             'conditions': [
438               ['target_arch == "x64"', {
439                 'outfile_type': 'windows_lib_x64',
440               }, {  # else, generate x86 stub library
441                 'outfile_type': 'windows_lib',
442               }],
443             ],
444             'output_dir': '<(PRODUCT_DIR)/lib',
445             'intermediate_dir': '<(INTERMEDIATE_DIR)',
446           },
447           'type': 'none',
448           'sources': [
449             # Adds C99 types for Visual C++.
450             'chromium/include/win/inttypes.h',
451           ],
452           'dependencies': [
453             'ffmpegsumo',
454           ],
455           'direct_dependent_settings': {
456             'include_dirs': [
457               '<(platform_config_root)',
458               'chromium/include/win',
459               '.',
460             ],
461             'link_settings': {
462               'libraries': [
463                 '<(output_dir)/ffmpegsumo.lib',
464               ],
465               'msvs_settings': {
466                 'VCLinkerTool': {
467                   'DelayLoadDLLs': [
468                     'ffmpegsumo.dll',
469                   ],
470                 },
471               },
472             },
473           },
474           'rules': [
475             {
476               'rule_name': 'generate_libs',
477               'extension': 'sigs',
478               'inputs': [
479                 '<(generate_stubs_script)',
480                 '<@(sig_files)',
481               ],
482               'outputs': [
483                 '<(output_dir)/<(RULE_INPUT_ROOT).lib',
484               ],
485               'action': ['python', '<(generate_stubs_script)',
486                          '-i', '<(intermediate_dir)',
487                          '-o', '<(output_dir)',
488                          '-t', '<(outfile_type)',
489                          '<@(RULE_INPUT_PATH)',
490               ],
491               'message': 'Generating FFmpeg import libraries',
492             },
493           ],
494         }, {  # else OS != "win", use POSIX stub generator
495           'variables': {
496             'outfile_type': 'posix_stubs',
497             'stubs_filename_root': 'ffmpeg_stubs',
498             'project_path': 'third_party/ffmpeg',
499             'intermediate_dir': '<(INTERMEDIATE_DIR)',
500             'output_root': '<(SHARED_INTERMEDIATE_DIR)/ffmpeg',
501             'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)'
502           },
503           'sources': [
504             '<(extra_header)',
505           ],
506           'type': '<(component)',
507           'include_dirs': [
508             '<(output_root)',
509             '../..',  # The chromium 'src' directory.
510             '<(platform_config_root)',
511             '.',
512           ],
513           'dependencies': [
514             # Required for the logging done in the stubs generator.
515             '../../base/base.gyp:base',
516           ],
517           'direct_dependent_settings': {
518             'defines': [
519               '__STDC_CONSTANT_MACROS',  # FFmpeg uses INT64_C.
520             ],
521             'include_dirs': [
522               '<(output_root)',
523               '../..',  # The chromium 'src' directory.
524               '<(platform_config_root)',
525               '.',
526             ],
527           },
528           'actions': [
529             {
530               'action_name': 'generate_stubs',
531               'inputs': [
532                 '<(generate_stubs_script)',
533                 '<(extra_header)',
534                 '<@(sig_files)',
535               ],
536               'outputs': [
537                 '<(intermediate_dir)/<(stubs_filename_root).cc',
538                 '<(output_root)/<(project_path)/<(stubs_filename_root).h',
539               ],
540               'action': ['python',
541                          '<(generate_stubs_script)',
542                          '-i', '<(intermediate_dir)',
543                          '-o', '<(output_root)/<(project_path)',
544                          '-t', '<(outfile_type)',
545                          '-e', '<(extra_header)',
546                          '-s', '<(stubs_filename_root)',
547                          '-p', '<(project_path)',
548                          '<@(_inputs)',
549               ],
550               'process_outputs_as_sources': 1,
551               'message': 'Generating FFmpeg stubs for dynamic loading',
552             },
553           ],
554           'conditions': [
555             # Linux/Solaris need libdl for dlopen() and friends.
556             ['OS == "linux" or OS == "solaris"', {
557               'link_settings': {
558                 'libraries': [
559                   '-ldl',
560                 ],
561               },
562             }],
563             ['component == "shared_library"', {
564               'cflags!': ['-fvisibility=hidden'],
565               'xcode_settings': {
566                 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',  # no -fvisibility=hidden
567               },
568             }],
569             ['build_ffmpegsumo != 0', {
570               'dependencies': [
571                 'ffmpegsumo',
572               ],
573             }],
574           ],  # conditions
575         }],
576       ],  # conditions
577     },
578   ],  # targets
579 }