Bug 1704628 Part 1: Make selectContextMenuItem use .activateItem() semantics. r=ochameau
[gecko.git] / media / libvpx / generate_sources_mozbuild.sh
blobf2bab8afab2de1da01ad889775649a43731890e0
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 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 source_list=$(echo "$source_list" | grep -v 'vpx_config\.c')
82 # Remove include-only asm files (no object code emitted)
83 source_list=$(echo "$source_list" | grep -v 'x86_abi_support\.asm')
84 source_list=$(echo "$source_list" | grep -v 'config\.asm')
86 # The actual ARM files end in .asm. We have rules to translate them to .S
87 source_list=$(echo "$source_list" | sed s/\.asm\.s$/.asm/)
89 # Exports - everything in vpx, vpx_mem, vpx_ports, vpx_scale
90 local exports_list=$(echo "$source_list" | \
91 egrep '^(vpx|vpx_mem|vpx_ports|vpx_scale)/.*h$')
92 # but not anything in one level down, like 'internal'
93 exports_list=$(echo "$exports_list" | egrep -v '/(internal|src)/')
94 # or any of the other internal-ish header files.
95 exports_list=$(echo "$exports_list" | egrep -v '/(emmintrin_compat.h|mem_.*|msvc.h|vpx_once.h)$')
97 # Remove these files from the main list.
98 source_list=$(comm -23 <(echo "$source_list") <(echo "$exports_list"))
100 # Write a single file that includes all source files for all archs.
101 local c_sources=$(echo "$source_list" | egrep '.(asm|c)$')
102 local exports_sources=$(echo "$exports_list" | egrep '.h$')
104 write_sources exports_sources ${2}_EXPORTS "$BASE_DIR/sources.mozbuild"
105 write_sources c_sources ${2}_SOURCES "$BASE_DIR/sources.mozbuild"
108 # Clean files from previous make.
109 function make_clean {
110 make clean > /dev/null
111 rm -f libvpx_srcs.txt
114 # Print the configuration.
115 # $1 - Header file directory.
116 function print_config {
117 $BASE_DIR/lint_config.sh -p \
118 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
119 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
122 # Generate *_rtcd.h files.
123 # $1 - Header file directory.
124 # $2 - Architecture.
125 # $3 - Optional - any additional arguments to pass through.
126 function gen_rtcd_header {
127 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
129 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
130 $BASE_DIR/lint_config.sh -p \
131 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
132 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
133 -o $BASE_DIR/$TEMP_DIR/libvpx.config
135 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
136 --arch=$2 \
137 --sym=vp8_rtcd $DISABLE_AVX $3 \
138 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
139 $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
140 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
142 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
143 --arch=$2 \
144 --sym=vp9_rtcd $DISABLE_AVX $3 \
145 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
146 $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \
147 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
149 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
150 --arch=$2 \
151 --sym=vpx_scale_rtcd $DISABLE_AVX $3 \
152 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
153 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \
154 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
156 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
157 --arch=$2 \
158 --sym=vpx_dsp_rtcd $DISABLE_AVX $3 \
159 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
160 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \
161 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
163 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
166 # Generate Config files. "--enable-external-build" must be set to skip
167 # detection of capabilities on specific targets.
168 # $1 - Header file directory.
169 # $2 - Config command line.
170 function gen_config_files {
171 ./configure $2 > /dev/null
173 # Disable HAVE_UNISTD_H.
174 ( echo '/HAVE_UNISTD_H'; echo 'd' ; echo 'w' ; echo 'q' ) | ed -s vpx_config.h
176 local ASM_CONV=ads2gas.pl
178 # Generate vpx_config.asm.
179 if [[ "$1" == *x64* ]] || [[ "$1" == *ia32* ]]; then
180 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h | awk '{print "%define " $2 " " $3}' > vpx_config.asm
181 else
182 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
185 cp vpx_config.* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
186 make_clean
187 rm -rf vpx_config.*
190 find_duplicates
192 echo "Create temporary directory."
193 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
194 rm -rf $TEMP_DIR
195 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
196 cd $TEMP_DIR
198 echo "Generate config files."
199 all_platforms="--enable-external-build --disable-examples --disable-install-docs --disable-unit-tests"
200 all_platforms="${all_platforms} --enable-multi-res-encoding --size-limit=8192x4608 --enable-pic"
201 all_platforms="${all_platforms} --disable-avx512"
202 x86_platforms="--enable-postproc --enable-vp9-postproc --as=yasm"
203 arm_platforms="--enable-runtime-cpu-detect --enable-realtime-only"
204 arm64_platforms="--enable-realtime-only"
206 gen_config_files linux/x64 "--target=x86_64-linux-gcc ${all_platforms} ${x86_platforms}"
207 gen_config_files linux/ia32 "--target=x86-linux-gcc ${all_platforms} ${x86_platforms}"
208 gen_config_files mac/x64 "--target=x86_64-darwin9-gcc ${all_platforms} ${x86_platforms}"
209 gen_config_files mac/ia32 "--target=x86-darwin9-gcc ${all_platforms} ${x86_platforms}"
210 gen_config_files win/x64 "--target=x86_64-win64-vs15 ${all_platforms} ${x86_platforms}"
211 gen_config_files win/ia32 "--target=x86-win32-gcc ${all_platforms} ${x86_platforms}"
213 gen_config_files linux/arm "--target=armv7-linux-gcc ${all_platforms} ${arm_platforms}"
214 gen_config_files linux/arm64 "--target=arm64-linux-gcc ${all_platforms} ${arm64_platforms}"
215 gen_config_files win/aarch64 "--target=arm64-win64-vs15 ${all_platforms} ${arm64_platforms}"
217 gen_config_files generic "--target=generic-gnu ${all_platforms}"
219 echo "Remove temporary directory."
220 cd $BASE_DIR
221 rm -rf $TEMP_DIR
223 echo "Create temporary directory."
224 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
225 rm -rf $TEMP_DIR
226 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
227 cd $TEMP_DIR
229 gen_rtcd_header linux/x64 x86_64
230 gen_rtcd_header linux/ia32 x86
231 gen_rtcd_header mac/x64 x86_64
232 gen_rtcd_header mac/ia32 x86
233 gen_rtcd_header win/x64 x86_64
234 gen_rtcd_header win/ia32 x86
236 gen_rtcd_header linux/arm armv7
237 gen_rtcd_header linux/arm64 arm64
238 gen_rtcd_header win/aarch64 arm64
240 gen_rtcd_header generic generic
242 echo "Prepare Makefile."
243 ./configure --target=generic-gnu > /dev/null
244 make_clean
246 # Remove existing source files.
247 rm -rf $BASE_DIR/sources.mozbuild
248 write_license $BASE_DIR/sources.mozbuild
249 echo "files = {" >> $BASE_DIR/sources.mozbuild
251 echo "Generate X86_64 source list."
252 config=$(print_config linux/x64)
253 make_clean
254 make libvpx_srcs.txt target=libs $config > /dev/null
255 convert_srcs_to_project_files libvpx_srcs.txt X64
257 # Copy vpx_version.h once. The file is the same for all platforms.
258 cp vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR
260 echo "Generate IA32 source list."
261 config=$(print_config linux/ia32)
262 make_clean
263 make libvpx_srcs.txt target=libs $config > /dev/null
264 convert_srcs_to_project_files libvpx_srcs.txt IA32
266 echo "Generate ARM source list."
267 config=$(print_config linux/arm)
268 make_clean
269 make libvpx_srcs.txt target=libs $config > /dev/null
270 convert_srcs_to_project_files libvpx_srcs.txt ARM
272 echo "Generate ARM64 source list."
273 config=$(print_config linux/arm64)
274 make_clean
275 make libvpx_srcs.txt target=libs $config > /dev/null
276 convert_srcs_to_project_files libvpx_srcs.txt ARM64
278 echo "Generate generic source list."
279 config=$(print_config generic)
280 make_clean
281 make libvpx_srcs.txt target=libs $config > /dev/null
282 convert_srcs_to_project_files libvpx_srcs.txt GENERIC
284 echo "}" >> $BASE_DIR/sources.mozbuild
286 echo "Remove temporary directory."
287 cd $BASE_DIR
288 rm -rf $TEMP_DIR
290 cd $BASE_DIR/$LIBVPX_SRC_DIR
292 cd $BASE_DIR