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 # $3 - Path of vpx_config.c under $LIBVPX_CONFIG_DIR
73 function convert_srcs_to_project_files
{
74 # Do the following here:
75 # 1. Filter .c, .h, .s, .S and .asm files.
76 # 3. Convert .asm.s to .asm because moz.build will do the conversion.
78 local source_list
=$
(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1)
80 # Adjust the path for vpx_config.c while maintaining list order:
81 # Since the config file resides in $BASE_DIR/$LIBVPX_CONFIG_DIR, while the
82 # files in $source_list are placed under $BASE_DIR/libvpx (see write_sources),
83 # the config file path requires adjustment. To ensure the list remains sorted,
84 # we must first remove it and then insert it at the beginning of the list.
87 source_list
=$
(echo "$source_list" |
grep -v 'vpx_config\.c')
88 # Insert vpx_config.c at the beginning of the list.
89 local config
=$
(echo "../$LIBVPX_CONFIG_DIR/$3/vpx_config.c")
90 source_list
=$
(echo "$config" ; echo "$source_list")
92 # Remove include-only asm files (no object code emitted)
93 source_list
=$
(echo "$source_list" |
grep -v 'x86_abi_support\.asm')
94 source_list
=$
(echo "$source_list" |
grep -v 'config\.asm')
96 # The actual ARM files end in .asm. We have rules to translate them to .S
97 source_list
=$
(echo "$source_list" |
sed s
/\.asm\.s$
/.asm
/)
99 # Exports - everything in vpx, vpx_mem, vpx_ports, vpx_scale
100 local exports_list
=$
(echo "$source_list" | \
101 egrep '^(vpx|vpx_mem|vpx_ports|vpx_scale)/.*h$')
102 # but not anything in one level down, like 'internal'
103 exports_list
=$
(echo "$exports_list" |
egrep -v '/(internal|src)/')
104 # or any of the other internal-ish header files.
105 exports_list
=$
(echo "$exports_list" |
egrep -v '/(emmintrin_compat.h|mem_.*|msvc.h|vpx_once.h)$')
107 # Remove these files from the main list.
108 source_list
=$
(comm -23 <(echo "$source_list") <(echo "$exports_list"))
110 # Write a single file that includes all source files for all archs.
111 local c_sources
=$
(echo "$source_list" |
egrep '.(asm|c)$')
112 local exports_sources
=$
(echo "$exports_list" |
egrep '.h$')
114 write_sources exports_sources
${2}_EXPORTS
"$BASE_DIR/sources.mozbuild"
115 write_sources c_sources
${2}_SOURCES
"$BASE_DIR/sources.mozbuild"
118 # Clean files from previous make.
119 function make_clean
{
120 make clean
> /dev
/null
121 rm -f libvpx_srcs.txt
124 # Print the configuration.
125 # $1 - Header file directory.
126 function print_config
{
127 $BASE_DIR/lint_config.sh
-p \
128 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
129 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
132 # Generate *_rtcd.h files.
133 # $1 - Header file directory.
135 # $3 - Optional - any additional arguments to pass through.
136 function gen_rtcd_header
{
137 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
139 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
140 $BASE_DIR/lint_config.sh
-p \
141 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
142 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
143 -o $BASE_DIR/$TEMP_DIR/libvpx.config
145 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
147 --sym=vp8_rtcd
$DISABLE_AVX $3 \
148 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
149 $BASE_DIR/$LIBVPX_SRC_DIR/vp
8/common
/rtcd_defs.pl \
150 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
152 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
154 --sym=vp9_rtcd
$DISABLE_AVX $3 \
155 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
156 $BASE_DIR/$LIBVPX_SRC_DIR/vp
9/common
/vp9_rtcd_defs.pl \
157 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
159 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
161 --sym=vpx_scale_rtcd
$DISABLE_AVX $3 \
162 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
163 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale
/vpx_scale_rtcd.pl \
164 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
166 $BASE_DIR/$LIBVPX_SRC_DIR/build
/make
/rtcd.pl \
168 --sym=vpx_dsp_rtcd
$DISABLE_AVX $3 \
169 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
170 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp
/vpx_dsp_rtcd_defs.pl \
171 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
173 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
176 # Generate Config files. "--enable-external-build" must be set to skip
177 # detection of capabilities on specific targets.
178 # $1 - Header file directory.
179 # $2 - Config command line.
180 function gen_config_files
{
181 .
/configure
$2 --log=$BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log
> /dev
/null
182 echo "Log file: $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log"
184 # Disable HAVE_UNISTD_H.
185 ( echo '/HAVE_UNISTD_H'; echo 'd' ; echo 'w' ; echo 'q' ) | ed
-s vpx_config.h
187 local ASM_CONV
=ads2gas.pl
189 # Generate vpx_config.asm.
190 if [[ "$1" == *x64
* ]] ||
[[ "$1" == *ia32
* ]]; then
191 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h |
awk '{print "%define " $2 " " $3}' > vpx_config.asm
193 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
196 cp vpx_config.
* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
203 echo "Create temporary directory."
204 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
206 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
209 echo "Generate config files."
210 all_platforms
="--enable-external-build --disable-examples --disable-install-docs --disable-unit-tests"
211 all_platforms
="${all_platforms} --enable-multi-res-encoding --size-limit=8192x4608 --enable-pic"
212 all_platforms
="${all_platforms} --disable-avx512"
213 x86_platforms
="--enable-postproc --enable-vp9-postproc --as=yasm"
214 arm_platforms
="--enable-runtime-cpu-detect --enable-realtime-only"
215 arm64_platforms
="--enable-realtime-only"
216 disable_sve
="--disable-sve" # Bug 1885585, Bug 1889813
218 gen_config_files linux
/x64
"--target=x86_64-linux-gcc ${all_platforms} ${x86_platforms}"
219 gen_config_files linux
/ia32
"--target=x86-linux-gcc ${all_platforms} ${x86_platforms}"
220 gen_config_files mac
/x64
"--target=x86_64-darwin9-gcc ${all_platforms} ${x86_platforms}"
221 gen_config_files mac
/ia32
"--target=x86-darwin9-gcc ${all_platforms} ${x86_platforms}"
222 gen_config_files win
/x64
"--target=x86_64-win64-vs15 ${all_platforms} ${x86_platforms}"
223 gen_config_files win
/ia32
"--target=x86-win32-gcc ${all_platforms} ${x86_platforms}"
225 gen_config_files linux
/arm
"--target=armv7-linux-gcc ${all_platforms} ${arm_platforms}"
226 gen_config_files linux
/arm64
"--target=arm64-linux-gcc ${all_platforms} ${arm64_platforms} ${disable_sve}" # Bug 1889813
227 gen_config_files win
/aarch64
"--target=arm64-win64-vs15 ${all_platforms} ${arm64_platforms} ${disable_sve}" # Bug 1885585
229 gen_config_files generic
"--target=generic-gnu ${all_platforms}"
231 echo "Remove temporary directory."
235 echo "Create temporary directory."
236 TEMP_DIR
="$LIBVPX_SRC_DIR.temp"
238 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
241 gen_rtcd_header linux
/x64 x86_64
242 gen_rtcd_header linux
/ia32 x86
243 gen_rtcd_header mac
/x64 x86_64
244 gen_rtcd_header mac
/ia32 x86
245 gen_rtcd_header win
/x64 x86_64
246 gen_rtcd_header win
/ia32 x86
248 gen_rtcd_header linux
/arm armv7
249 gen_rtcd_header linux
/arm64 arm64
$disable_sve # Bug 1889813
250 gen_rtcd_header win
/aarch64 arm64
$disable_sve # Bug 1885585
252 gen_rtcd_header generic generic
254 echo "Prepare Makefile."
255 .
/configure
--target=generic-gnu
> /dev
/null
258 # Remove existing source files.
259 rm -rf $BASE_DIR/sources.mozbuild
260 write_license
$BASE_DIR/sources.mozbuild
261 echo "files = {" >> $BASE_DIR/sources.mozbuild
263 echo "Generate X86_64 source list on Linux."
264 config
=$
(print_config linux
/x64
)
266 make libvpx_srcs.txt target
=libs
$config > /dev
/null
267 convert_srcs_to_project_files libvpx_srcs.txt LINUX_X64 linux
/x64
269 echo "Generate X86_64 source list on Mac."
270 config
=$
(print_config mac
/x64
)
272 make libvpx_srcs.txt target
=libs
$config > /dev
/null
273 convert_srcs_to_project_files libvpx_srcs.txt MAC_X64 mac
/x64
275 echo "Generate X86_64 source list on Windows."
276 config
=$
(print_config win
/x64
)
278 make libvpx_srcs.txt target
=libs
$config > /dev
/null
279 convert_srcs_to_project_files libvpx_srcs.txt WIN_X64 win
/x64
281 # Copy vpx_version.h once. The file is the same for all platforms.
282 cp vpx_version.h
$BASE_DIR/$LIBVPX_CONFIG_DIR
284 echo "Generate IA32 source list on Linux."
285 config
=$
(print_config linux
/ia32
)
287 make libvpx_srcs.txt target
=libs
$config > /dev
/null
288 convert_srcs_to_project_files libvpx_srcs.txt LINUX_IA32 linux
/ia32
290 echo "Generate IA32 source list on Mac."
291 config
=$
(print_config mac
/ia32
)
293 make libvpx_srcs.txt target
=libs
$config > /dev
/null
294 convert_srcs_to_project_files libvpx_srcs.txt MAC_IA32 mac
/ia32
296 echo "Generate IA32 source list on Windows."
297 config
=$
(print_config win
/ia32
)
299 make libvpx_srcs.txt target
=libs
$config > /dev
/null
300 convert_srcs_to_project_files libvpx_srcs.txt WIN_IA32 win
/ia32
302 echo "Generate ARM source list on Linux."
303 config
=$
(print_config linux
/arm
)
305 make libvpx_srcs.txt target
=libs
$config > /dev
/null
306 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM linux
/arm
308 echo "Generate ARM64 source list on Linux"
309 config
=$
(print_config linux
/arm64
)
311 make libvpx_srcs.txt target
=libs
$config > /dev
/null
312 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM64 linux
/arm64
314 echo "Generate AARCH64 source list on Windows."
315 config
=$
(print_config win
/aarch64
)
317 make libvpx_srcs.txt target
=libs
$config > /dev
/null
318 convert_srcs_to_project_files libvpx_srcs.txt WIN_AARCH64 win
/aarch64
320 echo "Generate generic source list."
321 config
=$
(print_config generic
)
323 make libvpx_srcs.txt target
=libs
$config > /dev
/null
324 convert_srcs_to_project_files libvpx_srcs.txt GENERIC generic
326 echo "}" >> $BASE_DIR/sources.mozbuild
328 echo "Remove temporary directory."
332 cd $BASE_DIR/$LIBVPX_SRC_DIR