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# $ ./post_update.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 36cd $(dirname $0) 37BASE=$(pwd) 38SRC="${BASE}" 39CFG="${BASE}/config" 40TMP=$(mktemp -d "${BASE}/../build.XXXX") 41 42# Clean up and prepare config directory 43rm -rf "${CFG}" 44mkdir -p "${CFG}/config" 45 46function clean { 47 rm -rf "${TMP}" 48} 49 50# Create empty temp and config directories. 51# $1 - Header file directory. 52function reset_dirs { 53 cd "${BASE}" 54 rm -rf "${TMP}" 55 mkdir "${TMP}" 56 cd "${TMP}" 57 58 echo "Generate ${1} config files." 59 mkdir -p "${CFG}/${1}/config" 60} 61 62# Missing function: 63# find_duplicates 64# We may have enough targets to avoid re-implementing this. 65 66# Generate Config files. 67# $1 - Header file directory. 68# $2 - cmake options. 69function gen_config_files { 70 cmake "${SRC}" ${2} &> cmake.txt 71 72 case "${1}" in 73 x86*) 74 egrep "#define [A-Z0-9_]+ [01]" config/aom_config.h | \ 75 awk '{print "%define " $2 " " $3}' > config/aom_config.asm 76 ;; 77 esac 78 79 cp config/aom_config.{h,c,asm} "${CFG}/${1}/config/" 80 81 cp config/*_rtcd.h "${CFG}/${1}/config/" 82 #clang-format -i "${CFG}/${1}/config/"*_rtcd.h 83} 84 85cd "${TMP}" 86 87# Scope 'trap' error reporting to configuration generation. 88( 89trap '{ 90 [ -f ${TMP}/cmake.txt ] && cat ${TMP}/cmake.txt 91 echo "Build directory ${TMP} not removed automatically." 92}' ERR 93 94all_platforms="-DCONFIG_SIZE_LIMIT=1" 95all_platforms+=" -DDECODE_HEIGHT_LIMIT=16384 -DDECODE_WIDTH_LIMIT=16384" 96all_platforms+=" -DCONFIG_AV1_ENCODER=1" 97all_platforms+=" -DCONFIG_AV1_HIGHBITDEPTH=1" 98all_platforms+=" -DCONFIG_MAX_DECODE_PROFILE=0" 99all_platforms+=" -DCONFIG_NORMAL_TILE_MODE=1" 100all_platforms+=" -DCONFIG_PIC=1" 101 102toolchain="-DCMAKE_TOOLCHAIN_FILE=${SRC}/build/cmake/toolchains" 103 104reset_dirs x86 105gen_config_files x86 "${toolchain}/i686-linux-gcc.cmake ${all_platforms}" 106 107# libaom_srcs.gni and aom_version.h are shared. 108cp libaom_srcs.gni "${BASE}" 109cp config/aom_version.h "${CFG}/config/" 110 111reset_dirs x86_64 112gen_config_files x86_64 "${all_platforms}" 113 114reset_dirs arm 115gen_config_files arm "${toolchain}/armv7-linux-gcc.cmake ${all_platforms} \ 116 -DCONFIG_RUNTIME_CPU_DETECT=0" 117 118reset_dirs arm64 119# Note clang is used to allow detection of SVE/SVE2; gcc as of version 13 is 120# missing the required arm_neon_sve_bridge.h header. 121gen_config_files arm64 "${toolchain}/arm64-linux-clang.cmake ${all_platforms}" 122 123reset_dirs riscv64 124gen_config_files riscv64 "${toolchain}/riscv-linux-gcc.cmake ${all_platforms}" 125) 126 127# libaom_srcs.gni was built for Chromium. Remove: 128# - the path prefix (//third_party/libaom/source/libaom/) 129# - comments (lines starting with #) 130# - header files 131# - inc files 132# - perl scripts (rtcd) 133 134rm -f "${BASE}/Android.bp" 135( 136 echo "// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE" 137 echo "// CONSULT YOUR go/whichlawyer LEGAL TEAM MEMBER BEFORE" 138 echo "// DEPENDING ON IT IN YOUR PROJECT. ***" 139 echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT" 140 echo "// Generated from Android.bp.in, run ./post_update.sh to regenerate" 141 echo 142 cat "${BASE}/libaom_srcs.gni" | 143 grep -v ^\# | 144 sed 's/\/\/third_party\/libaom\/source\/libaom\///' | 145 grep -v -e 'h",$' -e 'inc",$' -e 'pl",$' 146 echo 147 cat "${BASE}/Android.bp.in" 148) > "${BASE}/Android.bp" 149 150rm -f "${BASE}/libaom_srcs.gni" 151bpfmt -s -w "${BASE}/Android.bp" \ 152 || echo "bpfmt not found. Run 'm bpfmt' followed by" \ 153 "'bpfmt -s -w ${BASE}/Android.bp'." 154 155clean 156