#!/bin/bash # # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # This script is used to generate files in the directories needed to # build libvpx. Every time libvpx source code is updated run this script. # # The script depends on the bpfmt tool, which may need to be built with # m -j blueprint_tools # # For example, from the top of an Android tree: # $ source build/envsetup.sh # $ m -j blueprint_tools # $ external/libvpx/post_update.sh # # And this will update all the config files needed. set -e export LC_ALL=C cd $(dirname $0) BASE_DIR=$(pwd) LIBVPX_SRC_DIR="." LIBVPX_CONFIG_DIR="config" # Clean files from previous make. function make_clean { make clean > /dev/null rm -f libvpx_srcs.txt } # Lint a pair of vpx_config.h and vpx_config.asm to make sure they match. # $1 - Header file directory. function lint_config { $BASE_DIR/lint_config.sh \ -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm } # Print the configuration. # $1 - Header file directory. function print_config { $BASE_DIR/lint_config.sh -p \ -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm } # Print the configuration from Header file. # This function is an abridged version of print_config which does not use # lint_config and it does not require existence of vpx_config.asm. # $1 - Header file directory. function print_config_basic { combined_config="$(cat $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ | grep -E ' +[01] *$')" combined_config="$(echo "$combined_config" | grep -v DO1STROUNDING)" combined_config="$(echo "$combined_config" | sed 's/[ \t]//g')" combined_config="$(echo "$combined_config" | sed 's/.*define//')" combined_config="$(echo "$combined_config" | sed 's/0$/=no/')" combined_config="$(echo "$combined_config" | sed 's/1$/=yes/')" echo "$combined_config" | sort | uniq } # Generate *_rtcd.h files. # $1 - Header file directory. # $2 - Architecture. # $3 - Optional - any additional arguments to pass through. function gen_rtcd_header { echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files." rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config $BASE_DIR/lint_config.sh -p \ -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \ -o $BASE_DIR/$TEMP_DIR/libvpx.config $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ --arch=$2 \ --sym=vp8_rtcd $3 \ --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \ > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ --arch=$2 \ --sym=vp9_rtcd $3 \ --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \ > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ --arch=$2 \ --sym=vpx_scale_rtcd $3 \ --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \ > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ --arch=$2 \ --sym=vpx_dsp_rtcd $3 \ --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \ > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config } # Generate Config files. "--enable-external-build" must be set to skip # detection of capabilities on specific targets. # $1 - Header file directory. # $2 - Config command line. function gen_config_files { ./configure $2 > /dev/null # Generate vpx_config.asm for x86[_64]. if [[ "$1" == *x86* ]]; then egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ | awk '{print "%define " $2 " " $3}' > vpx_config.asm else # vpx_config.asm is unused for arm[64] but is needed to pass lint_config. egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ | awk '{print $2 " EQU " $3}' \ | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl > vpx_config.asm fi # Generate vpx_version.h $BASE_DIR/$LIBVPX_SRC_DIR/build/make/version.sh "$BASE_DIR/$LIBVPX_SRC_DIR" vpx_version.h cp vpx_config.* vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1 make_clean rm -rf vpx_config.* vpx_version.h } # Generate a text file containing sources for a config # $1 - Config function gen_source_list { make_clean if [[ "$1" = "generic" ]]; then config=$(print_config_basic $1) else config=$(print_config $1) fi make libvpx_srcs.txt libvpxrc_srcs.txt target=libs $config > /dev/null mv libvpx_srcs.txt libvpx_srcs_$1.txt mv libvpxrc_srcs.txt libvpxrc_srcs_$1.txt } # Extract a list of C sources from a libvpx_srcs.txt file # $1 - path to libvpx_srcs.txt # $2 - C file match pattern # $3 - Negative match pattern (default: none) function libvpx_srcs_txt_to_c_srcs { local match_pattern="$2" local negative_patterns=(-e "^vpx_config\\.c$") if [[ -n "$3" ]]; then negative_patterns+=(-e "$3") fi grep "${match_pattern}" $1 \ | grep -v "${negative_patterns[@]}" \ | awk '$0="\""$0"\","' \ | sort } # Extract a list of C++ sources from a libvpxrc_srcs.txt file # $1 - path to libvpxrc_srcs.txt function libvpxrc_srcs_txt_to_cc_srcs { grep ".cc$" $1 | awk '$0="\""$0"\","' | sort } # Extract a list of ASM sources from a libvpx_srcs.txt file # $1 - path to libvpx_srcs.txt function libvpx_srcs_txt_to_asm_srcs { grep ".asm$" $1 | awk '$0="\""$0"\","' | sort } # Extract a list of converted ASM sources from a libvpx_srcs.txt file # $1 - path to libvpx_srcs.txt function libvpx_srcs_txt_to_asm_S_srcs { grep ".asm.S$" $1 | awk '$0="\""$0"\","' | sort } # Convert a list of sources to a blueprint file containing a variable # assignment. # $1 - Config function gen_bp_srcs { ( # First collect the libvpx sources into variables. varprefix=libvpx_${1//-/_} local negative_pattern # Optimization file suffixes that require explicit architecture flagging. local arch_flag_req_suffixes=() case "$1" in arm64) negative_pattern="\\(_neon_\\(dotprod\\|i8mm\\)\\|_sve\\|_sve2\\)\\.c" arch_flag_req_suffixes=("neon_dotprod" "neon_i8mm" "sve" "sve2") ;; x86*) negative_pattern="\\(_sse4\\|_avx\\|_avx2\\|_avx512\\)\\.c" arch_flag_req_suffixes=("sse4" "avx" "avx2" "avx512") ;; esac for suffix in "${arch_flag_req_suffixes[@]}"; do echo "${varprefix}_${suffix}_c_srcs = [" libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt "_${suffix}\\.c" echo "]" echo done echo "${varprefix}_c_srcs = [" libvpx_srcs_txt_to_c_srcs libvpx_srcs_$1.txt "\\.c$" "${negative_pattern}" echo "\"$LIBVPX_CONFIG_DIR/$1/vpx_config.c\"," echo "]" if grep -qE ".asm(.S)?$" libvpx_srcs_$1.txt; then echo echo "${varprefix}_asm_srcs = [" libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt libvpx_srcs_txt_to_asm_S_srcs libvpx_srcs_$1.txt echo "]" fi # Now collect the libvpxrc sources into variables. Note that we're only # interested in x86_64 for now, but this can be expanded later. if [[ "$1" == "x86_64" ]]; then varprefix=libvpxrc_${1//-/_} echo echo "${varprefix}_c_srcs = [" # Note the architecture specific files only need to be filtered out, not # added to libvpxrc specific variables (as is done with libvpx), because # this library uses 'static_libs' to link to libvpx. libvpx_srcs_txt_to_c_srcs libvpxrc_srcs_$1.txt "\\.c$" \ "${negative_pattern}" echo "]" echo echo "${varprefix}_cc_srcs = [" libvpxrc_srcs_txt_to_cc_srcs libvpxrc_srcs_$1.txt "\\.cc$" "" echo "]" echo echo "${varprefix}_asm_srcs = [" libvpx_srcs_txt_to_asm_srcs libvpxrc_srcs_$1.txt libvpx_srcs_txt_to_asm_S_srcs libvpxrc_srcs_$1.txt echo "]" fi echo ) > config_$1.bp } # The ARM assembly sources must be converted from ADS to GAS compatible format. # This step is only required for ARM. MIPS uses intrinsics exclusively and x86 # requires 'yasm' to pre-process its assembly files. function convert_arm_asm { find $BASE_DIR/$LIBVPX_CONFIG_DIR/arm-neon -name '*.asm.S' | xargs -r rm for src in $(grep ".asm$" libvpx_srcs_arm-neon.txt); do newsrc=$LIBVPX_CONFIG_DIR/arm-neon/$src.S mkdir -p $BASE_DIR/$(dirname $newsrc) perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl <$BASE_DIR/$LIBVPX_SRC_DIR/$src >$BASE_DIR/$newsrc echo $newsrc >>libvpx_srcs_arm-neon.txt done sed -i "/\.asm$/ d" libvpx_srcs_arm-neon.txt } echo "Create temporary directory." TEMP_DIR="../libvpx.temp" rm -rf $TEMP_DIR cp -R $LIBVPX_SRC_DIR $TEMP_DIR cd $TEMP_DIR echo "Generate config files." all_platforms="--enable-external-build --enable-realtime-only --enable-pic" all_platforms+=" --disable-install-docs" all_platforms+=" --size-limit=4096x3072 --enable-vp9-highbitdepth" gen_config_files x86 "--target=x86-linux-gcc ${all_platforms}" gen_config_files x86_64 "--target=x86_64-linux-gcc ${all_platforms}" gen_config_files arm-neon \ "--target=armv7-linux-gcc ${all_platforms} --disable-runtime-cpu-detect" gen_config_files arm64 "--target=armv8-linux-gcc ${all_platforms}" gen_config_files generic "--target=generic-gnu ${all_platforms}" echo "Remove temporary directory." cd $BASE_DIR rm -rf $TEMP_DIR echo "Lint libvpx configuration." lint_config x86 lint_config x86_64 lint_config arm-neon lint_config arm64 lint_config generic echo "Create temporary directory." TEMP_DIR="../libvpx.temp" rm -rf $TEMP_DIR cp -R $LIBVPX_SRC_DIR $TEMP_DIR cd $TEMP_DIR gen_rtcd_header x86 x86 gen_rtcd_header x86_64 x86_64 gen_rtcd_header arm-neon armv7 gen_rtcd_header arm64 armv8 gen_rtcd_header generic generic echo "Prepare Makefile." ./configure --target=generic-gnu > /dev/null make_clean echo "Generate source lists" gen_source_list x86 gen_source_list x86_64 gen_source_list arm-neon gen_source_list arm64 gen_source_list generic echo "Convert ARM assembly format" convert_arm_asm echo "Convert to bp" gen_bp_srcs x86 gen_bp_srcs x86_64 gen_bp_srcs arm-neon gen_bp_srcs arm64 gen_bp_srcs generic rm -f $BASE_DIR/Android.bp ( echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT" echo "// Generated from Android.bp.in, run ./post_update.sh to regenerate" echo cat config_*.bp cat $BASE_DIR/Android.bp.in ) > $BASE_DIR/Android.bp bpfmt -s -w "${BASE_DIR}/Android.bp" \ || echo "bpfmt not found. Run 'm bpfmt' followed by" \ "'bpfmt -s -w ${BASE_DIR}/Android.bp'." echo "Remove temporary directory." cd $BASE_DIR rm -rf $TEMP_DIR