2f1b52180ced5abcdc4159fad32d41ab52c308be
[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     },
34   },
35   'variables': {
36     # Make sure asm_sources is always defined even if an arch doesn't have any
37     # asm sources (e.g. mips or x86 with forcefully disabled asm).
38     'asm_sources': [
39     ],
40
41     # Allow overriding the selection of which FFmpeg binaries to copy via an
42     # environment variable.  Affects the ffmpeg_binaries target.
43     'conditions': [
44       ['target_arch == "arm" and arm_version == 7 and arm_neon == 1', {
45         # Need a separate config for arm+neon vs arm
46         'ffmpeg_config%': 'arm-neon',
47       }, {
48         'ffmpeg_config%': '<(target_arch)',
49       }],
50       ['OS == "win" and (MSVS_VERSION == "2013" or MSVS_VERSION == "2013e")', {
51         'os_config%': 'win-vs2013',
52       }, {
53         'conditions': [
54           ['OS == "mac" or OS == "win" or OS == "openbsd"', {
55             'os_config%': '<(OS)',
56           }, {  # all other Unix OS's use the linux config
57             'conditions': [
58               ['msan==1', {
59                 # MemorySanitizer doesn't like assembly code.
60                 'os_config%': 'linux-noasm',
61               }, {
62                 'os_config%': 'linux',
63               }]
64             ],
65           }],
66         ],
67       }],
68       ['chromeos == 1', {
69         'ffmpeg_branding%': '<(branding)OS',
70       }, {  # otherwise, assume Chrome/Chromium.
71         'ffmpeg_branding%': '<(branding)',
72       }],
73     ],
74
75     'ffmpeg_variant%': '<(target_arch)',
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           # VS2010 does not correctly incrementally link obj files generated
94           # from asm files. This flag disables UseLibraryDependencyInputs to
95           # avoid this problem.
96           'msvs_2010_disable_uldi_when_referenced': 1,
97           'includes': [
98             'ffmpeg_generated.gypi',
99             '../yasm/yasm_compile.gypi',
100           ],
101           'sources': [
102             '<@(asm_sources)',
103             # XCode doesn't want to link a pure assembly target and will fail
104             # to link when it creates an empty file list.  So add a dummy file
105             # keep the linker happy.  See http://crbug.com/157073
106             'xcode_hack.c',
107           ],
108           'variables': {
109             # Path to platform configuration files.
110             'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)',
111
112             'conditions': [
113               ['target_arch == "ia32"', {
114                 'more_yasm_flags': [
115                   '-DARCH_X86_32',
116                  ],
117               }, {
118                 'more_yasm_flags': [
119                   '-DARCH_X86_64',
120                 ],
121               }],
122               ['OS == "mac"', {
123                 'more_yasm_flags': [
124                   # Necessary to ensure symbols end up with a _ prefix; added by
125                   # yasm_compile.gypi for Windows, but not Mac.
126                   '-DPREFIX',
127                 ]
128               }],
129             ],
130             'yasm_flags': [
131               '-DPIC',
132               '>@(more_yasm_flags)',
133               '-I', '<(platform_config_root)',
134               '-I', 'libavcodec/x86/',
135               '-I', 'libavutil/x86/',
136               '-I', '.',
137               # Disable warnings, prevents log spam for things we won't fix.
138               '-w',
139               '-P', 'config.asm',
140             ],
141             'yasm_output_path': '<(shared_generated_dir)/yasm'
142           },
143         },
144       ] # targets
145     }], # arch != arm
146     ['OS == "win" and clang == 0 and MSVS_VERSION != "2013" and MSVS_VERSION != "2013e"', {
147       # Convert the source code from c99 to c89 if we're on Windows and not
148       # using clang, which can compile c99 directly.  Clang support is
149       # experimental and unsupported. VS2013 also supports enough of C99 to
150       # be able to avoid this conversion.
151       'variables': {
152         'converter_script': 'chromium/scripts/c99conv.py',
153         'converter_executable': 'chromium/binaries/c99conv.exe',
154         # Path to platform configuration files.
155         'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)',
156       },
157       'includes': [
158         'ffmpeg_generated.gypi',
159       ],
160       'targets': [{
161         'target_name': 'convert_ffmpeg_sources',
162         'type': 'none',
163         'sources': [
164           '<@(c_sources)',
165         ],
166         'rules': [
167           {
168             'rule_name': 'convert_c99_to_c89',
169             'extension': 'c',
170             'inputs': [
171               '<(converter_script)',
172               '<(converter_executable)',
173               # Since we don't know the dependency graph for header includes
174               # we need to list them all here to ensure a header change causes
175               # a recompilation.
176               '<(platform_config_root)/config.h',
177               '<(platform_config_root)/libavutil/avconfig.h',
178               '<@(c_headers)',
179             ],
180             # Argh!  Required so that the msvs generator will properly convert
181             # RULE_INPUT_DIRNAME to a relative path.
182             'msvs_external_rule': 1,
183             'outputs': [
184               '<(shared_generated_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).c',
185             ],
186             'action': [
187               'python',
188               '<(converter_script)',
189               '<(RULE_INPUT_PATH)',
190               '<(shared_generated_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).c',
191               '-I', '<(platform_config_root)',
192             ],
193             'message': 'Converting <(RULE_INPUT_PATH) from C99 to C89',
194             'process_outputs_as_sources': 1,
195           },
196         ],
197       }],
198     }],
199     ['build_ffmpegsumo != 0', {
200       'includes': [
201         'ffmpeg_generated.gypi',
202       ],
203       'variables': {
204         # Path to platform configuration files.
205         'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)',
206       },
207       'targets': [
208         {
209           'target_name': 'ffmpegsumo',
210           'type': 'loadable_module',
211           'sources': [
212             '<(platform_config_root)/config.h',
213             '<(platform_config_root)/libavutil/avconfig.h',
214           ],
215           'include_dirs': [
216             '<(platform_config_root)',
217             '.',
218           ],
219           'defines': [
220             'HAVE_AV_CONFIG_H',
221             '_POSIX_C_SOURCE=200112',
222             '_XOPEN_SOURCE=600',
223             'PIC',
224           ],
225           'cflags': [
226             '-fPIC',
227             '-fomit-frame-pointer',
228           ],
229           'conditions': [
230             ['OS != "win" or clang == 1 or MSVS_VERSION == "2013" or MSVS_VERSION == "2013e"', {
231               # If we're not doing C99 conversion, add the normal source code.
232               'sources': ['<@(c_sources)'],
233             }, {
234               # Otherwise, compile the converted source code.
235               'dependencies': ['convert_ffmpeg_sources'],
236               'sources': ['<@(converter_outputs)'],
237             }],
238             ['target_arch != "arm" and target_arch != "mipsel" and os_config != "linux-noasm"', {
239               'dependencies': [
240                 'ffmpeg_yasm',
241               ],
242             }],
243             ['clang == 1', {
244               'xcode_settings': {
245                 'WARNING_CFLAGS': [
246                   # ffmpeg uses its own deprecated functions.
247                   '-Wno-deprecated-declarations',
248                   # ffmpeg doesn't care about pointer constness.
249                   '-Wno-incompatible-pointer-types',
250                   # ffmpeg doesn't follow usual parentheses conventions.
251                   '-Wno-parentheses',
252                   # ffmpeg doesn't care about pointer signedness.
253                   '-Wno-pointer-sign',
254                   # ffmpeg doesn't believe in exhaustive switch statements.
255                   '-Wno-switch',
256                 ],
257               },
258               'cflags': [
259                 '-Wno-deprecated-declarations',
260                 '-Wno-incompatible-pointer-types',
261                 '-Wno-logical-op-parentheses',
262                 '-Wno-parentheses',
263                 '-Wno-pointer-sign',
264                 '-Wno-switch',
265                 # Don't emit warnings for gcc -f flags clang doesn't implement.
266                 '-Qunused-arguments',
267               ],
268               'conditions': [
269                 ['ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS"', {
270                   'xcode_settings': {
271                     'WARNING_CFLAGS': [
272                       # Clang doesn't support __attribute__((flatten)),
273                       # http://llvm.org/PR7559
274                       # This is used in the h264 decoder.
275                       '-Wno-attributes',
276                     ],
277                   },
278                   'cflags': [
279                     '-Wno-attributes',
280                   ],
281                 }],
282               ],
283             }, {
284               'cflags': [
285                 # gcc doesn't have flags for specific warnings, so disable them
286                 # all.
287                 '-w',
288               ],
289             }],
290             ['target_arch == "ia32"', {
291               # Turn off valgrind build option that breaks ffmpeg builds.
292               'cflags!': [
293                 '-fno-omit-frame-pointer',
294               ],
295               'debug_extra_cflags!': [
296                 '-fno-omit-frame-pointer',
297               ],
298               'release_extra_cflags!': [
299                 '-fno-omit-frame-pointer',
300               ],
301             }],  # target_arch == "ia32"
302             ['target_arch == "arm"', {
303               # TODO(ihf): See the long comment in build_ffmpeg.sh
304               # We want to be consistent with CrOS and have configured
305               # ffmpeg for thumb. Protect yourself from -marm.
306               'cflags!': [
307                 '-marm',
308               ],
309               'cflags': [
310                 '-mthumb',
311                 '-march=armv7-a',
312                 '-mtune=cortex-a8',
313               ],
314               # On arm we use gcc to compile the assembly.
315               'sources': [
316                 '<@(asm_sources)',
317               ],
318               'conditions': [
319                 ['arm_neon == 0', {
320                   'cflags': [
321                     '-mfpu=vfpv3-d16',
322                   ],
323                 }, {
324                   'cflags': [
325                     '-mfpu=neon',
326                   ],
327                 }],
328                 ['arm_float_abi == "hard"', {
329                   'cflags': [
330                     '-DHAVE_VFP_ARGS=1'
331                   ],
332                 }, {
333                   'cflags': [
334                     '-DHAVE_VFP_ARGS=0'
335                   ],
336                 }],
337               ],
338             }],
339             ['target_arch == "mipsel"', {
340               'cflags': [
341                 '-mips32',
342                 '-EL -Wl,-EL',
343               ],
344             }],  # target_arch == "mipsel"
345             ['os_posix == 1 and OS != "mac"', {
346               'defines': [
347                 '_ISOC99_SOURCE',
348                 '_LARGEFILE_SOURCE',
349                 # BUG(ihf): ffmpeg compiles with this define. But according to
350                 # ajwong: I wouldn't change _FILE_OFFSET_BITS.  That's a scary change
351                 # cause it affects the default length of off_t, and fpos_t,
352                 # which can cause strange problems if the loading code doesn't
353                 # have it set and you start passing FILE*s or file descriptors
354                 # between symbol contexts.
355                 # '_FILE_OFFSET_BITS=64',
356               ],
357               'cflags': [
358                 '-std=c99',
359                 '-pthread',
360                 '-fno-math-errno',
361                 '-fno-signed-zeros',
362                 '-fno-tree-vectorize',
363                 '-fomit-frame-pointer',
364                 # Don't warn about libavformat using its own deprecated APIs.
365                 '-Wno-deprecated-declarations',
366               ],
367               'cflags!': [
368                 # Ensure the symbols are exported.
369                 #
370                 # TODO(ajwong): Manually tag the API that we use to be
371                 # exported.
372                 '-fvisibility=hidden',
373               ],
374               'link_settings': {
375                 'ldflags': [
376                   '-Wl,-Bsymbolic',
377                   '-L<(shared_generated_dir)',
378                 ],
379                 'libraries': [
380                   '-lz',
381                 ],
382               },
383             }],  # os_posix == 1 and OS != "mac"
384             ['OS == "openbsd"', {
385               # OpenBSD's gcc (4.2.1) does not support this flag
386               'cflags!': [
387                 '-fno-signed-zeros',
388               ],
389             }],
390             ['OS == "mac"', {
391               'defines': [
392                 '_DARWIN_C_SOURCE',
393               ],
394               'conditions': [
395                 ['mac_breakpad == 1', {
396                   'variables': {
397                     # A real .dSYM is needed for dump_syms to operate on.
398                     'mac_real_dsym': 1,
399                   },
400                 }],
401                 ['target_arch != "x64"', {
402                   # -read_only_relocs cannot be used with x86_64
403                   'xcode_settings': {
404                     'OTHER_LDFLAGS': [
405                       # This is needed because even though FFmpeg now builds
406                       # with -fPIC, it's not quite a complete PIC build, only
407                       # partial :( Thus we need to instruct the linker to allow
408                       # relocations for read-only segments for this target to be
409                       # able to generated the shared library on Mac.
410                       #
411                       # This makes Mark sad, but he's okay with it since it is
412                       # isolated to this module. When Mark finds this in the
413                       # future, and has forgotten this conversation, this
414                       # comment should remind him that the world is still nice
415                       # and butterflies still exist...as do rainbows, sunshine,
416                       # tulips, etc., etc...but not kittens. Those went away
417                       # with this flag.
418                       '-Wl,-read_only_relocs,suppress',
419                     ],
420                   },
421                 }],
422               ],
423               'link_settings': {
424                 'libraries': [
425                   '$(SDKROOT)/usr/lib/libz.dylib',
426                 ],
427               },
428               'xcode_settings': {
429                 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',  # No -fvisibility=hidden
430                 'DYLIB_INSTALL_NAME_BASE': '@loader_path',
431                 'LIBRARY_SEARCH_PATHS': [
432                   '<(shared_generated_dir)'
433                 ],
434               },
435             }],  # OS == "mac"
436             ['OS == "win"', {
437               'sources': [
438                 '<(shared_generated_dir)/ffmpegsumo.def',
439               ],
440               'include_dirs': [
441                 'chromium/include/win',
442               ],
443               # TODO(dalecurtis): We should fix these.  http://crbug.com/154421
444               'msvs_disabled_warnings': [
445                 4996, 4018, 4090, 4305, 4133, 4146, 4554, 4028, 4334, 4101, 4102,
446                 4116, 4307, 4273, 4005, 4056, 4756,
447               ],
448               'conditions': [
449                 ['clang == 1 or (OS == "win" and (MSVS_VERSION == "2013" or MSVS_VERSION == "2013e"))', {
450                   'defines': [
451                     'inline=__inline',
452                     'strtoll=_strtoi64',
453                     '_ISOC99_SOURCE',
454                     '_LARGEFILE_SOURCE',
455                     'HAVE_AV_CONFIG_H',
456                     'strtod=avpriv_strtod',
457                     'snprintf=avpriv_snprintf',
458                     '_snprintf=avpriv_snprintf',
459                     'vsnprintf=avpriv_vsnprintf',
460                   ],
461                 }],
462                 ['target_arch == "x64"', {
463                   # TODO(wolenetz): We should fix this.  http://crbug.com/171009
464                   'msvs_disabled_warnings' : [
465                     4267
466                   ],
467                 }],
468               ],
469               'msvs_settings': {
470                 # This magical incantation is necessary because VC++ will compile
471                 # object files to same directory... even if they have the same name!
472                 'VCCLCompilerTool': {
473                   'ObjectFile': '$(IntDir)/%(RelativeDir)/',
474                 },
475                 # Ignore warnings about a local symbol being inefficiently imported,
476                 # upstream is working on a fix.
477                 'VCLinkerTool': {
478                   'AdditionalOptions': ['/ignore:4049', '/ignore:4217'],
479                 }
480               },
481               'actions': [
482                 {
483                   'action_name': 'generate_def',
484                   'inputs': [
485                     '<(generate_stubs_script)',
486                     '<@(sig_files)',
487                   ],
488                   'outputs': [
489                     '<(shared_generated_dir)/ffmpegsumo.def',
490                   ],
491                   'action': ['python',
492                              '<(generate_stubs_script)',
493                              '-i', '<(INTERMEDIATE_DIR)',
494                              '-o', '<(shared_generated_dir)',
495                              '-t', 'windows_def',
496                              '-m', 'ffmpegsumo.dll',
497                              '<@(_inputs)',
498                   ],
499                   'message': 'Generating FFmpeg export definitions',
500                 },
501               ],
502             }],
503           ],
504         },
505       ],
506     }],
507   ],  # conditions
508   'targets': [
509     {
510       'target_name': 'ffmpeg',
511       'sources': [
512         # Files needed for stub generation rules.
513         '<@(sig_files)',
514       ],
515       'defines': [
516         '__STDC_CONSTANT_MACROS',  # FFmpeg uses INT64_C.
517       ],
518       'hard_dependency': 1,
519
520       # Do not fear the massive conditional blocks!  They do the following:
521       #   1) Use the Window stub generator on Windows
522       #   2) Else, use the POSIX stub generator on non-Windows
523       'conditions': [
524         ['OS == "win"', {
525           'msvs_guid': 'D7A94F58-576A-45D9-A45F-EB87C63ABBB0',
526           'variables': {
527             'conditions': [
528               ['target_arch == "x64"', {
529                 'outfile_type': 'windows_lib_x64',
530               }, {  # else, generate x86 stub library
531                 'outfile_type': 'windows_lib',
532               }],
533             ],
534             'output_dir': '<(PRODUCT_DIR)/lib',
535             'intermediate_dir': '<(INTERMEDIATE_DIR)',
536           },
537           'type': 'none',
538           'sources': [
539             # Adds C99 types for Visual C++.
540             'chromium/include/win/inttypes.h',
541           ],
542           'dependencies': [
543             'ffmpegsumo',
544           ],
545           'direct_dependent_settings': {
546             'include_dirs': [
547               '<(platform_config_root)',
548               'chromium/include/win',
549               '.',
550             ],
551             'link_settings': {
552               'libraries': [
553                 '<(output_dir)/ffmpegsumo.lib',
554               ],
555               'msvs_settings': {
556                 'VCLinkerTool': {
557                   'DelayLoadDLLs': [
558                     'ffmpegsumo.dll',
559                   ],
560                 },
561               },
562             },
563           },
564           'rules': [
565             {
566               'rule_name': 'generate_libs',
567               'extension': 'sigs',
568               'inputs': [
569                 '<(generate_stubs_script)',
570                 '<@(sig_files)',
571               ],
572               'outputs': [
573                 '<(output_dir)/<(RULE_INPUT_ROOT).lib',
574               ],
575               'action': ['python', '<(generate_stubs_script)',
576                          '-i', '<(intermediate_dir)',
577                          '-o', '<(output_dir)',
578                          '-t', '<(outfile_type)',
579                          '<@(RULE_INPUT_PATH)',
580               ],
581               'message': 'Generating FFmpeg import libraries',
582             },
583           ],
584         }, {  # else OS != "win", use POSIX stub generator
585           'variables': {
586             'outfile_type': 'posix_stubs',
587             'stubs_filename_root': 'ffmpeg_stubs',
588             'project_path': 'third_party/ffmpeg',
589             'intermediate_dir': '<(INTERMEDIATE_DIR)',
590             'output_root': '<(SHARED_INTERMEDIATE_DIR)/ffmpeg',
591             'platform_config_root': 'chromium/config/<(ffmpeg_branding)/<(os_config)/<(ffmpeg_config)'
592           },
593           'sources': [
594             '<(extra_header)',
595           ],
596           'type': '<(component)',
597           'include_dirs': [
598             '<(output_root)',
599             '../..',  # The chromium 'src' directory.
600             '<(platform_config_root)',
601             '.',
602           ],
603           'dependencies': [
604             # Required for the logging done in the stubs generator.
605             '../../base/base.gyp:base',
606           ],
607           'direct_dependent_settings': {
608             'defines': [
609               '__STDC_CONSTANT_MACROS',  # FFmpeg uses INT64_C.
610             ],
611             'include_dirs': [
612               '<(output_root)',
613               '../..',  # The chromium 'src' directory.
614               '<(platform_config_root)',
615               '.',
616             ],
617           },
618           'actions': [
619             {
620               'action_name': 'generate_stubs',
621               'inputs': [
622                 '<(generate_stubs_script)',
623                 '<(extra_header)',
624                 '<@(sig_files)',
625               ],
626               'outputs': [
627                 '<(intermediate_dir)/<(stubs_filename_root).cc',
628                 '<(output_root)/<(project_path)/<(stubs_filename_root).h',
629               ],
630               'action': ['python',
631                          '<(generate_stubs_script)',
632                          '-i', '<(intermediate_dir)',
633                          '-o', '<(output_root)/<(project_path)',
634                          '-t', '<(outfile_type)',
635                          '-e', '<(extra_header)',
636                          '-s', '<(stubs_filename_root)',
637                          '-p', '<(project_path)',
638                          '<@(_inputs)',
639               ],
640               'process_outputs_as_sources': 1,
641               'message': 'Generating FFmpeg stubs for dynamic loading',
642             },
643           ],
644           'conditions': [
645             # Linux/Solaris need libdl for dlopen() and friends.
646             ['OS == "linux" or OS == "solaris"', {
647               'link_settings': {
648                 'libraries': [
649                   '-ldl',
650                 ],
651               },
652             }],
653             ['component == "shared_library"', {
654               'cflags!': ['-fvisibility=hidden'],
655               'xcode_settings': {
656                 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',  # no -fvisibility=hidden
657               },
658             }],
659             ['build_ffmpegsumo != 0', {
660               'dependencies': [
661                 'ffmpegsumo',
662               ],
663             }],
664           ],  # conditions
665         }],
666       ],  # conditions
667     },
668   ],  # targets
669 }