1#!/bin/bash 2# 3# Copyright (c) 2018 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 has been modified for use in Android. It is used to generate .bp 8# files and files in the config/ directories needed to build libaom. 9# 10# Every time the upstream source code is updated this script must be run. 11# 12# Usage: 13# $ ./generate_config.sh 14# Requirements: 15# Install the following Debian packages. 16# - cmake3 17# - yasm or nasm 18# Toolchain for armv7: 19# - gcc-arm-linux-gnueabihf 20# - g++-arm-linux-gnueabihf 21# Toolchain for arm64: 22# - gcc-aarch64-linux-gnu 23# - g++-aarch64-linux-gnu 24# Toolchain for riscv64: 25# - gcc-riscv64-linux-gnu 26# - g++-riscv64-linux-gnu 27# Toolchain for x86: 28# - gcc-i686-linux-gnu 29# - g++-i686-linux-gnu 30 31set -eE 32 33# sort() consistently. 34export LC_ALL=C 35 36BASE=$(pwd) 37SRC="${BASE}" 38CFG="${BASE}/config" 39TMP=$(mktemp -d "${BASE}/../build.XXXX") 40 41# Clean up and prepare config directory 42rm -rf "${CFG}" 43mkdir -p "${CFG}/config" 44 45function clean { 46 rm -rf "${TMP}" 47} 48 49# Create empty temp and config directories. 50# $1 - Header file directory. 51function reset_dirs { 52 cd "${BASE}" 53 rm -rf "${TMP}" 54 mkdir "${TMP}" 55 cd "${TMP}" 56 57 echo "Generate ${1} config files." 58 mkdir -p "${CFG}/${1}/config" 59} 60 61if [ $# -ne 0 ]; then 62 echo "Unknown option(s): ${@}" 63 exit 1 64fi 65 66# Missing function: 67# find_duplicates 68# We may have enough targets to avoid re-implementing this. 69 70# Generate Config files. 71# $1 - Header file directory. 72# $2 - cmake options. 73function gen_config_files { 74 cmake "${SRC}" ${2} &> cmake.txt 75 76 case "${1}" in 77 x86*) 78 egrep "#define [A-Z0-9_]+ [01]" config/aom_config.h | \ 79 awk '{print "%define " $2 " " $3}' > config/aom_config.asm 80 ;; 81 esac 82 83 cp config/aom_config.{h,c,asm} "${CFG}/${1}/config/" 84 85 cp config/*_rtcd.h "${CFG}/${1}/config/" 86 #clang-format -i "${CFG}/${1}/config/"*_rtcd.h 87} 88 89cd "${TMP}" 90 91# Scope 'trap' error reporting to configuration generation. 92( 93trap '{ 94 [ -f ${TMP}/cmake.txt ] && cat ${TMP}/cmake.txt 95 echo "Build directory ${TMP} not removed automatically." 96}' ERR 97 98all_platforms="-DCONFIG_SIZE_LIMIT=1" 99all_platforms+=" -DDECODE_HEIGHT_LIMIT=16384 -DDECODE_WIDTH_LIMIT=16384" 100all_platforms+=" -DCONFIG_AV1_ENCODER=1" 101all_platforms+=" -DCONFIG_AV1_HIGHBITDEPTH=1" 102all_platforms+=" -DCONFIG_MAX_DECODE_PROFILE=0" 103all_platforms+=" -DCONFIG_NORMAL_TILE_MODE=1" 104# Android requires ssse3. Simplify the build by disabling everything above that 105# and RTCD. 106all_platforms+=" -DENABLE_SSE4_1=0" 107all_platforms+=" -DCONFIG_RUNTIME_CPU_DETECT=0" 108 109toolchain="-DCMAKE_TOOLCHAIN_FILE=${SRC}/build/cmake/toolchains" 110 111reset_dirs x86 112gen_config_files x86 \ 113 "${toolchain}/i686-linux-gcc.cmake ${all_platforms} -DCONFIG_PIC=1" 114 115# libaom_srcs.gni and aom_version.h are shared. 116cp libaom_srcs.gni "${BASE}" 117cp config/aom_version.h "${CFG}/config/" 118 119reset_dirs x86_64 120gen_config_files x86_64 "${all_platforms}" 121 122reset_dirs arm 123gen_config_files arm "${toolchain}/armv7-linux-gcc.cmake ${all_platforms}" 124 125reset_dirs arm64 126# Note clang is use to allow detection of SVE/SVE2; gcc as of version 13 is 127# missing the required arm_neon_sve_bridge.h header. 128gen_config_files arm64 "${toolchain}/arm64-linux-clang.cmake ${all_platforms} \ 129 -DCONFIG_RUNTIME_CPU_DETECT=1" 130 131reset_dirs riscv64 132gen_config_files riscv64 "${toolchain}/riscv-linux-gcc.cmake ${all_platforms}" 133) 134 135# libaom_srcs.gni was built for Chromium. Remove: 136# - the path prefix (//third_party/libaom/source/libaom/) 137# - comments (lines starting with #) 138# - header files 139# - inc files 140# - perl scripts (rtcd) 141 142rm -f "${BASE}/Android.bp" 143( 144 echo "// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE" 145 echo "// CONSULT YOUR go/whichlawyer LEGAL TEAM MEMBER BEFORE" 146 echo "// DEPENDING ON IT IN YOUR PROJECT. ***" 147 echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT" 148 echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate" 149 echo 150 cat "${BASE}/libaom_srcs.gni" | 151 grep -v ^\# | 152 sed 's/\/\/third_party\/libaom\/source\/libaom\///' | 153 grep -v -e 'h",$' -e 'inc",$' -e 'pl",$' 154 echo 155 cat "${BASE}/Android.bp.in" 156) > "${BASE}/Android.bp" 157 158rm -f "${BASE}/libaom_srcs.gni" 159bpfmt -s -w "${BASE}/Android.bp" \ 160 || echo "bpfmt not found. Run 'm bpfmt' followed by" \ 161 "'bpfmt -s -w ${BASE}/Android.bp'." 162 163clean 164