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 20export LC_ALL=C 21cd $(dirname $0) 22BASE_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 { 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 38} 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. 66# $3 - Optional - any additional arguments to pass through. 67function gen_rtcd_header { 68 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files." 69 70 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config 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 75 76 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 77 --arch=$2 \ 78 --sym=vp8_rtcd $3 \ 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 \ 85 --sym=vp9_rtcd $3 \ 86 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 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 \ 92 --sym=vpx_scale_rtcd $3 \ 93 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 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 \ 99 --sym=vpx_dsp_rtcd $3 \ 100 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 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. 111function gen_config_files { 112 ./configure $2 > /dev/null 113 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 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 133# Generate a text file containing sources for a config 134# $1 - Config 135function gen_source_list { 136 make_clean 137 if [[ "$1" = "generic" ]]; then 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 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 158# 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 164# Convert a list of sources to a blueprint file containing a variable 165# assignment. 166# $1 - Config 167function gen_bp_srcs { 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\"," 173 echo "]" 174 if grep -qE ".asm(.S)?$" libvpx_srcs_$1.txt; then 175 echo 176 echo "${varprefix}_asm_srcs = [" 177 libvpx_srcs_txt_to_asm_srcs libvpx_srcs_$1.txt 178 libvpx_srcs_txt_to_asm_S_srcs libvpx_srcs_$1.txt 179 echo "]" 180 fi 181 echo 182 ) > config_$1.bp 183} 184 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. 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 199echo "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." 206all_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" 209intel="--disable-sse4_1 --disable-avx --disable-avx2 --disable-avx512 --as=yasm" 210gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}" 211gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}" 212gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}" 213gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}" 214gen_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 223lint_config arm-neon 224lint_config arm64 225lint_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 233gen_rtcd_header x86 x86 "${intel}" 234gen_rtcd_header x86_64 x86_64 "${intel}" 235gen_rtcd_header arm-neon armv7 236gen_rtcd_header arm64 armv8 237gen_rtcd_header generic generic 238 239echo "Prepare Makefile." 240./configure --target=generic-gnu > /dev/null 241make_clean 242 243echo "Generate source lists" 244gen_source_list x86 245gen_source_list x86_64 246gen_source_list arm-neon 247gen_source_list arm64 248gen_source_list generic 249 250echo "Convert ARM assembly format" 251convert_arm_asm 252 253echo "Convert to bp" 254gen_bp_srcs x86 255gen_bp_srcs x86_64 256gen_bp_srcs arm-neon 257gen_bp_srcs arm64 258gen_bp_srcs generic 259 260rm -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 269 270echo "Remove temporary directory." 271cd $BASE_DIR 272rm -rf $TEMP_DIR 273