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 # Modified from chromium/src/third_party/libvpx/generate_gni.sh
9 # This script is used to generate sources.mozbuild and files in the
10 # config/platform directories needed to build libvpx.
11 # Every time libvpx source code is updated just run this script.
14 # $ ./generate_sources_mozbuild.sh
18 LIBVPX_SRC_DIR
="libvpx"
19 LIBVPX_CONFIG_DIR
="config"
20 DISABLE_AVX
="--disable-avx512"
22 # Print license header.
23 # $1 - Output base name
24 function write_license
{
25 echo "# This file is generated. Do not edit." >> $1
29 # Search for source files with the same basename in vp8, vp9, and vpx_dsp. The
30 # build does not support duplicate file names.
31 function find_duplicates
{
32 local readonly duplicate_file_names
=$
(find \
33 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
34 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
35 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
36 -type f
-name \
*.c |
xargs -I {} basename {} |
sort |
uniq -d \
39 if [ -n "${duplicate_file_names}" ]; then
40 echo "ERROR: DUPLICATE FILES FOUND"
41 for file in ${duplicate_file_names}; do
43 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
44 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
45 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
52 # Generate sources.mozbuild with a list of source files.
53 # $1 - Array name for file list. This is processed with 'declare' below to
54 # regenerate the array locally.
57 function write_sources
{
58 # Convert the first argument back in to an array.
59 declare -a file_list
=("${!1}")
61 echo " '$2': [" >> "$3"
64 echo " 'libvpx/$f'," >> "$3"
69 # Convert a list of source files into sources.mozbuild.
72 function convert_srcs_to_project_files
{
73 # Do the following here:
74 # 1. Filter .c, .h, .s, .S and .asm files.
75 # 3. Convert .asm.s to .asm because moz.build will do the conversion.
77 local source_list
=$
(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1)
79 # Remove vpx_config.c.
80 # The platform-specific vpx_config.c will be added into in moz.build later.
81 source_list
=$
(echo "$source_list" |
grep -v 'vpx_config\.c')
83 # Remove include-only asm files (no object code emitted)
84 source_list
=$
(echo "$source_list" |
grep -v 'x86_abi_support\.asm')
85 source_list
=$
(echo "$source_list" |
grep -v 'config\.asm')
87 # The actual ARM files end in .asm. We have rules to translate them to .S
88 source_list
=$
(echo "$source_list" |
sed s
/\.asm\.s$
/.asm
/)
90 # Exports - everything in vpx, vpx_mem, vpx_ports, vpx_scale
91 local exports_list
=$
(echo "$source_list" | \
92 egrep '^(vpx|vpx_mem|vpx_ports|vpx_scale)/.*h$')
93 # but not anything in one level down, like 'internal'
94 exports_list
=$
(echo "$exports_list" |
egrep -v '/(internal|src)/')
95 # or any of the other internal-ish header files.
96 exports_list
=$
(echo "$exports_list" |
egrep -v '/(emmintrin_compat.h|mem_.*|msvc.h|vpx_once.h)$')
98 # Remove these files from the main list.
99 source_list
=$
(comm -23 <(echo "$source_list") <(echo "$exports_list"))
101 # Write a single file that includes all source files for all archs.
102 local c_sources
=$
(echo "$source_list" |
egrep '.(asm|c)$')
103 local exports_sources
=$
(echo "$exports_list" |
egrep '.h$')
105 write_sources exports_sources
${2}_EXPORTS
"$BASE_DIR/sources.mozbuild"
106 write_sources c_sources
${2}_SOURCES
"$BASE_DIR/sources.mozbuild"
109 # Clean files from previous make.
110 function make_clean
{
111 make clean
> /dev
/null
112 rm -f libvpx_srcs.txt
115 # Print the configuration.
116 # $1 - Header file directory.
117 function print_config
{
118 $BASE_DIR/lint_config.sh
-p \
119 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
120 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
123 # Generate *_rtcd.h files.
124 # $1 - Header file directory.
126 # $3 - Optional - any additional arguments to pass through.
127 function gen_rtcd_header
{
128 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
130 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
131 $BASE_DIR/lint_config.sh
-p \
132 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
133 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
134 -o $BASE_DIR/$TEMP_DIR/libvpx.config
136 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
138 --sym=vp8_rtcd
$DISABLE_AVX $3 \
139 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
140 $BASE_DIR/$LIBVPX_SRC_DIR/vp
8/common
/rtcd_defs.pl \
141 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
143 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
145 --sym=vp9_rtcd
$DISABLE_AVX $3 \
146 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
147 $BASE_DIR/$LIBVPX_SRC_DIR/vp
9/common
/vp9_rtcd_defs.pl \
148 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
150 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
152 --sym=vpx_scale_rtcd
$DISABLE_AVX $3 \
153 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
154 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale
/vpx_scale_rtcd.pl \
155 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
157 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
159 --sym=vpx_dsp_rtcd
$DISABLE_AVX $3 \
160 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
161 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp
/vpx_dsp_rtcd_defs.pl \
162 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
164 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
167 # Generate Config files. "--enable-external-build" must be set to skip
168 # detection of capabilities on specific targets.
169 # $1 - Header file directory.
170 # $2 - Config command line.
171 function gen_config_files
{
172 .
/configure
$2 > /dev
/null
174 # Disable HAVE_UNISTD_H.
175 ( echo '/HAVE_UNISTD_H'; echo 'd' ; echo 'w' ; echo 'q' ) | ed
-s vpx_config.h
177 local ASM_CONV
=ads2gas.pl
179 # Generate vpx_config.asm.
180 if [[ "$1" == *x64
* ]] ||
[[ "$1" == *ia32
* ]]; then
181 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h |
awk '{print "%define " $2 " " $3}' > vpx_config.asm
183 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h |
awk '{print $2 " EQU " $3}' | perl
$BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/$ASM_CONV > vpx_config.asm
186 cp vpx_config.
* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
193 echo "Create temporary directory."
194 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
196 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
199 echo "Generate config files."
200 all_platforms
="--enable-external-build --disable-examples --disable-install-docs --disable-unit-tests"
201 all_platforms
="${all_platforms} --enable-multi-res-encoding --size-limit=8192x4608 --enable-pic"
202 all_platforms
="${all_platforms} --disable-avx512"
203 x86_platforms
="--enable-postproc --enable-vp9-postproc --as=yasm"
204 arm_platforms
="--enable-runtime-cpu-detect --enable-realtime-only"
205 arm64_platforms
="--enable-realtime-only"
207 gen_config_files linux
/x64
"--target=x86_64-linux-gcc ${all_platforms} ${x86_platforms}"
208 gen_config_files linux
/ia32
"--target=x86-linux-gcc ${all_platforms} ${x86_platforms}"
209 gen_config_files mac
/x64
"--target=x86_64-darwin9-gcc ${all_platforms} ${x86_platforms}"
210 gen_config_files mac
/ia32
"--target=x86-darwin9-gcc ${all_platforms} ${x86_platforms}"
211 gen_config_files win
/x64
"--target=x86_64-win64-vs15 ${all_platforms} ${x86_platforms}"
212 gen_config_files win
/ia32
"--target=x86-win32-gcc ${all_platforms} ${x86_platforms}"
214 gen_config_files linux
/arm
"--target=armv7-linux-gcc ${all_platforms} ${arm_platforms}"
215 gen_config_files linux
/arm64
"--target=arm64-linux-gcc ${all_platforms} ${arm64_platforms}"
216 gen_config_files win
/aarch64
"--target=arm64-win64-vs15 ${all_platforms} ${arm64_platforms}"
218 gen_config_files generic
"--target=generic-gnu ${all_platforms}"
220 echo "Remove temporary directory."
224 echo "Create temporary directory."
225 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
227 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
230 gen_rtcd_header linux
/x64 x86_64
231 gen_rtcd_header linux
/ia32 x86
232 gen_rtcd_header mac
/x64 x86_64
233 gen_rtcd_header mac
/ia32 x86
234 gen_rtcd_header win
/x64 x86_64
235 gen_rtcd_header win
/ia32 x86
237 gen_rtcd_header linux
/arm armv7
238 gen_rtcd_header linux
/arm64 arm64
239 gen_rtcd_header win
/aarch64 arm64
241 gen_rtcd_header generic generic
243 echo "Prepare Makefile."
244 .
/configure
--target=generic-gnu
> /dev
/null
247 # Remove existing source files.
248 rm -rf $BASE_DIR/sources.mozbuild
249 write_license
$BASE_DIR/sources.mozbuild
250 echo "files = {" >> $BASE_DIR/sources.mozbuild
252 echo "Generate X86_64 source list."
253 config
=$
(print_config linux
/x64
)
255 make libvpx_srcs.txt target
=libs
$config > /dev
/null
256 convert_srcs_to_project_files libvpx_srcs.txt X64
258 # Copy vpx_version.h once. The file is the same for all platforms.
259 cp vpx_version.h
$BASE_DIR/$LIBVPX_CONFIG_DIR
261 echo "Generate IA32 source list."
262 config
=$
(print_config linux
/ia32
)
264 make libvpx_srcs.txt target
=libs
$config > /dev
/null
265 convert_srcs_to_project_files libvpx_srcs.txt IA32
267 echo "Generate ARM source list."
268 config
=$
(print_config linux
/arm
)
270 make libvpx_srcs.txt target
=libs
$config > /dev
/null
271 convert_srcs_to_project_files libvpx_srcs.txt ARM
273 echo "Generate ARM64 source list."
274 config
=$
(print_config linux
/arm64
)
276 make libvpx_srcs.txt target
=libs
$config > /dev
/null
277 convert_srcs_to_project_files libvpx_srcs.txt ARM64
279 echo "Generate generic source list."
280 config
=$
(print_config generic
)
282 make libvpx_srcs.txt target
=libs
$config > /dev
/null
283 convert_srcs_to_project_files libvpx_srcs.txt GENERIC
285 echo "}" >> $BASE_DIR/sources.mozbuild
287 echo "Remove temporary directory."
291 cd $BASE_DIR/$LIBVPX_SRC_DIR