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 # 10 # For example: 11 # $ ./generate_config.sh 12 # 13 # And this will update all the config files needed. 14 15 export LC_ALL=C 16 BASE_DIR=$(pwd) 17 LIBVPX_SRC_DIR="libvpx" 18 LIBVPX_CONFIG_DIR="config" 19 20 # Clean files from previous make. 21 function make_clean { 22 make clean > /dev/null 23 rm -f libvpx_srcs.txt 24 } 25 26 # Lint a pair of vpx_config.h and vpx_config.asm to make sure they match. 27 # $1 - Header file directory. 28 function lint_config { 29 # mips does not contain any assembly so the header does not need to be 30 # compared to the asm. 31 if [[ "$1" != *mips* ]]; then 32 $BASE_DIR/lint_config.sh \ 33 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ 34 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm 35 fi 36 } 37 38 # Print the configuration. 39 # $1 - Header file directory. 40 function print_config { 41 $BASE_DIR/lint_config.sh -p \ 42 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ 43 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm 44 } 45 46 # Print the configuration from Header file. 47 # This function is an abridged version of print_config which does not use 48 # lint_config and it does not require existence of vpx_config.asm. 49 # $1 - Header file directory. 50 function print_config_basic { 51 combined_config="$(cat $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ 52 | grep -E ' +[01] *$')" 53 combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)" 54 combined_config="$(echo "$combined_config" | sed 's/[ \t]//g')" 55 combined_config="$(echo "$combined_config" | sed 's/.*define//')" 56 combined_config="$(echo "$combined_config" | sed 's/0$/=no/')" 57 combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')" 58 echo "$combined_config" | sort | uniq 59 } 60 61 # Generate *_rtcd.h files. 62 # $1 - Header file directory. 63 # $2 - Architecture. 64 function gen_rtcd_header { 65 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files." 66 67 # We don't properly persist the config options specificed on the configure 68 # line. Until that is fixed, force them here. 69 DISABLE_CONFIG="--disable-sse4_1 --disable-avx --disable-avx2" 70 71 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config 72 if [[ "$2" == *mips* ]]; then 73 print_config_basic $1 > $BASE_DIR/$TEMP_DIR/libvpx.config 74 else 75 $BASE_DIR/lint_config.sh -p \ 76 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ 77 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \ 78 -o $BASE_DIR/$TEMP_DIR/libvpx.config 79 fi 80 81 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 82 --arch=$2 \ 83 --sym=vp8_rtcd \ 84 $DISABLE_CONFIG \ 85 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 86 $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \ 87 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h 88 89 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 90 --arch=$2 \ 91 --sym=vp9_rtcd \ 92 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 93 $DISABLE_CONFIG \ 94 $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \ 95 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h 96 97 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 98 --arch=$2 \ 99 --sym=vpx_scale_rtcd \ 100 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 101 $DISABLE_CONFIG \ 102 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \ 103 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h 104 105 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 106 --arch=$2 \ 107 --sym=vpx_dsp_rtcd \ 108 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 109 $DISABLE_CONFIG \ 110 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \ 111 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h 112 113 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config 114 } 115 116 # Generate Config files. "--enable-external-build" must be set to skip 117 # detection of capabilities on specific targets. 118 # $1 - Header file directory. 119 # $2 - Config command line. 120 function gen_config_files { 121 ./configure $2 > /dev/null 122 123 # Generate vpx_config.asm. Do not create one for mips. 124 if [[ "$1" != *mips* ]]; then 125 if [[ "$1" == *x86* ]]; then 126 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ 127 | awk '{print "%define " $2 " " $3}' > vpx_config.asm 128 else 129 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ 130 | awk '{print $2 " EQU " $3}' \ 131 | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl > vpx_config.asm 132 fi 133 fi 134 135 # Generate vpx_version.h 136 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/version.sh "$BASE_DIR/$LIBVPX_SRC_DIR" vpx_version.h 137 138 cp vpx_config.* vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1 139 make_clean 140 rm -rf vpx_config.* vpx_version.h 141 } 142 143 echo "Create temporary directory." 144 TEMP_DIR="$LIBVPX_SRC_DIR.temp" 145 rm -rf $TEMP_DIR 146 cp -R $LIBVPX_SRC_DIR $TEMP_DIR 147 cd $TEMP_DIR 148 149 echo "Generate config files." 150 all_platforms="--enable-external-build --enable-realtime-only --enable-pic --disable-runtime-cpu-detect" 151 intel="--disable-sse4_1 --disable-avx --disable-avx2 --as=yasm" 152 gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}" 153 gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}" 154 gen_config_files arm "--target=armv6-linux-gcc ${all_platforms}" 155 gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}" 156 gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}" 157 gen_config_files mips32 "--target=mips32-linux-gcc --disable-dspr2 ${all_platforms}" 158 gen_config_files mips32-dspr2 "--target=mips32-linux-gcc --enable-dspr2 ${all_platforms}" 159 gen_config_files mips64 "--target=mips64-linux-gcc ${all_platforms}" 160 gen_config_files generic "--target=generic-gnu ${all_platforms}" 161 162 echo "Remove temporary directory." 163 cd $BASE_DIR 164 rm -rf $TEMP_DIR 165 166 echo "Lint libvpx configuration." 167 lint_config x86 168 lint_config x86_64 169 lint_config arm 170 lint_config arm-neon 171 lint_config arm64 172 lint_config mips32 173 lint_config mips32-dspr2 174 lint_config mips64 175 lint_config generic 176 177 echo "Create temporary directory." 178 TEMP_DIR="$LIBVPX_SRC_DIR.temp" 179 rm -rf $TEMP_DIR 180 cp -R $LIBVPX_SRC_DIR $TEMP_DIR 181 cd $TEMP_DIR 182 183 gen_rtcd_header x86 x86 184 gen_rtcd_header x86_64 x86_64 185 gen_rtcd_header arm armv6 186 gen_rtcd_header arm-neon armv7 187 gen_rtcd_header arm64 armv8 188 gen_rtcd_header mips32 mips32 189 gen_rtcd_header mips32-dspr2 mips32 190 gen_rtcd_header mips64 mips64 191 gen_rtcd_header generic generic 192 193 echo "Prepare Makefile." 194 ./configure --target=generic-gnu > /dev/null 195 make_clean 196 197 echo "Generate X86 source list." 198 config=$(print_config x86) 199 make_clean 200 make libvpx_srcs.txt target=libs $config > /dev/null 201 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/x86/ 202 203 echo "Generate X86_64 source list." 204 config=$(print_config x86_64) 205 make_clean 206 make libvpx_srcs.txt target=libs $config > /dev/null 207 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/x86_64/ 208 209 echo "Generate ARM source list." 210 config=$(print_config arm) 211 make_clean 212 make libvpx_srcs.txt target=libs $config > /dev/null 213 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm/ 214 215 echo "Generate ARM NEON source list." 216 config=$(print_config arm-neon) 217 make_clean 218 make libvpx_srcs.txt target=libs $config > /dev/null 219 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm-neon/ 220 221 echo "Generate ARM64 source list." 222 config=$(print_config arm64) 223 make_clean 224 make libvpx_srcs.txt target=libs $config > /dev/null 225 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm64/ 226 227 echo "Generate MIPS source list." 228 config=$(print_config_basic mips32) 229 make_clean 230 make libvpx_srcs.txt target=libs $config > /dev/null 231 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips32/ 232 233 echo "Generate MIPS DSPR2 source list." 234 config=$(print_config_basic mips32-dspr2) 235 make_clean 236 make libvpx_srcs.txt target=libs $config > /dev/null 237 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips32-dspr2/ 238 239 echo "Generate MIPS64 source list." 240 config=$(print_config_basic mips64) 241 make_clean 242 make libvpx_srcs.txt target=libs $config > /dev/null 243 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips64/ 244 245 echo "Generate GENERIC source list." 246 config=$(print_config_basic generic) 247 make_clean 248 make libvpx_srcs.txt target=libs $config > /dev/null 249 cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/generic/ 250 251 252 echo "Remove temporary directory." 253 cd $BASE_DIR 254 rm -rf $TEMP_DIR 255