Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 2 | # |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 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. |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 6 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 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. |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 9 | # |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 10 | # Every time the upstream source code is updated this script must be run. |
| 11 | # |
| 12 | # Usage: |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 13 | # $ ./generate_config.sh |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 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 | # 32bit build environment for cmake. Including but potentially not limited to: |
| 25 | # - lib32gcc-7-dev |
| 26 | # - lib32stdc++-7-dev |
| 27 | # Alternatively: treat 32bit builds like Windows and manually tweak aom_config.h |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 28 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 29 | set -eE |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 30 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 31 | # sort() consistently. |
| 32 | export LC_ALL=C |
| 33 | |
| 34 | BASE=$(pwd) |
| 35 | SRC="${BASE}/libaom" |
| 36 | CFG="${BASE}/config" |
| 37 | TMP=$(mktemp -d "${BASE}/build.XXXX") |
| 38 | |
| 39 | # Clean up and prepare config directory |
| 40 | rm -rf "${CFG}" |
| 41 | mkdir -p "${CFG}/config" |
| 42 | |
| 43 | function clean { |
| 44 | rm -rf "${TMP}" |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 47 | # Create empty temp and config directories. |
| 48 | # $1 - Header file directory. |
| 49 | function reset_dirs { |
| 50 | cd "${BASE}" |
| 51 | rm -rf "${TMP}" |
| 52 | mkdir "${TMP}" |
| 53 | cd "${TMP}" |
| 54 | |
| 55 | echo "Generate ${1} config files." |
| 56 | mkdir -p "${CFG}/${1}/config" |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 59 | if [ $# -ne 0 ]; then |
| 60 | echo "Unknown option(s): ${@}" |
| 61 | exit 1 |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 62 | fi |
| 63 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 64 | # Missing function: |
| 65 | # find_duplicates |
| 66 | # We may have enough targets to avoid re-implementing this. |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 67 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 68 | # Generate Config files. |
| 69 | # $1 - Header file directory. |
| 70 | # $2 - cmake options. |
| 71 | function gen_config_files { |
| 72 | cmake "${SRC}" ${2} &> cmake.txt |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 73 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 74 | case "${1}" in |
| 75 | x86*) |
| 76 | egrep "#define [A-Z0-9_]+ [01]" config/aom_config.h | \ |
| 77 | awk '{print "%define " $2 " " $3}' > config/aom_config.asm |
| 78 | ;; |
| 79 | esac |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 80 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 81 | cp config/aom_config.{h,c,asm} "${CFG}/${1}/config/" |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 82 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 83 | cp config/*_rtcd.h "${CFG}/${1}/config/" |
| 84 | #clang-format -i "${CFG}/${1}/config/"*_rtcd.h |
| 85 | } |
| 86 | |
| 87 | function update_readme { |
| 88 | local IFS=$'\n' |
| 89 | # Split git log output '<date>\n<commit hash>' on the newline to produce 2 |
| 90 | # array entries. |
| 91 | local vals=($(git -C "${SRC}" --no-pager log -1 --format="%cd%n%H" \ |
| 92 | --date=format:"%A %B %d %Y")) |
| 93 | sed -E -i.bak \ |
| 94 | -e "s/^(Date:)[[:space:]]+.*$/\1 ${vals[0]}/" \ |
| 95 | -e "s/^(Commit:)[[:space:]]+[a-f0-9]{40}/\1 ${vals[1]}/" \ |
| 96 | ${BASE}/README.android |
| 97 | rm ${BASE}/README.android.bak |
| 98 | cat <<EOF |
| 99 | |
| 100 | README.android updated with: |
| 101 | Date: ${vals[0]} |
| 102 | Commit: ${vals[1]} |
| 103 | EOF |
| 104 | } |
| 105 | |
| 106 | cd "${TMP}" |
| 107 | |
| 108 | # Scope 'trap' error reporting to configuration generation. |
| 109 | ( |
| 110 | trap '{ |
| 111 | [ -f ${TMP}/cmake.txt ] && cat ${TMP}/cmake.txt |
| 112 | echo "Build directory ${TMP} not removed automatically." |
| 113 | }' ERR |
| 114 | |
| 115 | all_platforms="-DCONFIG_SIZE_LIMIT=1" |
| 116 | all_platforms+=" -DDECODE_HEIGHT_LIMIT=16384 -DDECODE_WIDTH_LIMIT=16384" |
| 117 | all_platforms+=" -DCONFIG_AV1_ENCODER=0" |
| 118 | all_platforms+=" -DCONFIG_LOWBITDEPTH=1" |
| 119 | all_platforms+=" -DCONFIG_MAX_DECODE_PROFILE=0" |
| 120 | all_platforms+=" -DCONFIG_NORMAL_TILE_MODE=1" |
| 121 | # Android requires ssse3. Simplify the build by disabling everything above that |
| 122 | # and RTCD. |
| 123 | all_platforms+=" -DENABLE_SSE4_1=0" |
| 124 | all_platforms+=" -DCONFIG_RUNTIME_CPU_DETECT=0" |
| 125 | |
| 126 | toolchain="-DCMAKE_TOOLCHAIN_FILE=${SRC}/build/cmake/toolchains" |
| 127 | |
| 128 | reset_dirs x86 |
Johann | 3d220f9 | 2019-01-11 12:43:22 -0800 | [diff] [blame] | 129 | gen_config_files x86 "${toolchain}/x86-linux.cmake ${all_platforms} -DCONFIG_PIC=1" |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 130 | |
| 131 | # libaom_srcs.gni and aom_version.h are shared. |
| 132 | cp libaom_srcs.gni "${BASE}" |
| 133 | cp config/aom_version.h "${CFG}/config/" |
| 134 | |
| 135 | reset_dirs x86_64 |
| 136 | gen_config_files x86_64 "${all_platforms}" |
| 137 | |
| 138 | reset_dirs arm |
| 139 | gen_config_files arm "${toolchain}/armv7-linux-gcc.cmake ${all_platforms}" |
| 140 | |
| 141 | reset_dirs arm64 |
| 142 | gen_config_files arm64 "${toolchain}/arm64-linux-gcc.cmake ${all_platforms}" |
| 143 | ) |
| 144 | |
| 145 | # This needs to be run by update_libaom.sh before the .git file is removed. |
| 146 | #update_readme |
| 147 | |
| 148 | # libaom_srcs.gni was built for Chromium. Remove: |
| 149 | # - the path prefix (//third_party/libaom/source/) |
| 150 | # - comments (lines starting with #) |
| 151 | # - header files |
| 152 | # - perl scripts (rtcd) |
| 153 | |
Johann | 38edf10 | 2019-01-11 12:45:55 -0800 | [diff] [blame] | 154 | rm -f "${BASE}/Android.bp" |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 155 | ( |
| 156 | echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT" |
| 157 | echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate" |
| 158 | echo |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 159 | cat "${BASE}/libaom_srcs.gni" | |
| 160 | grep -v ^\# | |
| 161 | sed 's/\/\/third_party\/libaom\/source\///' | |
| 162 | grep -v h\",$ | |
| 163 | grep -v pl\",$ |
| 164 | cat "${BASE}/Android.bp.in" |
| 165 | ) > "${BASE}/Android.bp" |
Johann | 38edf10 | 2019-01-11 12:45:55 -0800 | [diff] [blame] | 166 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 167 | rm -f "${BASE}/libaom_srcs.gni" |
Johann | 38edf10 | 2019-01-11 12:45:55 -0800 | [diff] [blame] | 168 | bpfmt -w "${BASE}/Android.bp" || echo "bpfmt not found: format Android.bp manually." |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 169 | |
Ray Essick | 247da04 | 2018-11-29 14:14:00 -0800 | [diff] [blame] | 170 | |
Johann | 39f1322 | 2019-01-09 11:48:14 -0800 | [diff] [blame] | 171 | clean |