Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 1 | #!/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 Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 10 | # 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 Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 17 | # |
| 18 | # And this will update all the config files needed. |
| 19 | |
| 20 | export LC_ALL=C |
Colin Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 21 | cd $(dirname $0) |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 22 | BASE_DIR=$(pwd) |
| 23 | LIBVPX_SRC_DIR="libvpx" |
| 24 | LIBVPX_CONFIG_DIR="config" |
| 25 | |
| 26 | # Clean files from previous make. |
| 27 | function 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. |
| 34 | function lint_config { |
Johann | 9d86dd8 | 2019-01-18 09:13:56 -0800 | [diff] [blame] | 35 | $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 Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | # Print the configuration. |
| 41 | # $1 - Header file directory. |
| 42 | function 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. |
| 52 | function 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. |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 66 | # $3 - Optional - any additional arguments to pass through. |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 67 | function gen_rtcd_header { |
| 68 | echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files." |
| 69 | |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 70 | rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config |
Johann | 9d86dd8 | 2019-01-18 09:13:56 -0800 | [diff] [blame] | 71 | $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 Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 75 | |
| 76 | $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ |
| 77 | --arch=$2 \ |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 78 | --sym=vp8_rtcd $3 \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 79 | --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 \ |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 85 | --sym=vp9_rtcd $3 \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 86 | --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 87 | $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 \ |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 92 | --sym=vpx_scale_rtcd $3 \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 93 | --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 94 | $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 \ |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 99 | --sym=vpx_dsp_rtcd $3 \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 100 | --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 101 | $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. |
| 111 | function gen_config_files { |
| 112 | ./configure $2 > /dev/null |
| 113 | |
Johann | 9d86dd8 | 2019-01-18 09:13:56 -0800 | [diff] [blame] | 114 | # 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 Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 123 | 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 Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 133 | # Generate a text file containing sources for a config |
| 134 | # $1 - Config |
| 135 | function gen_source_list { |
| 136 | make_clean |
Johann | 9d86dd8 | 2019-01-18 09:13:56 -0800 | [diff] [blame] | 137 | if [[ "$1" = "generic" ]]; then |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 138 | 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 |
| 148 | function 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 |
| 154 | function libvpx_srcs_txt_to_asm_srcs { |
| 155 | grep ".asm$" $1 | awk '$0="\"libvpx/"$0"\","' | sort |
| 156 | } |
| 157 | |
Dan Willemsen | fac5991 | 2018-10-05 14:54:21 -0700 | [diff] [blame] | 158 | # Extract a list of converted ASM sources from a libvpx_srcs.txt file |
| 159 | # $1 - path to libvpx_srcs.txt |
| 160 | function libvpx_srcs_txt_to_asm_S_srcs { |
| 161 | grep ".asm.S$" $1 | awk '$0="\""$0"\","' | sort |
| 162 | } |
| 163 | |
Colin Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 164 | # Convert a list of sources to a blueprint file containing a variable |
| 165 | # assignment. |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 166 | # $1 - Config |
Colin Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 167 | function gen_bp_srcs { |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 168 | ( |
| 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 Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 173 | echo "]" |
Dan Willemsen | fac5991 | 2018-10-05 14:54:21 -0700 | [diff] [blame] | 174 | if grep -qE ".asm(.S)?$" libvpx_srcs_$1.txt; then |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 175 | echo |
| 176 | echo "${varprefix}_asm_srcs = [" |
| 177 | libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt |
Dan Willemsen | fac5991 | 2018-10-05 14:54:21 -0700 | [diff] [blame] | 178 | libvpx_srcs_txt_to_asm_S_srcs libvpx_srcs_$1.txt |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 179 | echo "]" |
| 180 | fi |
| 181 | echo |
| 182 | ) > config_$1.bp |
Colin Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Dan Willemsen | fac5991 | 2018-10-05 14:54:21 -0700 | [diff] [blame] | 185 | # 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. |
| 188 | function 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 Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 199 | echo "Create temporary directory." |
| 200 | TEMP_DIR="$LIBVPX_SRC_DIR.temp" |
| 201 | rm -rf $TEMP_DIR |
| 202 | cp -R $LIBVPX_SRC_DIR $TEMP_DIR |
| 203 | cd $TEMP_DIR |
| 204 | |
| 205 | echo "Generate config files." |
James Zern | 55557a2 | 2017-06-03 11:57:12 -0700 | [diff] [blame] | 206 | all_platforms="--enable-external-build --enable-realtime-only --enable-pic" |
| 207 | all_platforms+=" --disable-runtime-cpu-detect --disable-install-docs" |
| 208 | all_platforms+=" --size-limit=4096x3072 --enable-vp9-highbitdepth" |
Johann | df37111 | 2018-01-16 14:31:39 -0800 | [diff] [blame] | 209 | intel="--disable-sse4_1 --disable-avx --disable-avx2 --disable-avx512 --as=yasm" |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 210 | gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}" |
| 211 | gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}" |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 212 | gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}" |
| 213 | gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}" |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 214 | gen_config_files generic "--target=generic-gnu ${all_platforms}" |
| 215 | |
| 216 | echo "Remove temporary directory." |
| 217 | cd $BASE_DIR |
| 218 | rm -rf $TEMP_DIR |
| 219 | |
| 220 | echo "Lint libvpx configuration." |
| 221 | lint_config x86 |
| 222 | lint_config x86_64 |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 223 | lint_config arm-neon |
| 224 | lint_config arm64 |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 225 | lint_config generic |
| 226 | |
| 227 | echo "Create temporary directory." |
| 228 | TEMP_DIR="$LIBVPX_SRC_DIR.temp" |
| 229 | rm -rf $TEMP_DIR |
| 230 | cp -R $LIBVPX_SRC_DIR $TEMP_DIR |
| 231 | cd $TEMP_DIR |
| 232 | |
Johann | 7bc9feb | 2017-01-18 14:34:32 -0800 | [diff] [blame] | 233 | gen_rtcd_header x86 x86 "${intel}" |
| 234 | gen_rtcd_header x86_64 x86_64 "${intel}" |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 235 | gen_rtcd_header arm-neon armv7 |
| 236 | gen_rtcd_header arm64 armv8 |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 237 | gen_rtcd_header generic generic |
| 238 | |
| 239 | echo "Prepare Makefile." |
| 240 | ./configure --target=generic-gnu > /dev/null |
| 241 | make_clean |
| 242 | |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 243 | echo "Generate source lists" |
| 244 | gen_source_list x86 |
| 245 | gen_source_list x86_64 |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 246 | gen_source_list arm-neon |
| 247 | gen_source_list arm64 |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 248 | gen_source_list generic |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 249 | |
Dan Willemsen | fac5991 | 2018-10-05 14:54:21 -0700 | [diff] [blame] | 250 | echo "Convert ARM assembly format" |
| 251 | convert_arm_asm |
| 252 | |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 253 | echo "Convert to bp" |
| 254 | gen_bp_srcs x86 |
| 255 | gen_bp_srcs x86_64 |
Johann | 9d86dd8 | 2019-01-18 09:13:56 -0800 | [diff] [blame] | 256 | gen_bp_srcs arm-neon |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 257 | gen_bp_srcs arm64 |
Colin Cross | 253d2c2 | 2018-02-09 13:48:31 -0800 | [diff] [blame] | 258 | gen_bp_srcs generic |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 259 | |
Colin Cross | fcddc56 | 2017-04-26 14:12:48 -0700 | [diff] [blame] | 260 | rm -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 |
| 268 | bpfmt -w $BASE_DIR/Android.bp |
Vignesh Venkatasubramanian | 7ce0a1d | 2015-08-25 11:05:01 -0700 | [diff] [blame] | 269 | |
| 270 | echo "Remove temporary directory." |
| 271 | cd $BASE_DIR |
| 272 | rm -rf $TEMP_DIR |