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 15export LC_ALL=C 16BASE_DIR=$(pwd) 17LIBVPX_SRC_DIR="libvpx" 18LIBVPX_CONFIG_DIR="config" 19 20# Clean files from previous make. 21function 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. 28function 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. 40function 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. 50function 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# $3 - Optional - any additional arguments to pass through. 65function gen_rtcd_header { 66 echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files." 67 68 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config 69 if [[ "$2" == *mips* ]]; then 70 print_config_basic $1 > $BASE_DIR/$TEMP_DIR/libvpx.config 71 else 72 $BASE_DIR/lint_config.sh -p \ 73 -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \ 74 -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \ 75 -o $BASE_DIR/$TEMP_DIR/libvpx.config 76 fi 77 78 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 79 --arch=$2 \ 80 --sym=vp8_rtcd $3 \ 81 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 82 $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \ 83 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h 84 85 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 86 --arch=$2 \ 87 --sym=vp9_rtcd $3 \ 88 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 89 $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \ 90 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h 91 92 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 93 --arch=$2 \ 94 --sym=vpx_scale_rtcd $3 \ 95 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 96 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \ 97 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h 98 99 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \ 100 --arch=$2 \ 101 --sym=vpx_dsp_rtcd $3 \ 102 --config=$BASE_DIR/$TEMP_DIR/libvpx.config \ 103 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \ 104 > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h 105 106 rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config 107} 108 109# Generate Config files. "--enable-external-build" must be set to skip 110# detection of capabilities on specific targets. 111# $1 - Header file directory. 112# $2 - Config command line. 113function gen_config_files { 114 ./configure $2 > /dev/null 115 116 # Generate vpx_config.asm. Do not create one for mips. 117 if [[ "$1" != *mips* ]]; then 118 if [[ "$1" == *x86* ]]; then 119 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ 120 | awk '{print "%define " $2 " " $3}' > vpx_config.asm 121 else 122 egrep "#define [A-Z0-9_]+ [01]" vpx_config.h \ 123 | awk '{print $2 " EQU " $3}' \ 124 | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/ads2gas.pl > vpx_config.asm 125 fi 126 fi 127 128 # Generate vpx_version.h 129 $BASE_DIR/$LIBVPX_SRC_DIR/build/make/version.sh "$BASE_DIR/$LIBVPX_SRC_DIR" vpx_version.h 130 131 cp vpx_config.* vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1 132 make_clean 133 rm -rf vpx_config.* vpx_version.h 134} 135 136echo "Create temporary directory." 137TEMP_DIR="$LIBVPX_SRC_DIR.temp" 138rm -rf $TEMP_DIR 139cp -R $LIBVPX_SRC_DIR $TEMP_DIR 140cd $TEMP_DIR 141 142echo "Generate config files." 143all_platforms="--enable-external-build --enable-realtime-only --enable-pic --disable-runtime-cpu-detect --disable-install-docs --size-limit=4096x3072" 144intel="--disable-sse4_1 --disable-avx --disable-avx2 --as=yasm" 145gen_config_files x86 "--target=x86-linux-gcc ${intel} ${all_platforms}" 146gen_config_files x86_64 "--target=x86_64-linux-gcc ${intel} ${all_platforms}" 147gen_config_files arm "--target=armv7-linux-gcc --disable-neon ${all_platforms}" 148gen_config_files arm-neon "--target=armv7-linux-gcc ${all_platforms}" 149gen_config_files arm64 "--force-target=armv8-linux-gcc ${all_platforms}" 150gen_config_files mips32 "--target=mips32-linux-gcc --disable-dspr2 --disable-msa ${all_platforms}" 151gen_config_files mips32-dspr2 "--target=mips32-linux-gcc --enable-dspr2 ${all_platforms}" 152gen_config_files mips32-msa "--target=mips32-linux-gcc --enable-msa ${all_platforms}" 153gen_config_files mips64 "--target=mips64-linux-gcc --disable-msa ${all_platforms}" 154gen_config_files mips64-msa "--target=mips64-linux-gcc --enable-msa ${all_platforms}" 155gen_config_files generic "--target=generic-gnu ${all_platforms}" 156 157echo "Remove temporary directory." 158cd $BASE_DIR 159rm -rf $TEMP_DIR 160 161echo "Lint libvpx configuration." 162lint_config x86 163lint_config x86_64 164lint_config arm 165lint_config arm-neon 166lint_config arm64 167lint_config mips32 168lint_config mips32-dspr2 169lint_config mips32-msa 170lint_config mips64 171lint_config mips64-msa 172lint_config generic 173 174echo "Create temporary directory." 175TEMP_DIR="$LIBVPX_SRC_DIR.temp" 176rm -rf $TEMP_DIR 177cp -R $LIBVPX_SRC_DIR $TEMP_DIR 178cd $TEMP_DIR 179 180gen_rtcd_header x86 x86 "${intel}" 181gen_rtcd_header x86_64 x86_64 "${intel}" 182gen_rtcd_header arm armv7 "--disable-neon" 183gen_rtcd_header arm-neon armv7 184gen_rtcd_header arm64 armv8 185gen_rtcd_header mips32 mips32 186gen_rtcd_header mips32-dspr2 mips32 187gen_rtcd_header mips32-msa mips32 188gen_rtcd_header mips64 mips64 189gen_rtcd_header mips64-msa mips64 190gen_rtcd_header generic generic 191 192echo "Prepare Makefile." 193./configure --target=generic-gnu > /dev/null 194make_clean 195 196echo "Generate X86 source list." 197config=$(print_config x86) 198make_clean 199make libvpx_srcs.txt target=libs $config > /dev/null 200cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/x86/ 201 202echo "Generate X86_64 source list." 203config=$(print_config x86_64) 204make_clean 205make libvpx_srcs.txt target=libs $config > /dev/null 206cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/x86_64/ 207 208echo "Generate ARM source list." 209config=$(print_config arm) 210make_clean 211make libvpx_srcs.txt target=libs $config > /dev/null 212cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm/ 213 214echo "Generate ARM NEON source list." 215config=$(print_config arm-neon) 216make_clean 217make libvpx_srcs.txt target=libs $config > /dev/null 218cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm-neon/ 219 220echo "Generate ARM64 source list." 221config=$(print_config arm64) 222make_clean 223make libvpx_srcs.txt target=libs $config > /dev/null 224cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/arm64/ 225 226echo "Generate MIPS source list." 227config=$(print_config_basic mips32) 228make_clean 229make libvpx_srcs.txt target=libs $config > /dev/null 230cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips32/ 231 232echo "Generate MIPS DSPR2 source list." 233config=$(print_config_basic mips32-dspr2) 234make_clean 235make libvpx_srcs.txt target=libs $config > /dev/null 236cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips32-dspr2/ 237 238echo "Generate MIPS MSA source list." 239config=$(print_config_basic mips32-msa) 240make_clean 241make libvpx_srcs.txt target=libs $config > /dev/null 242cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips32-msa/ 243 244echo "Generate MIPS64 source list." 245config=$(print_config_basic mips64) 246make_clean 247make libvpx_srcs.txt target=libs $config > /dev/null 248cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips64/ 249 250echo "Generate MIPS64 MSA source list." 251config=$(print_config_basic mips64-msa) 252make_clean 253make libvpx_srcs.txt target=libs $config > /dev/null 254cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/mips64-msa/ 255 256echo "Generate GENERIC source list." 257config=$(print_config_basic generic) 258make_clean 259make libvpx_srcs.txt target=libs $config > /dev/null 260cp libvpx_srcs.txt $BASE_DIR/$LIBVPX_CONFIG_DIR/generic/ 261 262 263echo "Remove temporary directory." 264cd $BASE_DIR 265rm -rf $TEMP_DIR 266