3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script is used to generate .gypi, .gni files and files in the
8 # config/platform directories needed to build libvpx.
9 # Every time libvpx source code is updated just run this script.
12 # $ ./generate_gypi.sh [--disable-avx] [--only-configs]
14 # The following optional flags are supported:
15 # --disable-avx : AVX+AVX2 support is disabled.
16 # --only-configs: Excludes generation of GN and GYP files (i.e. only
17 # configuration headers are generated).
19 # !!! It's highly recommended to install yasm before running this script.
23 LIBVPX_SRC_DIR
="source/libvpx"
24 LIBVPX_CONFIG_DIR
="source/config"
31 DISABLE_AVX
="--disable-avx --disable-avx2"
39 echo "Unknown option: $i"
45 # Print license header.
46 # $1 - Output base name
47 function write_license
{
48 echo "# This file is generated. Do not edit." >> $1
49 echo "# Copyright (c) 2014 The Chromium Authors. All rights reserved." >> $1
50 echo "# Use of this source code is governed by a BSD-style license that can be" >> $1
51 echo "# found in the LICENSE file." >> $1
55 # Print gypi boilerplate header.
56 # $1 - Output base name
57 function write_gypi_header
{
61 # Print gypi boilerplate footer.
62 # $1 - Output base name
63 function write_gypi_footer
{
67 # Generate a gypi with a list of source files.
68 # $1 - Array name for file list. This is processed with 'declare' below to
69 # regenerate the array locally.
72 # Convert the first argument back in to an array.
73 local readonly file_list
=(${!1})
77 write_gypi_header
"$2"
79 echo " 'sources': [" >> "$2"
80 for f
in ${file_list[@]}
82 echo " '<(libvpx_source)/$f'," >> "$2"
86 write_gypi_footer
"$2"
89 # Generate a gni with a list of source files.
90 # $1 - Array name for file list. This is processed with 'declare' below to
91 # regenerate the array locally.
92 # $2 - GN variable name.
95 # Convert the first argument back in to an array.
96 declare -a file_list
=("${!1}")
101 echo " \"//third_party/libvpx_new/source/libvpx/$f\"," >> "$3"
106 # Target template function
107 # $1 - Array name for file list.
111 function write_target_definition
{
112 declare -a sources_list
=("${!1}")
115 echo " 'target_name': '$3'," >> "$2"
116 echo " 'type': 'static_library'," >> "$2"
117 echo " 'include_dirs': [" >> "$2"
118 echo " 'source/config/<(OS_CATEGORY)/<(target_arch_full)'," >> "$2"
119 echo " '<(libvpx_source)'," >> "$2"
121 echo " 'sources': [" >> "$2"
122 for f
in $sources_list
124 echo " '<(libvpx_source)/$f'," >> $2
127 if [[ $4 == fpu
=neon
]]; then
128 echo " 'includes': [ 'ads2gas.gypi' ]," >> "$2"
129 echo " 'cflags!': [ '-mfpu=vfpv3-d16' ]," >> "$2"
130 echo " 'conditions': [" >> $2
131 echo " # Disable GCC LTO in neon targets due to compiler bug" >> "$2"
132 echo " # crbug.com/408997" >> "$2"
133 echo " ['clang==0 and use_lto==1', {" >> "$2"
134 echo " 'cflags!': [" >> "$2"
135 echo " '-flto'," >> "$2"
136 echo " '-ffat-lto-objects'," >> "$2"
141 echo " 'cflags': [ '-m$4', ]," >> "$2"
142 echo " 'xcode_settings': { 'OTHER_CFLAGS': [ '-m$4' ] }," >> "$2"
143 if [[ -z $DISABLE_AVX && $4 == avx2
]]; then
144 echo " 'msvs_settings': {" >> "$2"
145 echo " 'VCCLCompilerTool': {" >> "$2"
146 echo " 'EnableEnhancedInstructionSet': '5', # /arch:AVX2" >> "$2"
149 elif [[ $4 == ssse3 ||
$4 == sse4.1
]]; then
150 echo " 'conditions': [" >> "$2"
151 echo " ['OS==\"win\" and clang==1', {" >> "$2"
152 echo " # cl.exe's /arch flag doesn't have a setting for SSSE3/4, and cl.exe" >> "$2"
153 echo " # doesn't need it for intrinsics. clang-cl does need it, though." >> "$2"
154 echo " 'msvs_settings': {" >> "$2"
155 echo " 'VCCLCompilerTool': { 'AdditionalOptions': [ '-m$4' ] }," >> "$2"
164 # Generate a gypi which applies additional compiler flags based on the file
166 # $1 - Array name for file list.
168 function write_intrinsics_gypi
{
169 declare -a file_list
=("${!1}")
171 local mmx_sources
=$
(echo "$file_list" |
grep '_mmx\.c$')
172 local sse2_sources
=$
(echo "$file_list" |
grep '_sse2\.c$')
173 local sse3_sources
=$
(echo "$file_list" |
grep '_sse3\.c$')
174 local ssse3_sources
=$
(echo "$file_list" |
grep '_ssse3\.c$')
175 local sse4_1_sources
=$
(echo "$file_list" |
grep '_sse4\.c$')
176 local avx_sources
=$
(echo "$file_list" |
grep '_avx\.c$')
177 local avx2_sources
=$
(echo "$file_list" |
grep '_avx2\.c$')
178 local neon_sources
=$
(echo "$file_list" |
grep '_neon\.c$\|\.asm$')
180 # Intrinsic functions and files are in flux. We can selectively generate them
181 # but we can not selectively include them in libvpx.gyp. Throw some errors
182 # when new targets are needed.
186 write_gypi_header
"$2"
188 echo " 'targets': [" >> "$2"
191 if [ 0 -ne ${#mmx_sources} ]; then
192 write_target_definition mmx_sources
[@
] "$2" libvpx_intrinsics_mmx mmx
194 if [ 0 -ne ${#sse2_sources} ]; then
195 write_target_definition sse2_sources
[@
] "$2" libvpx_intrinsics_sse2 sse2
197 if [ 0 -ne ${#sse3_sources} ]; then
198 #write_target_definition sse3_sources[@] "$2" libvpx_intrinsics_sse3 sse3
199 echo "ERROR: Uncomment sse3 sections in libvpx.gyp"
202 if [ 0 -ne ${#ssse3_sources} ]; then
203 write_target_definition ssse3_sources
[@
] "$2" libvpx_intrinsics_ssse3 ssse3
205 if [ 0 -ne ${#sse4_1_sources} ]; then
206 write_target_definition sse4_1_sources
[@
] "$2" libvpx_intrinsics_sse4_1 sse4.1
208 if [[ -z $DISABLE_AVX && 0 -ne ${#avx_sources} ]]; then
209 #write_target_definition avx_sources[@] "$2" libvpx_intrinsics_avx avx
210 echo "ERROR: Uncomment avx sections in libvpx.gyp"
213 if [[ -z $DISABLE_AVX && 0 -ne ${#avx2_sources} ]]; then
214 write_target_definition avx2_sources
[@
] "$2" libvpx_intrinsics_avx2 avx2
218 if [ 0 -ne ${#neon_sources} ]; then
219 write_target_definition neon_sources
[@
] "$2" libvpx_intrinsics_neon fpu
=neon
224 write_gypi_footer
"$2"
227 # Convert a list of source files into gypi and gni files.
229 # $2 - Output gypi file base. Will generate additional .gypi files when
230 # different compilation flags are required.
231 function convert_srcs_to_project_files
{
232 # Do the following here:
233 # 1. Filter .c, .h, .s, .S and .asm files.
234 # 2. Move certain files to a separate include to allow applying different
236 # 3. Replace .asm.s to .asm because gyp will do the conversion.
238 local source_list
=$
(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1)
240 # Not sure why vpx_config is not included.
241 source_list
=$
(echo "$source_list" |
grep -v 'vpx_config\.c')
243 # The actual ARM files end in .asm. We have rules to translate them to .S
244 source_list
=$
(echo "$source_list" |
sed s
/\.asm\.s$
/.asm
/)
246 # Select all x86 files ending with .c
247 local intrinsic_list
=$
(echo "$source_list" | \
248 egrep '(mmx|sse2|sse3|ssse3|sse4|avx|avx2).c$')
250 # Select all neon files ending in C but only when building in RTCD mode
251 if [ "libvpx_srcs_arm_neon_cpu_detect" == "$2" ]; then
252 # Select all arm neon files ending in _neon.c and all asm files.
253 # The asm files need to be included in the intrinsics target because
254 # they need the -mfpu=neon flag.
255 # the pattern may need to be updated if vpx_scale gets intrinics
256 local intrinsic_list
=$
(echo "$source_list" | \
257 egrep 'neon.*(\.c|\.asm)$')
260 # Remove these files from the main list.
261 source_list
=$
(comm -23 <(echo "$source_list") <(echo "$intrinsic_list"))
263 local x86_list
=$
(echo "$source_list" |
egrep '/x86/')
265 write_gypi source_list
"$BASE_DIR/$2.gypi"
267 # All the files are in a single "element." Check if the first element has
269 if [ 0 -ne ${#intrinsic_list} ]; then
270 write_intrinsics_gypi intrinsic_list
[@
] "$BASE_DIR/$2_intrinsics.gypi"
273 # Write a single .gni file that includes all source files for all archs.
274 if [ 0 -ne ${#x86_list} ]; then
275 local c_sources
=$
(echo "$source_list" |
egrep '.(c|h)$')
276 local assembly_sources
=$
(echo "$source_list" |
egrep '.asm$')
277 local mmx_sources
=$
(echo "$intrinsic_list" |
grep '_mmx\.c$')
278 local sse2_sources
=$
(echo "$intrinsic_list" |
grep '_sse2\.c$')
279 local sse3_sources
=$
(echo "$intrinsic_list" |
grep '_sse3\.c$')
280 local ssse3_sources
=$
(echo "$intrinsic_list" |
grep '_ssse3\.c$')
281 local sse4_1_sources
=$
(echo "$intrinsic_list" |
grep '_sse4\.c$')
282 local avx_sources
=$
(echo "$intrinsic_list" |
grep '_avx\.c$')
283 local avx2_sources
=$
(echo "$intrinsic_list" |
grep '_avx2\.c$')
285 write_gni c_sources
$2 "$BASE_DIR/libvpx_srcs.gni"
286 write_gni assembly_sources
$2_assembly "$BASE_DIR/libvpx_srcs.gni"
287 write_gni mmx_sources
$2_mmx "$BASE_DIR/libvpx_srcs.gni"
288 write_gni sse2_sources
$2_sse2 "$BASE_DIR/libvpx_srcs.gni"
289 write_gni sse3_sources
$2_sse3 "$BASE_DIR/libvpx_srcs.gni"
290 write_gni ssse3_sources
$2_ssse3 "$BASE_DIR/libvpx_srcs.gni"
291 write_gni sse4_1_sources
$2_sse4_1 "$BASE_DIR/libvpx_srcs.gni"
292 if [ -z "$DISABLE_AVX" ]; then
293 write_gni avx_sources
$2_avx "$BASE_DIR/libvpx_srcs.gni"
294 write_gni avx2_sources
$2_avx2 "$BASE_DIR/libvpx_srcs.gni"
297 local c_sources
=$
(echo "$source_list" |
egrep '.(c|h)$')
298 local assembly_sources
=$
(echo -e "$source_list\n$intrinsic_list" | \
300 local neon_sources
=$
(echo "$intrinsic_list" |
grep '_neon\.c$')
301 write_gni c_sources
$2 "$BASE_DIR/libvpx_srcs.gni"
302 write_gni assembly_sources
$2_assembly "$BASE_DIR/libvpx_srcs.gni"
303 if [ 0 -ne ${#neon_sources} ]; then
304 write_gni neon_sources
$2_neon "$BASE_DIR/libvpx_srcs.gni"
309 # Clean files from previous make.
310 function make_clean
{
311 make clean
> /dev
/null
312 rm -f libvpx_srcs.txt
315 # Lint a pair of vpx_config.h and vpx_config.asm to make sure they match.
316 # $1 - Header file directory.
317 function lint_config
{
318 # mips does not contain any assembly so the header does not need to be
319 # compared to the asm.
320 if [[ "$1" != *mipsel
&& "$1" != *mips64el
]]; then
321 $BASE_DIR/lint_config.sh \
322 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
323 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
327 # Print the configuration.
328 # $1 - Header file directory.
329 function print_config
{
330 $BASE_DIR/lint_config.sh
-p \
331 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
332 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
335 # Print the configuration from Header file.
336 # This function is an abridged version of print_config which does not use
337 # lint_config and it does not require existence of vpx_config.asm.
338 # $1 - Header file directory.
339 function print_config_basic
{
340 combined_config
="$(cat $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
341 | grep -E ' +[01] *$')"
342 combined_config
="$(echo "$combined_config" | grep -v DO1STROUNDING)"
343 combined_config
="$(echo "$combined_config" | sed 's/[ \t]//g')"
344 combined_config
="$(echo "$combined_config" | sed 's/.*define//')"
345 combined_config
="$(echo "$combined_config" | sed 's/0$/=no/')"
346 combined_config
="$(echo "$combined_config" | sed 's/1$/=yes/')"
347 echo "$combined_config" |
sort |
uniq
350 # Generate *_rtcd.h files.
351 # $1 - Header file directory.
353 function gen_rtcd_header
{
354 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
356 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
357 if [[ "$2" == "mipsel" ||
"$2" == "mips64el" ]]; then
358 print_config_basic
$1 > $BASE_DIR/$TEMP_DIR/libvpx.config
360 $BASE_DIR/lint_config.sh
-p \
361 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
362 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
363 -o $BASE_DIR/$TEMP_DIR/libvpx.config
366 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
368 --sym=vp8_rtcd
$DISABLE_AVX \
369 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
370 $BASE_DIR/$LIBVPX_SRC_DIR/vp
8/common
/rtcd_defs.pl \
371 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
373 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
375 --sym=vp9_rtcd
$DISABLE_AVX \
376 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
377 $BASE_DIR/$LIBVPX_SRC_DIR/vp
9/common
/vp9_rtcd_defs.pl \
378 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
380 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
382 --sym=vpx_scale_rtcd
$DISABLE_AVX \
383 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
384 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale
/vpx_scale_rtcd.pl \
385 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
387 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
389 --sym=vpx_dsp_rtcd
$DISABLE_AVX \
390 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
391 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp
/vpx_dsp_rtcd_defs.pl \
392 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
394 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
397 # Generate Config files. "--enable-external-build" must be set to skip
398 # detection of capabilities on specific targets.
399 # $1 - Header file directory.
400 # $2 - Config command line.
401 function gen_config_files
{
402 .
/configure
$2 > /dev
/null
404 # Disable HAVE_UNISTD_H as it causes vp8 to try to detect how many cpus
405 # available, which doesn't work from iniside a sandbox on linux.
406 ( echo '/HAVE_UNISTD_H/s/[01]/0/' ; echo 'w' ; echo 'q' ) | ed
-s vpx_config.h
408 # Generate vpx_config.asm. Do not create one for mips.
409 if [[ "$1" != *mipsel
&& "$1" != *mips64el
]]; then
410 if [[ "$1" == *x64
* ]] ||
[[ "$1" == *ia32
* ]]; then
411 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h |
awk '{print "%define " $2 " " $3}' > vpx_config.asm
413 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h |
awk '{print $2 " EQU " $3}' | perl
$BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/ads2gas.pl
> vpx_config.asm
417 cp vpx_config.
* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
422 echo "Create temporary directory."
423 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
425 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
428 echo "Generate config files."
429 all_platforms
="--enable-external-build --enable-postproc --disable-install-srcs --enable-multi-res-encoding --enable-temporal-denoising --disable-unit-tests --disable-install-docs --disable-examples --enable-vp9-temporal-denoising --enable-vp9-postproc --size-limit=16384x16384 $DISABLE_AVX"
430 gen_config_files linux
/ia32
"--target=x86-linux-gcc --disable-ccache --enable-pic --enable-realtime-only ${all_platforms}"
431 gen_config_files linux
/x64
"--target=x86_64-linux-gcc --disable-ccache --enable-pic --enable-realtime-only ${all_platforms}"
432 gen_config_files linux
/arm
"--target=armv6-linux-gcc --enable-pic --enable-realtime-only --disable-install-bins --disable-install-libs --disable-edsp ${all_platforms}"
433 gen_config_files linux
/arm-neon
"--target=armv7-linux-gcc --enable-pic --enable-realtime-only --disable-edsp ${all_platforms}"
434 gen_config_files linux
/arm-neon-cpu-detect
"--target=armv7-linux-gcc --enable-pic --enable-realtime-only --enable-runtime-cpu-detect --disable-edsp ${all_platforms}"
435 gen_config_files linux
/arm64
"--force-target=armv8-linux-gcc --enable-pic --enable-realtime-only --disable-edsp ${all_platforms}"
436 gen_config_files linux
/mipsel
"--target=mips32-linux-gcc ${all_platforms}"
437 gen_config_files linux
/mips64el
"--target=mips64-linux-gcc ${all_platforms}"
438 gen_config_files linux
/generic
"--target=generic-gnu --enable-pic --enable-realtime-only ${all_platforms}"
439 gen_config_files win
/ia32
"--target=x86-win32-vs12 --enable-realtime-only ${all_platforms}"
440 gen_config_files win
/x64
"--target=x86_64-win64-vs12 --enable-realtime-only ${all_platforms}"
441 gen_config_files mac
/ia32
"--target=x86-darwin9-gcc --enable-pic --enable-realtime-only ${all_platforms}"
442 gen_config_files mac
/x64
"--target=x86_64-darwin9-gcc --enable-pic --enable-realtime-only ${all_platforms}"
443 gen_config_files nacl
"--target=generic-gnu --enable-pic --enable-realtime-only ${all_platforms}"
445 echo "Remove temporary directory."
449 echo "Lint libvpx configuration."
450 lint_config linux
/ia32
451 lint_config linux
/x64
452 lint_config linux
/arm
453 lint_config linux
/arm-neon
454 lint_config linux
/arm-neon-cpu-detect
455 lint_config linux
/arm64
456 lint_config linux
/mipsel
457 lint_config linux
/mips64el
458 lint_config linux
/generic
465 echo "Create temporary directory."
466 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
468 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
471 gen_rtcd_header linux
/ia32 x86
472 gen_rtcd_header linux
/x64 x86_64
473 gen_rtcd_header linux
/arm armv6
474 gen_rtcd_header linux
/arm-neon armv7
475 gen_rtcd_header linux
/arm-neon-cpu-detect armv7
476 gen_rtcd_header linux
/arm64 armv8
477 gen_rtcd_header linux
/mipsel mipsel
478 gen_rtcd_header linux
/mips64el mips64el
479 gen_rtcd_header linux
/generic generic
480 gen_rtcd_header win
/ia32 x86
481 gen_rtcd_header win
/x64 x86_64
482 gen_rtcd_header mac
/ia32 x86
483 gen_rtcd_header mac
/x64 x86_64
484 gen_rtcd_header nacl nacl
486 echo "Prepare Makefile."
487 .
/configure
--target=generic-gnu
> /dev
/null
490 if [ -z $ONLY_CONFIGS ]; then
491 # Remove existing .gni file.
492 rm -rf $BASE_DIR/libvpx_srcs.gni
493 write_license
$BASE_DIR/libvpx_srcs.gni
495 echo "Generate X86 source list."
496 config
=$
(print_config linux
/ia32
)
498 make libvpx_srcs.txt target
=libs
$config > /dev
/null
499 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86
501 # Copy vpx_version.h. The file should be the same for all platforms.
502 cp vpx_version.h
$BASE_DIR/$LIBVPX_CONFIG_DIR
504 echo "Generate X86_64 source list."
505 config
=$
(print_config linux
/x64
)
507 make libvpx_srcs.txt target
=libs
$config > /dev
/null
508 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86_64
510 echo "Generate ARM source list."
511 config
=$
(print_config linux
/arm
)
513 make libvpx_srcs.txt target
=libs
$config > /dev
/null
514 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm
516 echo "Generate ARM NEON source list."
517 config
=$
(print_config linux
/arm-neon
)
519 make libvpx_srcs.txt target
=libs
$config > /dev
/null
520 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon
522 echo "Generate ARM NEON CPU DETECT source list."
523 config
=$
(print_config linux
/arm-neon-cpu-detect
)
525 make libvpx_srcs.txt target
=libs
$config > /dev
/null
526 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon_cpu_detect
528 echo "Generate ARM64 source list."
529 config
=$
(print_config linux
/arm64
)
531 make libvpx_srcs.txt target
=libs
$config > /dev
/null
532 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm64
534 echo "Generate MIPS source list."
535 config
=$
(print_config_basic linux
/mipsel
)
537 make libvpx_srcs.txt target
=libs
$config > /dev
/null
538 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_mips
540 echo "MIPS64 source list is identical to MIPS source list. No need to generate it."
542 echo "Generate NaCl source list."
543 config
=$
(print_config_basic nacl
)
545 make libvpx_srcs.txt target
=libs
$config > /dev
/null
546 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_nacl
548 echo "Generate GENERIC source list."
549 config
=$
(print_config_basic linux
/generic
)
551 make libvpx_srcs.txt target
=libs
$config > /dev
/null
552 convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_generic
555 echo "Remove temporary directory."
559 # TODO(fgalligan): Can we turn on "--enable-realtime-only" for mipsel?