1# Copyright (c) 2012 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  'variables': {
6    'libvpx_build_vp9%': 1,
7    'libvpx_source%': 'source/libvpx',
8    # Disable LTO for neon targets
9    # crbug.com/408997
10    'use_lto%': 0,
11    'conditions': [
12      ['os_posix==1', {
13        'asm_obj_extension': 'o',
14      }],
15      ['OS=="win"', {
16        'asm_obj_extension': 'obj',
17      }],
18
19      ['msan==1', {
20        'target_arch_full': 'generic',
21      }, {
22        'conditions': [
23          ['(target_arch=="arm" or target_arch=="armv7") and arm_neon==1', {
24            'target_arch_full': 'arm-neon',
25          }, {
26            'conditions': [
27              ['OS=="android" and ((target_arch=="arm" or target_arch=="armv7") and arm_neon==0)', {
28                'target_arch_full': 'arm-neon-cpu-detect',
29              }, {
30               'target_arch_full': '<(target_arch)',
31              }],
32            ],
33          }],
34          ['target_arch=="arm64"', {
35            'target_arch_full': 'arm64',
36          }],
37        ],
38      }],
39
40      ['os_posix == 1 and OS != "mac"', {
41        'OS_CATEGORY%': 'linux',
42      }, {
43        'OS_CATEGORY%': '<(OS)',
44      }],
45    ],
46
47    # Location of the intermediate output.
48    'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/third_party/libvpx',
49  },
50  'target_defaults': {
51    'target_conditions': [
52      ['<(libvpx_build_vp9)==0', {
53        'sources/': [ ['exclude', '(^|/)vp9/'], ],
54      }],
55    ],
56    'variables': {
57      'conditions': [
58        ['OS=="win" and buildtype=="Official"', {
59          # Do not set to 'size', as it results in an error on win64.
60          'optimize' :'speed',
61        }],
62      ],
63    },
64  },
65  'conditions': [
66    ['target_arch=="ia32"', {
67      'includes': ['libvpx_srcs_x86_intrinsics.gypi', ],
68    }],
69    ['target_arch=="x64" and msan==0', {
70      'includes': ['libvpx_srcs_x86_64_intrinsics.gypi', ],
71    }],
72    [ '(target_arch=="arm" or target_arch=="armv7") and arm_neon==0 and OS=="android"', {
73      # When building for targets which may not have NEON (but may!), include
74      # support for neon and hide it behind Android cpu-features.
75      'includes': ['libvpx_srcs_arm_neon_cpu_detect_intrinsics.gypi', ],
76    }],
77    [ '(target_arch != "arm" and target_arch != "armv7") and \
78       (target_arch != "mipsel" and target_arch != "mips64el")', {
79      'targets': [
80        {
81          # This libvpx target contains both encoder and decoder.
82          # Encoder is configured to be realtime only.
83          'target_name': 'libvpx',
84          'type': 'static_library',
85          'variables': {
86            'yasm_output_path': '<(SHARED_INTERMEDIATE_DIR)/third_party/libvpx',
87            'OS_CATEGORY%': '<(OS_CATEGORY)',
88            'yasm_flags': [
89              '-D', 'CHROMIUM',
90              '-I', 'source/config/<(OS_CATEGORY)/<(target_arch_full)',
91              '-I', 'source/config',
92              '-I', '<(libvpx_source)',
93              '-I', '<(shared_generated_dir)', # Generated assembly offsets
94            ],
95            # yasm only gets the flags we define. It doesn't inherit any of the
96            # really useful defines that come with a gcc invocation. In this
97            # case, we rely on __ANDROID__ to set 'rand' to 'lrand48'.
98            # Previously we used the builtin _rand but that's gone away.
99            'conditions': [
100              ['OS=="android"', {
101                'yasm_flags': [
102                  '-D', '__ANDROID__',
103                ],
104              }],
105            ],
106            'clang_warning_flags': [
107              # libvpx heavily relies on implicit enum casting.
108              '-Wno-conversion',
109              # libvpx does `if ((a == b))` in some places.
110              '-Wno-parentheses-equality',
111            ],
112          },
113          'dependencies': [
114            'gen_asm_offsets_vp8',
115          ],
116          'includes': [
117            '../yasm/yasm_compile.gypi'
118          ],
119          'include_dirs': [
120            'source/config/<(OS_CATEGORY)/<(target_arch_full)',
121            'source/config',
122            '<(libvpx_source)',
123            '<(libvpx_source)/vp8/common',
124            '<(libvpx_source)/vp8/decoder',
125            '<(libvpx_source)/vp8/encoder',
126            '<(shared_generated_dir)', # Provides vpx_rtcd.h.
127          ],
128          'direct_dependent_settings': {
129            'include_dirs': [
130              '<(libvpx_source)',
131            ],
132          },
133          # VS2010 does not correctly incrementally link obj files generated
134          # from asm files. This flag disables UseLibraryDependencyInputs to
135          # avoid this problem.
136          'msvs_2010_disable_uldi_when_referenced': 1,
137          'conditions': [
138            ['target_arch=="ia32"', {
139              'includes': [
140                'libvpx_srcs_x86.gypi',
141              ],
142              'dependencies': [
143                'libvpx_intrinsics_mmx',
144                'libvpx_intrinsics_sse2',
145                # Currently no sse3 intrinsic functions
146                #'libvpx_intrinsics_sse3',
147                'libvpx_intrinsics_ssse3',
148                'libvpx_intrinsics_sse4_1',
149                # Currently no avx intrinsic functions
150                #'libvpx_intrinsics_avx',
151                #'libvpx_intrinsics_avx2',
152              ],
153            }],
154            ['target_arch=="arm64"', {
155              'includes': [ 'libvpx_srcs_arm64.gypi', ],
156            }],
157            ['target_arch=="x64"', {
158              'conditions': [
159                ['msan==1', {
160                  'includes': [ 'libvpx_srcs_generic.gypi', ],
161                }, {
162                  'includes': [
163                    'libvpx_srcs_x86_64.gypi',
164                  ],
165                  'dependencies': [
166                    'libvpx_intrinsics_mmx',
167                    'libvpx_intrinsics_sse2',
168                    # Currently no sse3 intrinsic functions
169                    #'libvpx_intrinsics_sse3',
170                    'libvpx_intrinsics_ssse3',
171                    'libvpx_intrinsics_sse4_1',
172                    # Currently no avx intrinsic functions
173                    #'libvpx_intrinsics_avx',
174                    #'libvpx_intrinsics_avx2',
175                  ],
176                }],
177              ],
178            }],
179          ],
180        },
181      ],
182    },
183    ],
184    # 'libvpx' target for mipsel and mips64el builds.
185    [ 'target_arch=="mipsel" or target_arch=="mips64el"', {
186      'targets': [
187        {
188          # This libvpx target contains both encoder and decoder.
189          # Encoder is configured to be realtime only.
190          'target_name': 'libvpx',
191          'type': 'static_library',
192          'variables': {
193            'shared_generated_dir':
194              '<(SHARED_INTERMEDIATE_DIR)/third_party/libvpx',
195          },
196          'includes': [
197            'libvpx_srcs_mips.gypi',
198          ],
199          'include_dirs': [
200            'source/config/<(OS_CATEGORY)/<(target_arch_full)',
201            'source/config',
202            '<(libvpx_source)',
203            '<(libvpx_source)/vp8/common',
204            '<(libvpx_source)/vp8/decoder',
205            '<(libvpx_source)/vp8/encoder',
206          ],
207          'direct_dependent_settings': {
208            'include_dirs': [
209              '<(libvpx_source)',
210            ],
211          },
212          'sources': [
213            'source/config/<(OS_CATEGORY)/<(target_arch_full)/vpx_config.c',
214          ],
215        },
216      ],
217    },
218    ],
219    # 'libvpx' target for ARM builds.
220    [ '(target_arch=="arm" or target_arch=="armv7") ', {
221      'targets': [
222        {
223          # This libvpx target contains both encoder and decoder.
224          # Encoder is configured to be realtime only.
225          'target_name': 'libvpx',
226          'type': 'static_library',
227          'dependencies': [
228            'gen_asm_offsets_vp8',
229            'gen_asm_offsets_vpx_scale',
230          ],
231
232          # Copy the script to the output folder so that we can use it with
233          # absolute path.
234          'copies': [{
235            'destination': '<(shared_generated_dir)',
236            'files': [
237              '<(ads2gas_script_path)',
238              '<(ads2gas_script_include)',
239            ],
240          }],
241
242          # Rule to convert .asm files to .S files.
243          'rules': [
244            {
245              'rule_name': 'convert_asm',
246              'extension': 'asm',
247              'inputs': [
248                '<(shared_generated_dir)/<(ads2gas_script)',
249                '<(shared_generated_dir)/thumb.pm',
250              ],
251              'outputs': [
252                '<(shared_generated_dir)/<(RULE_INPUT_ROOT).S',
253              ],
254              'action': [
255                'bash',
256                '-c',
257                'cat <(RULE_INPUT_PATH) | perl <(shared_generated_dir)/<(ads2gas_script) -chromium > <(shared_generated_dir)/<(RULE_INPUT_ROOT).S',
258              ],
259              'process_outputs_as_sources': 1,
260              'message': 'Convert libvpx asm file for ARM <(RULE_INPUT_PATH)',
261            },
262          ],
263
264          'variables': {
265            'variables': {
266              'conditions': [
267                ['OS=="ios"', {
268                  'ads2gas_script%': 'ads2gas_apple.pl',
269                }, {
270                  'ads2gas_script%': 'ads2gas.pl',
271                }],
272              ],
273            },
274            'ads2gas_script%': '<(ads2gas_script)',
275            # Location of the assembly conversion script.
276            'ads2gas_script_path': '<(libvpx_source)/build/make/<(ads2gas_script)',
277            'ads2gas_script_include': '<(libvpx_source)/build/make/thumb.pm',
278          },
279          'xcode_settings': {
280            'OTHER_CFLAGS': [
281              '-I<!(pwd)/source/config/<(OS_CATEGORY)/<(target_arch_full)',
282              '-I<!(pwd)/source/config',
283              '-I<(shared_generated_dir)',
284            ],
285          },
286          'include_dirs': [
287            'source/config/<(OS_CATEGORY)/<(target_arch_full)',
288            'source/config',
289            '<(libvpx_source)',
290          ],
291          'direct_dependent_settings': {
292            'include_dirs': [
293              '<(libvpx_source)',
294            ],
295          },
296          # We need to explicitly tell the assembler to look for
297          # .include directive files from the place where they're
298          # generated to.
299          'cflags': [
300             '-Wa,-I,<(shared_generated_dir)',
301          ],
302          'conditions': [
303            # For Android WebView, the following pathc are not required and not
304            # allowed, because they generate the absolute path.
305            ['android_webview_build!=1', {
306              'cflags': [
307                '-Wa,-I,<!(pwd)/source/config/<(OS_CATEGORY)/<(target_arch_full)',
308                '-Wa,-I,<!(pwd)/source/config',
309              ],
310            }],
311            # Libvpx optimizations for ARMv6 or ARMv7 without NEON.
312            ['arm_neon==0', {
313              'conditions': [
314                ['OS=="android"', {
315                  'includes': [
316                    'libvpx_srcs_arm_neon_cpu_detect.gypi',
317                  ],
318                  'dependencies': [
319                    'libvpx_intrinsics_neon',
320		  ],
321                  'cflags': [
322                    '-Wa,-mfpu=neon',
323                  ],
324                }, {
325                  'includes': [
326                    'libvpx_srcs_arm.gypi',
327                  ],
328                }],
329              ],
330            }],
331            # Libvpx optimizations for ARMv7 with NEON.
332            ['arm_neon==1', {
333              'includes': [
334                'libvpx_srcs_arm_neon.gypi',
335              ],
336            }],
337            ['OS == "android"', {
338              'includes': [
339                '../../build/android/cpufeatures.gypi',
340              ],
341            }],
342            ['OS == "ios"', {
343              'xcode_settings': {
344                'OTHER_CFLAGS!': [
345                  # Breaks at least boolhuff_armv5te:token_high_bit_not_set_ev.
346                  '-fstack-protector-all',  # Implies -fstack-protector
347                ],
348              },
349            }],
350          ],
351        },
352      ],
353    }],
354  ],
355  'targets': [
356    {
357      # A tool that runs on host to extract integers from object file.
358      'target_name': 'libvpx_obj_int_extract',
359      'type': 'executable',
360      'toolsets': ['host'],
361      'include_dirs': [
362        'source/config/<(OS_CATEGORY)/<(target_arch_full)',
363        'source/config',
364        '<(libvpx_source)',
365      ],
366      'sources': [
367        '<(libvpx_source)/build/make/obj_int_extract.c',
368      ],
369      'conditions': [
370        ['android_webview_build==1', {
371          'defines': [ 'FORCE_PARSE_ELF' ],
372          'include_dirs': [ 'include' ],
373        }],
374      ],
375    },
376    {
377      # A library that contains assembly offsets needed.
378      'target_name': 'libvpx_asm_offsets_vp8',
379      'type': 'static_library',
380      'android_unmangled_name': 1,
381      'hard_dependency': 1,
382      'include_dirs': [
383        'source/config/<(OS_CATEGORY)/<(target_arch_full)',
384        'source/config',
385        '<(libvpx_source)',
386      ],
387      'conditions': [
388        ['asan==1', {
389          'cflags!': [ '-fsanitize=address' ],
390          'xcode_settings': { 'OTHER_CFLAGS!': [ '-fsanitize=address' ] },
391          'ldflags!': [ '-fsanitize=address' ],
392        }],
393        ['OS=="win"', {
394          'msvs_settings': {
395            'VCCLCompilerTool': {
396              # Clang uses -fdata-sections when function level linking is
397              # enabled, but libvpx_obj_int_extract expects all data to
398              # reside in the same section on Windows.
399              'EnableFunctionLevelLinking': 'false',
400            },
401          },
402        }],
403      ],
404      'sources': [
405        '<(libvpx_source)/vp8/encoder/vp8_asm_enc_offsets.c',
406      ],
407    },
408    {
409      # A library that contains assembly offsets needed.
410      # TODO(fgalligan): Merge libvpx_asm_offsets_vpx_scale into
411      # libvpx_asm_offsets.
412      'target_name': 'libvpx_asm_offsets_vpx_scale',
413      'type': 'static_library',
414      'android_unmangled_name': 1,
415      'hard_dependency': 1,
416      'include_dirs': [
417        'source/config/<(OS_CATEGORY)/<(target_arch_full)',
418        'source/config',
419        '<(libvpx_source)',
420      ],
421      'conditions': [
422        ['asan==1', {
423          'cflags!': [ '-faddress-sanitizer', '-fsanitize=address', ],
424          'xcode_settings': {
425            'OTHER_CFLAGS!': [ '-faddress-sanitizer','-fsanitize=address' ],
426          },
427          'ldflags!': [ '-faddress-sanitizer', '-fsanitize=address', ],
428        }],
429      ],
430      'sources': [
431        '<(libvpx_source)/vpx_scale/vpx_scale_asm_offsets.c',
432      ],
433    },
434    {
435      # A target that takes assembly offsets library and generate the
436      # corresponding assembly files.
437      # This target is a hard dependency because the generated .asm files
438      # are needed all assembly optimized files in libvpx.
439      'target_name': 'gen_asm_offsets_vp8',
440      'type': 'none',
441      'hard_dependency': 1,
442      'dependencies': [
443        'libvpx_asm_offsets_vp8',
444        'libvpx_obj_int_extract#host',
445      ],
446      'variables' : {
447        'lib_intermediate_name' : '',
448        'output_format':'',
449        'output_dir': '<(shared_generated_dir)',
450        'conditions' : [
451          ['android_webview_build==1', {
452            # pass the empty string for 3rd and 4th arguments of
453            # intermediates-dir-for macro.
454            'lib_intermediate_name' : '$(abspath $(call intermediates-dir-for,STATIC_LIBRARIES,libvpx_asm_offsets_vp8,,,$(gyp_var_prefix)))/libvpx_asm_offsets_vp8.a',
455          }],
456          ['(target_arch=="arm" or target_arch=="armv7")', {
457            'output_format': 'gas',
458          }, {
459            'output_format': 'rvds',
460          }],
461        ],
462      },
463      'conditions': [
464        ['OS=="win"', {
465          'variables': {
466            'ninja_obj_dir': '<(PRODUCT_DIR)/obj/third_party/libvpx/<(libvpx_source)/vp8',
467          },
468          'actions': [
469            {
470              'action_name': 'copy_enc_offsets_obj',
471              'inputs': [ 'copy_obj.py' ],
472              'outputs': [ '<(INTERMEDIATE_DIR)/vp8_asm_enc_offsets.obj' ],
473              'action': [
474                'python',
475                '<(DEPTH)/third_party/libvpx/copy_obj.py',
476                '-d', '<@(_outputs)',
477                '-s', '<(PRODUCT_DIR)/obj/libvpx_asm_offsets_vp8/vp8_asm_enc_offsets.obj',
478                '-s', '<(ninja_obj_dir)/encoder/libvpx_asm_offsets_vp8.vp8_asm_enc_offsets.obj',
479                '-s', '<(PRODUCT_DIR)/obj/Source/WebKit/chromium/third_party/libvpx/<(libvpx_source)/vp8/encoder/libvpx_asm_offsets_vp8.vp8_asm_enc_offsets.obj',
480              ],
481              'process_outputs_as_sources': 1,
482            },
483          ],
484          'sources': [
485            '<(INTERMEDIATE_DIR)/vp8_asm_enc_offsets.obj',
486          ],
487        }, {
488          'variables': {
489            'unpack_lib_search_path_list': [
490              '-a', '<(PRODUCT_DIR)/libvpx_asm_offsets_vp8.a',
491              '-a', '<(LIB_DIR)/third_party/libvpx/libvpx_asm_offsets_vp8.a',
492              '-a', '<(LIB_DIR)/chromium/src/third_party/libvpx/libvpx_asm_offsets_vp8.a',
493              '-a', '<(LIB_DIR)/Source/WebKit/chromium/third_party/libvpx/libvpx_asm_offsets_vp8.a',
494              '-a', '<(lib_intermediate_name)',
495            ],
496            'unpack_lib_output_dir':'<(INTERMEDIATE_DIR)',
497            'unpack_lib_name':'vp8_asm_enc_offsets.o'
498          },
499          'includes': ['unpack_lib_posix.gypi'],
500          # Need this otherwise gyp won't run the rule on them.
501          'sources': [
502            '<(INTERMEDIATE_DIR)/vp8_asm_enc_offsets.o',
503          ],
504        }],
505      ],
506      'includes': ['obj_int_extract.gypi'],
507    },
508    {
509      # A target that takes assembly offsets library and generate the
510      # corresponding assembly files.
511      # This target is a hard dependency because the generated .asm files
512      # are needed all assembly optimized files in libvpx.
513      'target_name': 'gen_asm_offsets_vpx_scale',
514      'type': 'none',
515      'hard_dependency': 1,
516      'dependencies': [
517        'libvpx_asm_offsets_vpx_scale',
518        'libvpx_obj_int_extract#host',
519      ],
520      'variables' : {
521        'lib_intermediate_name' : '',
522        'output_format':'',
523        'output_dir': '<(shared_generated_dir)',
524        'conditions' : [
525          ['android_webview_build==1', {
526            # pass the empty string for 3rd and 4th arguments of
527            # intermediates-dir-for macro.
528            'lib_intermediate_name' : '$(abspath $(call intermediates-dir-for,STATIC_LIBRARIES,libvpx_asm_offsets_vpx_scale,,,$(gyp_var_prefix)))/libvpx_asm_offsets_vpx_scale.a',
529          }],
530          ['(target_arch=="arm" or target_arch=="armv7")', {
531            'output_format': 'gas',
532          }, {
533            'output_format': 'rvds',
534          }],
535        ],
536      },
537      'conditions': [
538        ['OS=="win"', {
539          'variables': {
540            'ninja_obj_dir': '<(PRODUCT_DIR)/obj/third_party/libvpx/<(libvpx_source)/vpx_scale',
541          },
542          'actions': [
543            {
544              'action_name': 'copy_enc_offsets_obj',
545              'inputs': [ 'copy_obj.py' ],
546              'outputs': [ '<(INTERMEDIATE_DIR)/vpx_scale_asm_offsets.obj' ],
547              'action': [
548                'python',
549                '<(DEPTH)/third_party/libvpx/copy_obj.py',
550                '-d', '<@(_outputs)',
551                '-s', '<(PRODUCT_DIR)/obj/libvpx_asm_offsets_vpx_scale/vpx_scale_asm_offsets.obj',
552                '-s', '<(ninja_obj_dir)/encoder/libvpx_asm_offsets_vpx_scale.vpx_scale_asm_offsets.obj',
553                '-s', '<(PRODUCT_DIR)/obj/Source/WebKit/chromium/third_party/libvpx/<(libvpx_source)/vpx_scale/libvpx_asm_offsets_vpx_scale.vpx_scale_asm_offsets.obj',
554              ],
555              'process_outputs_as_sources': 1,
556            },
557          ],
558          'sources': [
559            '<(INTERMEDIATE_DIR)/vpx_scale_asm_offsets.obj',
560          ],
561        }, {
562          'variables': {
563            'unpack_lib_search_path_list': [
564              '-a', '<(PRODUCT_DIR)/libvpx_asm_offsets_vpx_scale.a',
565              '-a', '<(LIB_DIR)/third_party/libvpx/libvpx_asm_offsets_vpx_scale.a',
566              '-a', '<(LIB_DIR)/chromium/src/third_party/libvpx/libvpx_asm_offsets_vpx_scale.a',
567              '-a', '<(LIB_DIR)/Source/WebKit/chromium/third_party/libvpx/libvpx_asm_offsets_vpx_scale.a',
568              '-a', '<(lib_intermediate_name)',
569            ],
570            'unpack_lib_output_dir':'<(INTERMEDIATE_DIR)',
571            'unpack_lib_name':'vpx_scale_asm_offsets.o'
572          },
573          'includes': ['unpack_lib_posix.gypi'],
574         # Need this otherwise gyp won't run the rule on them.
575          'sources': [
576            '<(INTERMEDIATE_DIR)/vpx_scale_asm_offsets.o',
577          ],
578        }],
579      ],
580      'includes': ['obj_int_extract.gypi'],
581    },
582  ],
583}
584