Backed out changeset e396dfbd2f76 (bug 1905712)
[gecko.git] / media / libvpx / generate_sources_mozbuild.sh
blobf84dc75be1709ddcd48eccb7c9bb5a50a02a36a4
1 #!/bin/bash -e
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.
13 # Usage:
14 # $ ./generate_sources_mozbuild.sh
16 export LC_ALL=C
17 BASE_DIR=$(pwd)
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
26 echo "" >> $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
42 find \
43 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
44 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
45 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
46 -name $file
47 done
48 exit 1
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.
55 # $2 - Variable name.
56 # $3 - Output file.
57 function write_sources {
58 # Convert the first argument back in to an array.
59 declare -a file_list=("${!1}")
61 echo " '$2': [" >> "$3"
62 for f in $file_list
64 echo " 'libvpx/$f'," >> "$3"
65 done
66 echo "]," >> "$3"
69 # Convert a list of source files into sources.mozbuild.
70 # $1 - Input file.
71 # $2 - Output prefix.
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.
86 # Remove vpx_config.c
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.
134 # $2 - Architecture.
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 \
146 --arch=$2 \
147 --sym=vp8_rtcd $DISABLE_AVX $3 \
148 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
149 $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
150 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
152 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
153 --arch=$2 \
154 --sym=vp9_rtcd $DISABLE_AVX $3 \
155 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
156 $BASE_DIR/$LIBVPX_SRC_DIR/vp9/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 \
160 --arch=$2 \
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 \
167 --arch=$2 \
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 mkdir -p $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
182 ./configure $2 --log=$BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log > /dev/null
183 echo "Log file: $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log"
185 # Disable HAVE_UNISTD_H.
186 ( echo '/HAVE_UNISTD_H'; echo 'd' ; echo 'w' ; echo 'q' ) | ed -s vpx_config.h
188 local ASM_CONV=ads2gas.pl
190 # Generate vpx_config.asm.
191 if [[ "$1" == *x64* ]] || [[ "$1" == *ia32* ]]; then
192 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h | awk '{print "%define " $2 " " $3}' > vpx_config.asm
193 else
194 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
197 cp vpx_config.* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
198 make_clean
199 rm -rf vpx_config.*
202 find_duplicates
204 echo "Create temporary directory."
205 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
206 rm -rf $TEMP_DIR
207 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
208 cd $TEMP_DIR
210 echo "Generate config files."
211 all_platforms="--enable-external-build --disable-examples --disable-install-docs --disable-unit-tests"
212 all_platforms="${all_platforms} --enable-multi-res-encoding --size-limit=8192x4608 --enable-pic"
213 all_platforms="${all_platforms} --disable-avx512"
214 x86_platforms="--enable-postproc --enable-vp9-postproc --as=yasm"
215 runtime_cpu_detect="--enable-runtime-cpu-detect"
216 realtime_only="--enable-realtime-only"
217 disable_sve="--disable-sve" # Bug 1885585, Bug 1889813
219 gen_config_files linux/x64 "--target=x86_64-linux-gcc ${all_platforms} ${x86_platforms}"
220 gen_config_files linux/ia32 "--target=x86-linux-gcc ${all_platforms} ${x86_platforms}"
221 gen_config_files mac/x64 "--target=x86_64-darwin9-gcc ${all_platforms} ${x86_platforms}"
222 gen_config_files mac/ia32 "--target=x86-darwin9-gcc ${all_platforms} ${x86_platforms}"
223 gen_config_files win/x64 "--target=x86_64-win64-vs15 ${all_platforms} ${x86_platforms}"
224 gen_config_files win/ia32 "--target=x86-win32-gcc ${all_platforms} ${x86_platforms}"
226 gen_config_files linux/arm "--target=armv7-linux-gcc ${all_platforms} ${runtime_cpu_detect} ${realtime_only}"
227 gen_config_files linux/arm64 "--target=arm64-linux-gcc ${all_platforms} ${realtime_only} ${disable_sve}" # Bug 1889813
228 gen_config_files mac/arm64 "--target=arm64-darwin-gcc ${all_platforms}"
229 gen_config_files win/aarch64 "--target=arm64-win64-vs15 ${all_platforms} ${realtime_only} ${disable_sve}" # Bug 1885585
231 gen_config_files generic "--target=generic-gnu ${all_platforms}"
233 echo "Remove temporary directory."
234 cd $BASE_DIR
235 rm -rf $TEMP_DIR
237 echo "Create temporary directory."
238 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
239 rm -rf $TEMP_DIR
240 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
241 cd $TEMP_DIR
243 gen_rtcd_header linux/x64 x86_64
244 gen_rtcd_header linux/ia32 x86
245 gen_rtcd_header mac/x64 x86_64
246 gen_rtcd_header mac/ia32 x86
247 gen_rtcd_header win/x64 x86_64
248 gen_rtcd_header win/ia32 x86
250 gen_rtcd_header linux/arm armv7
251 gen_rtcd_header linux/arm64 arm64 $disable_sve # Bug 1889813
252 gen_rtcd_header mac/arm64 arm64
253 gen_rtcd_header win/aarch64 arm64 $disable_sve # Bug 1885585
255 gen_rtcd_header generic generic
257 echo "Prepare Makefile."
258 ./configure --target=generic-gnu > /dev/null
259 make_clean
261 # Remove existing source files.
262 rm -rf $BASE_DIR/sources.mozbuild
263 write_license $BASE_DIR/sources.mozbuild
264 echo "files = {" >> $BASE_DIR/sources.mozbuild
266 echo "Generate X86_64 source list on Linux."
267 config=$(print_config linux/x64)
268 make_clean
269 make libvpx_srcs.txt target=libs $config > /dev/null
270 convert_srcs_to_project_files libvpx_srcs.txt LINUX_X64 linux/x64
272 echo "Generate X86_64 source list on Mac."
273 config=$(print_config mac/x64)
274 make_clean
275 make libvpx_srcs.txt target=libs $config > /dev/null
276 convert_srcs_to_project_files libvpx_srcs.txt MAC_X64 mac/x64
278 echo "Generate X86_64 source list on Windows."
279 config=$(print_config win/x64)
280 make_clean
281 make libvpx_srcs.txt target=libs $config > /dev/null
282 convert_srcs_to_project_files libvpx_srcs.txt WIN_X64 win/x64
284 # Copy vpx_version.h once. The file is the same for all platforms.
285 cp vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR
287 echo "Generate IA32 source list on Linux."
288 config=$(print_config linux/ia32)
289 make_clean
290 make libvpx_srcs.txt target=libs $config > /dev/null
291 convert_srcs_to_project_files libvpx_srcs.txt LINUX_IA32 linux/ia32
293 echo "Generate IA32 source list on Mac."
294 config=$(print_config mac/ia32)
295 make_clean
296 make libvpx_srcs.txt target=libs $config > /dev/null
297 convert_srcs_to_project_files libvpx_srcs.txt MAC_IA32 mac/ia32
299 echo "Generate IA32 source list on Windows."
300 config=$(print_config win/ia32)
301 make_clean
302 make libvpx_srcs.txt target=libs $config > /dev/null
303 convert_srcs_to_project_files libvpx_srcs.txt WIN_IA32 win/ia32
305 echo "Generate ARM source list on Linux."
306 config=$(print_config linux/arm)
307 make_clean
308 make libvpx_srcs.txt target=libs $config > /dev/null
309 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM linux/arm
311 echo "Generate ARM64 source list on Linux"
312 config=$(print_config linux/arm64)
313 make_clean
314 make libvpx_srcs.txt target=libs $config > /dev/null
315 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM64 linux/arm64
317 echo "Generate ARM64 source list on Mac"
318 config=$(print_config mac/arm64)
319 make_clean
320 make libvpx_srcs.txt target=libs $config > /dev/null
321 convert_srcs_to_project_files libvpx_srcs.txt MAC_ARM64 mac/arm64
323 echo "Generate AARCH64 source list on Windows."
324 config=$(print_config win/aarch64)
325 make_clean
326 make libvpx_srcs.txt target=libs $config > /dev/null
327 convert_srcs_to_project_files libvpx_srcs.txt WIN_AARCH64 win/aarch64
329 echo "Generate generic source list."
330 config=$(print_config generic)
331 make_clean
332 make libvpx_srcs.txt target=libs $config > /dev/null
333 convert_srcs_to_project_files libvpx_srcs.txt GENERIC generic
335 echo "}" >> $BASE_DIR/sources.mozbuild
337 echo "Remove temporary directory."
338 cd $BASE_DIR
339 rm -rf $TEMP_DIR
341 cd $BASE_DIR/$LIBVPX_SRC_DIR
343 cd $BASE_DIR