Home | History | Annotate | Download | only in libvpx
      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 # 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
     17 #
     18 # And this will update all the config files needed.
     19 
     20 export LC_ALL=C
     21 cd $(dirname $0)
     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 {
     35   # mips does not contain any assembly so the header does not need to be
     36   # compared to the asm.
     37   if [[ "$1" != *mips* ]]; then
     38     $BASE_DIR/lint_config.sh \
     39       -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
     40       -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
     41   fi
     42 }
     43 
     44 # Print the configuration.
     45 # $1 - Header file directory.
     46 function print_config {
     47   $BASE_DIR/lint_config.sh -p \
     48     -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
     49     -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
     50 }
     51 
     52 # Print the configuration from Header file.
     53 # This function is an abridged version of print_config which does not use
     54 # lint_config and it does not require existence of vpx_config.asm.
     55 # $1 - Header file directory.
     56 function print_config_basic {
     57   combined_config="$(cat $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
     58                    | grep -E ' +[01] *$')"
     59   combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)"
     60   combined_config="$(echo "$combined_config" | sed 's/[ \t]//g')"
     61   combined_config="$(echo "$combined_config" | sed 's/.*define//')"
     62   combined_config="$(echo "$combined_config" | sed 's/0$/=no/')"
     63   combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')"
     64   echo "$combined_config" | sort | uniq
     65 }
     66 
     67 # Generate *_rtcd.h files.
     68 # $1 - Header file directory.
     69 # $2 - Architecture.
     70 # $3 - Optional - any additional arguments to pass through.
     71 function gen_rtcd_header {
     72   echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
     73 
     74   rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
     75   if [[ "$2" == *mips* ]]; then
     76     print_config_basic $1 > $BASE_DIR/$TEMP_DIR/libvpx.config
     77   else
     78     $BASE_DIR/lint_config.sh -p \
     79       -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
     80       -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
     81       -o $BASE_DIR/$TEMP_DIR/libvpx.config
     82   fi
     83 
     84   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     85     --arch=$2 \
     86     --sym=vp8_rtcd $3 \
     87     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     88     $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
     89     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
     90 
     91   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     92     --arch=$2 \
     93     --sym=vp9_rtcd $3 \
     94     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     95     $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \
     96     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
     97 
     98   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     99     --arch=$2 \
    100     --sym=vpx_scale_rtcd $3 \
    101     --config=$BASE_DIR/$TEMP_DIR/libvpx.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 $3 \
    108     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
    109     $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \
    110     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
    111 
    112   rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
    113 }
    114 
    115 # Generate Config files. "--enable-external-build" must be set to skip
    116 # detection of capabilities on specific targets.
    117 # $1 - Header file directory.
    118 # $2 - Config command line.
    119 function gen_config_files {
    120   ./configure $2 > /dev/null
    121 
    122   # Generate vpx_config.asm. Do not create one for mips.
    123   if [[ "$1" != *mips* ]]; then
    124     if [[ "$1" == *x86* ]]; then
    125       egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \
    126         | awk '{print "%define " $2 " " $3}' > vpx_config.asm
    127     else
    128       egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \
    129         | awk '{print $2 " EQU " $3}' \
    130         | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl > vpx_config.asm
    131     fi
    132   fi
    133 
    134   # Generate vpx_version.h
    135   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/version.sh "$BASE_DIR/$LIBVPX_SRC_DIR" vpx_version.h
    136 
    137   cp vpx_config.* vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
    138   make_clean
    139   rm -rf vpx_config.* vpx_version.h
    140 }
    141 
    142 # Generate a text file containing sources for a config
    143 # $1 - Config
    144 function gen_source_list {
    145   make_clean
    146   if [[ "$1" = "mips"* ]] || [[ "$1" = "generic" ]]; then
    147     config=$(print_config_basic $1)
    148   else
    149     config=$(print_config $1)
    150   fi
    151   make libvpx_srcs.txt target=libs $config > /dev/null
    152   mv libvpx_srcs.txt libvpx_srcs_$1.txt
    153 }
    154 
    155 # Extract a list of C sources from a libvpx_srcs.txt file
    156 # $1 - path to libvpx_srcs.txt
    157 function libvpx_srcs_txt_to_c_srcs {
    158     grep ".c$" $1 | grep -v "^vpx_config.c$" | awk '$0="\"libvpx/"$0"\","' | sort
    159 }
    160 
    161 # Extract a list of ASM sources from a libvpx_srcs.txt file
    162 # $1 - path to libvpx_srcs.txt
    163 function libvpx_srcs_txt_to_asm_srcs {
    164     grep ".asm$" $1 | awk '$0="\"libvpx/"$0"\","' | sort
    165 }
    166 
    167 # Convert a list of sources to a blueprint file containing a variable
    168 # assignment.
    169 # $1 - Config
    170 function gen_bp_srcs {
    171   (
    172     varprefix=libvpx_${1//-/_}
    173     echo "${varprefix}_c_srcs = ["
    174     libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt
    175     echo "\"$LIBVPX_CONFIG_DIR/$1/vpx_config.c\","
    176     echo "]"
    177     if grep -q ".asm$" libvpx_srcs_$1.txt; then
    178       echo
    179       echo "${varprefix}_asm_srcs = ["
    180       libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt
    181       echo "]"
    182     fi
    183     echo
    184   ) > config_$1.bp
    185 }
    186 
    187 # Convert a list of sources to a blueprint file containing a variable
    188 # assignment, relative to a reference config.
    189 # $1 - Config
    190 # $2 - Reference config
    191 function gen_bp_srcs_with_excludes {
    192   (
    193     varprefix=libvpx_${1//-/_}
    194     echo "${varprefix}_c_srcs = ["
    195     comm -23 <(libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt) <(libvpx_srcs_txt_to_c_srcs libvpx_srcs_$2.txt)
    196     echo "\"$LIBVPX_CONFIG_DIR/$1/vpx_config.c\","
    197     echo "]"
    198     echo
    199     echo "${varprefix}_exclude_c_srcs = ["
    200     comm -13 <(libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt) <(libvpx_srcs_txt_to_c_srcs libvpx_srcs_$2.txt)
    201     echo "\"$LIBVPX_CONFIG_DIR/$2/vpx_config.c\","
    202     echo "]"
    203     echo
    204     if grep -q ".asm$" libvpx_srcs_$1.txt; then
    205       echo
    206       echo "${varprefix}_asm_srcs = ["
    207       libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt
    208       echo "]"
    209     fi
    210     echo
    211   ) > config_$1.bp
    212 }
    213 
    214 echo "Create temporary directory."
    215 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
    216 rm -rf $TEMP_DIR
    217 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
    218 cd $TEMP_DIR
    219 
    220 echo "Generate config files."
    221 all_platforms="--enable-external-build --enable-realtime-only --enable-pic"
    222 all_platforms+=" --disable-runtime-cpu-detect --disable-install-docs"
    223 all_platforms+=" --size-limit=4096x3072 --enable-vp9-highbitdepth"
    224 intel="--disable-sse4_1 --disable-avx --disable-avx2 --disable-avx512 --as=yasm"
    225 gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}"
    226 gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}"
    227 gen_config_files arm "--target=armv7-linux-gcc --disable-neon ${all_platforms}"
    228 gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}"
    229 gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}"
    230 gen_config_files mips32 "--target=mips32-linux-gcc --disable-dspr2 --disable-msa ${all_platforms}"
    231 gen_config_files mips32-dspr2 "--target=mips32-linux-gcc --enable-dspr2 ${all_platforms}"
    232 gen_config_files mips32-msa "--target=mips32-linux-gcc --enable-msa ${all_platforms}"
    233 gen_config_files mips64 "--target=mips64-linux-gcc --disable-msa ${all_platforms}"
    234 gen_config_files mips64-msa "--target=mips64-linux-gcc --enable-msa ${all_platforms}"
    235 gen_config_files generic "--target=generic-gnu ${all_platforms}"
    236 
    237 echo "Remove temporary directory."
    238 cd $BASE_DIR
    239 rm -rf $TEMP_DIR
    240 
    241 echo "Lint libvpx configuration."
    242 lint_config x86
    243 lint_config x86_64
    244 lint_config arm
    245 lint_config arm-neon
    246 lint_config arm64
    247 lint_config mips32
    248 lint_config mips32-dspr2
    249 lint_config mips32-msa
    250 lint_config mips64
    251 lint_config mips64-msa
    252 lint_config generic
    253 
    254 echo "Create temporary directory."
    255 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
    256 rm -rf $TEMP_DIR
    257 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
    258 cd $TEMP_DIR
    259 
    260 gen_rtcd_header x86 x86 "${intel}"
    261 gen_rtcd_header x86_64 x86_64 "${intel}"
    262 gen_rtcd_header arm armv7 "--disable-neon"
    263 gen_rtcd_header arm-neon armv7
    264 gen_rtcd_header arm64 armv8
    265 gen_rtcd_header mips32 mips32
    266 gen_rtcd_header mips32-dspr2 mips32
    267 gen_rtcd_header mips32-msa mips32
    268 gen_rtcd_header mips64 mips64
    269 gen_rtcd_header mips64-msa mips64
    270 gen_rtcd_header generic generic
    271 
    272 echo "Prepare Makefile."
    273 ./configure --target=generic-gnu > /dev/null
    274 make_clean
    275 
    276 echo "Generate source lists"
    277 gen_source_list x86
    278 gen_source_list x86_64
    279 gen_source_list arm
    280 gen_source_list arm-neon
    281 gen_source_list arm64
    282 gen_source_list mips32
    283 gen_source_list mips32-dspr2
    284 gen_source_list mips32-msa
    285 gen_source_list mips64
    286 gen_source_list mips64-msa
    287 gen_source_list generic
    288 
    289 echo "Convert to bp"
    290 gen_bp_srcs x86
    291 gen_bp_srcs x86_64
    292 gen_bp_srcs arm
    293 gen_bp_srcs_with_excludes arm-neon arm
    294 gen_bp_srcs arm64
    295 gen_bp_srcs mips32
    296 gen_bp_srcs_with_excludes mips32-dspr2 mips32
    297 gen_bp_srcs_with_excludes mips32-msa mips32
    298 gen_bp_srcs mips64
    299 gen_bp_srcs_with_excludes mips64-msa mips64
    300 gen_bp_srcs generic
    301 
    302 rm -f $BASE_DIR/Android.bp
    303 (
    304   echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT"
    305   echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate"
    306   echo
    307   cat config_*.bp
    308   cat $BASE_DIR/Android.bp.in
    309 ) > $BASE_DIR/Android.bp
    310 bpfmt -w $BASE_DIR/Android.bp
    311 
    312 echo "Remove temporary directory."
    313 cd $BASE_DIR
    314 rm -rf $TEMP_DIR
    315