blob: fd6b349829f50f0a3d07a4182d87b4475c93ee01 [file] [log] [blame]
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -07001#!/bin/bash -e
2#
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.
6
7# This script is used to generate files in the <platform> directories needed to
8# build libvpx. Every time libvpx source code is updated run this script.
9#
Colin Crossfcddc562017-04-26 14:12:48 -070010# The script depends on the bpfmt tool, which may need to be built with
11# m -j blueprint_tools
12#
13# For example, from the top of an Android tree:
14# $ source build/envsetup.sh
15# $ m -j blueprint_tools
16# $ external/libvpx/generate_config.sh
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070017#
18# And this will update all the config files needed.
19
20export LC_ALL=C
Colin Crossfcddc562017-04-26 14:12:48 -070021cd $(dirname $0)
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070022BASE_DIR=$(pwd)
23LIBVPX_SRC_DIR="libvpx"
24LIBVPX_CONFIG_DIR="config"
25
26# Clean files from previous make.
27function make_clean {
28 make clean > /dev/null
29 rm -f libvpx_srcs.txt
30}
31
32# Lint a pair of vpx_config.h and vpx_config.asm to make sure they match.
33# $1 - Header file directory.
34function lint_config {
Johann9d86dd82019-01-18 09:13:56 -080035 $BASE_DIR/lint_config.sh \
36 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
37 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070038}
39
40# Print the configuration.
41# $1 - Header file directory.
42function print_config {
43 $BASE_DIR/lint_config.sh -p \
44 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
45 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
46}
47
48# Print the configuration from Header file.
49# This function is an abridged version of print_config which does not use
50# lint_config and it does not require existence of vpx_config.asm.
51# $1 - Header file directory.
52function print_config_basic {
53 combined_config="$(cat $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
54 | grep -E ' +[01] *$')"
55 combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)"
56 combined_config="$(echo "$combined_config" | sed 's/[ \t]//g')"
57 combined_config="$(echo "$combined_config" | sed 's/.*define//')"
58 combined_config="$(echo "$combined_config" | sed 's/0$/=no/')"
59 combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')"
60 echo "$combined_config" | sort | uniq
61}
62
63# Generate *_rtcd.h files.
64# $1 - Header file directory.
65# $2 - Architecture.
Johann7bc9feb2017-01-18 14:34:32 -080066# $3 - Optional - any additional arguments to pass through.
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070067function gen_rtcd_header {
68 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
69
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070070 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
Johann9d86dd82019-01-18 09:13:56 -080071 $BASE_DIR/lint_config.sh -p \
72 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
73 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
74 -o $BASE_DIR/$TEMP_DIR/libvpx.config
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070075
76 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
77 --arch=$2 \
Johann7bc9feb2017-01-18 14:34:32 -080078 --sym=vp8_rtcd $3 \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070079 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
80 $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
81 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
82
83 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
84 --arch=$2 \
Johann7bc9feb2017-01-18 14:34:32 -080085 --sym=vp9_rtcd $3 \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070086 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070087 $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \
88 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
89
90 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
91 --arch=$2 \
Johann7bc9feb2017-01-18 14:34:32 -080092 --sym=vpx_scale_rtcd $3 \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070093 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -070094 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \
95 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
96
97 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
98 --arch=$2 \
Johann7bc9feb2017-01-18 14:34:32 -080099 --sym=vpx_dsp_rtcd $3 \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700100 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700101 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \
102 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
103
104 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
105}
106
107# Generate Config files. "--enable-external-build" must be set to skip
108# detection of capabilities on specific targets.
109# $1 - Header file directory.
110# $2 - Config command line.
111function gen_config_files {
112 ./configure $2 > /dev/null
113
Johann9d86dd82019-01-18 09:13:56 -0800114 # Generate vpx_config.asm for x86[_64].
115 if [[ "$1" == *x86* ]]; then
116 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \
117 | awk '{print "%define " $2 " " $3}' > vpx_config.asm
118 else
119 # vpx_config.asm is unused for arm[64] but is needed to pass lint_config.
120 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \
121 | awk '{print $2 " EQU " $3}' \
122 | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl > vpx_config.asm
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700123 fi
124
125 # Generate vpx_version.h
126 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/version.sh "$BASE_DIR/$LIBVPX_SRC_DIR" vpx_version.h
127
128 cp vpx_config.* vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
129 make_clean
130 rm -rf vpx_config.* vpx_version.h
131}
132
Colin Cross253d2c22018-02-09 13:48:31 -0800133# Generate a text file containing sources for a config
134# $1 - Config
135function gen_source_list {
136 make_clean
Johann9d86dd82019-01-18 09:13:56 -0800137 if [[ "$1" = "generic" ]]; then
Colin Cross253d2c22018-02-09 13:48:31 -0800138 config=$(print_config_basic $1)
139 else
140 config=$(print_config $1)
141 fi
142 make libvpx_srcs.txt target=libs $config > /dev/null
143 mv libvpx_srcs.txt libvpx_srcs_$1.txt
144}
145
146# Extract a list of C sources from a libvpx_srcs.txt file
147# $1 - path to libvpx_srcs.txt
148function libvpx_srcs_txt_to_c_srcs {
149 grep ".c$" $1 | grep -v "^vpx_config.c$" | awk '$0="\"libvpx/"$0"\","' | sort
150}
151
152# Extract a list of ASM sources from a libvpx_srcs.txt file
153# $1 - path to libvpx_srcs.txt
154function libvpx_srcs_txt_to_asm_srcs {
155 grep ".asm$" $1 | awk '$0="\"libvpx/"$0"\","' | sort
156}
157
Dan Willemsenfac59912018-10-05 14:54:21 -0700158# Extract a list of converted ASM sources from a libvpx_srcs.txt file
159# $1 - path to libvpx_srcs.txt
160function libvpx_srcs_txt_to_asm_S_srcs {
161 grep ".asm.S$" $1 | awk '$0="\""$0"\","' | sort
162}
163
Colin Crossfcddc562017-04-26 14:12:48 -0700164# Convert a list of sources to a blueprint file containing a variable
165# assignment.
Colin Cross253d2c22018-02-09 13:48:31 -0800166# $1 - Config
Colin Crossfcddc562017-04-26 14:12:48 -0700167function gen_bp_srcs {
Colin Cross253d2c22018-02-09 13:48:31 -0800168 (
169 varprefix=libvpx_${1//-/_}
170 echo "${varprefix}_c_srcs = ["
171 libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt
172 echo "\"$LIBVPX_CONFIG_DIR/$1/vpx_config.c\","
Colin Crossfcddc562017-04-26 14:12:48 -0700173 echo "]"
Dan Willemsenfac59912018-10-05 14:54:21 -0700174 if grep -qE ".asm(.S)?$" libvpx_srcs_$1.txt; then
Colin Cross253d2c22018-02-09 13:48:31 -0800175 echo
176 echo "${varprefix}_asm_srcs = ["
177 libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt
Dan Willemsenfac59912018-10-05 14:54:21 -0700178 libvpx_srcs_txt_to_asm_S_srcs libvpx_srcs_$1.txt
Colin Cross253d2c22018-02-09 13:48:31 -0800179 echo "]"
180 fi
181 echo
182 ) > config_$1.bp
Colin Crossfcddc562017-04-26 14:12:48 -0700183}
184
Dan Willemsenfac59912018-10-05 14:54:21 -0700185# The ARM assembly sources must be converted from ADS to GAS compatible format.
186# This step is only required for ARM. MIPS uses intrinsics exclusively and x86
187# requires 'yasm' to pre-process its assembly files.
188function convert_arm_asm {
189 find $BASE_DIR/$LIBVPX_CONFIG_DIR/arm-neon -name '*.asm.S' | xargs -r rm
190 for src in $(grep ".asm$" libvpx_srcs_arm-neon.txt); do
191 newsrc=$LIBVPX_CONFIG_DIR/arm-neon/$src.S
192 mkdir -p $BASE_DIR/$(dirname $newsrc)
193 perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl <$BASE_DIR/$LIBVPX_SRC_DIR/$src >$BASE_DIR/$newsrc
194 echo $newsrc >>libvpx_srcs_arm-neon.txt
195 done
196 sed -i "/\.asm$/ d" libvpx_srcs_arm-neon.txt
197}
198
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700199echo "Create temporary directory."
200TEMP_DIR="$LIBVPX_SRC_DIR.temp"
201rm -rf $TEMP_DIR
202cp -R $LIBVPX_SRC_DIR $TEMP_DIR
203cd $TEMP_DIR
204
205echo "Generate config files."
James Zern55557a22017-06-03 11:57:12 -0700206all_platforms="--enable-external-build --enable-realtime-only --enable-pic"
207all_platforms+=" --disable-runtime-cpu-detect --disable-install-docs"
208all_platforms+=" --size-limit=4096x3072 --enable-vp9-highbitdepth"
Johanndf371112018-01-16 14:31:39 -0800209intel="--disable-sse4_1 --disable-avx --disable-avx2 --disable-avx512 --as=yasm"
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700210gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}"
211gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}"
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700212gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}"
213gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}"
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700214gen_config_files generic "--target=generic-gnu ${all_platforms}"
215
216echo "Remove temporary directory."
217cd $BASE_DIR
218rm -rf $TEMP_DIR
219
220echo "Lint libvpx configuration."
221lint_config x86
222lint_config x86_64
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700223lint_config arm-neon
224lint_config arm64
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700225lint_config generic
226
227echo "Create temporary directory."
228TEMP_DIR="$LIBVPX_SRC_DIR.temp"
229rm -rf $TEMP_DIR
230cp -R $LIBVPX_SRC_DIR $TEMP_DIR
231cd $TEMP_DIR
232
Johann7bc9feb2017-01-18 14:34:32 -0800233gen_rtcd_header x86 x86 "${intel}"
234gen_rtcd_header x86_64 x86_64 "${intel}"
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700235gen_rtcd_header arm-neon armv7
236gen_rtcd_header arm64 armv8
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700237gen_rtcd_header generic generic
238
239echo "Prepare Makefile."
240./configure --target=generic-gnu > /dev/null
241make_clean
242
Colin Cross253d2c22018-02-09 13:48:31 -0800243echo "Generate source lists"
244gen_source_list x86
245gen_source_list x86_64
Colin Cross253d2c22018-02-09 13:48:31 -0800246gen_source_list arm-neon
247gen_source_list arm64
Colin Cross253d2c22018-02-09 13:48:31 -0800248gen_source_list generic
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700249
Dan Willemsenfac59912018-10-05 14:54:21 -0700250echo "Convert ARM assembly format"
251convert_arm_asm
252
Colin Cross253d2c22018-02-09 13:48:31 -0800253echo "Convert to bp"
254gen_bp_srcs x86
255gen_bp_srcs x86_64
Johann9d86dd82019-01-18 09:13:56 -0800256gen_bp_srcs arm-neon
Colin Cross253d2c22018-02-09 13:48:31 -0800257gen_bp_srcs arm64
Colin Cross253d2c22018-02-09 13:48:31 -0800258gen_bp_srcs generic
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700259
Colin Crossfcddc562017-04-26 14:12:48 -0700260rm -f $BASE_DIR/Android.bp
261(
262 echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT"
263 echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate"
264 echo
265 cat config_*.bp
266 cat $BASE_DIR/Android.bp.in
267) > $BASE_DIR/Android.bp
268bpfmt -w $BASE_DIR/Android.bp
Vignesh Venkatasubramanian7ce0a1d2015-08-25 11:05:01 -0700269
270echo "Remove temporary directory."
271cd $BASE_DIR
272rm -rf $TEMP_DIR