blob: 0de85a35ceaaae28816c0af5de1168966ec01f07 [file] [log] [blame]
Johann39f13222019-01-09 11:48:14 -08001#!/bin/bash
Ray Essick247da042018-11-29 14:14:00 -08002#
Johann39f13222019-01-09 11:48:14 -08003# 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 Essick247da042018-11-29 14:14:00 -08006
Johann39f13222019-01-09 11:48:14 -08007# 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 Essick247da042018-11-29 14:14:00 -08009#
Johann39f13222019-01-09 11:48:14 -080010# Every time the upstream source code is updated this script must be run.
11#
12# Usage:
Ray Essick247da042018-11-29 14:14:00 -080013# $ ./generate_config.sh
Johann39f13222019-01-09 11:48:14 -080014# 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 Essick247da042018-11-29 14:14:00 -080028
Johann39f13222019-01-09 11:48:14 -080029set -eE
Ray Essick247da042018-11-29 14:14:00 -080030
Johann39f13222019-01-09 11:48:14 -080031# sort() consistently.
32export LC_ALL=C
33
34BASE=$(pwd)
35SRC="${BASE}/libaom"
36CFG="${BASE}/config"
37TMP=$(mktemp -d "${BASE}/build.XXXX")
38
39# Clean up and prepare config directory
40rm -rf "${CFG}"
41mkdir -p "${CFG}/config"
42
43function clean {
44 rm -rf "${TMP}"
Ray Essick247da042018-11-29 14:14:00 -080045}
46
Johann39f13222019-01-09 11:48:14 -080047# Create empty temp and config directories.
48# $1 - Header file directory.
49function 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 Essick247da042018-11-29 14:14:00 -080057}
58
Johann39f13222019-01-09 11:48:14 -080059if [ $# -ne 0 ]; then
60 echo "Unknown option(s): ${@}"
61 exit 1
Ray Essick247da042018-11-29 14:14:00 -080062fi
63
Johann39f13222019-01-09 11:48:14 -080064# Missing function:
65# find_duplicates
66# We may have enough targets to avoid re-implementing this.
Ray Essick247da042018-11-29 14:14:00 -080067
Johann39f13222019-01-09 11:48:14 -080068# Generate Config files.
69# $1 - Header file directory.
70# $2 - cmake options.
71function gen_config_files {
72 cmake "${SRC}" ${2} &> cmake.txt
Ray Essick247da042018-11-29 14:14:00 -080073
Johann39f13222019-01-09 11:48:14 -080074 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 Essick247da042018-11-29 14:14:00 -080080
Johann39f13222019-01-09 11:48:14 -080081 cp config/aom_config.{h,c,asm} "${CFG}/${1}/config/"
Ray Essick247da042018-11-29 14:14:00 -080082
Johann39f13222019-01-09 11:48:14 -080083 cp config/*_rtcd.h "${CFG}/${1}/config/"
84 #clang-format -i "${CFG}/${1}/config/"*_rtcd.h
85}
86
87function 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
100README.android updated with:
101Date: ${vals[0]}
102Commit: ${vals[1]}
103EOF
104}
105
106cd "${TMP}"
107
108# Scope 'trap' error reporting to configuration generation.
109(
110trap '{
111 [ -f ${TMP}/cmake.txt ] && cat ${TMP}/cmake.txt
112 echo "Build directory ${TMP} not removed automatically."
113}' ERR
114
115all_platforms="-DCONFIG_SIZE_LIMIT=1"
116all_platforms+=" -DDECODE_HEIGHT_LIMIT=16384 -DDECODE_WIDTH_LIMIT=16384"
117all_platforms+=" -DCONFIG_AV1_ENCODER=0"
118all_platforms+=" -DCONFIG_LOWBITDEPTH=1"
119all_platforms+=" -DCONFIG_MAX_DECODE_PROFILE=0"
120all_platforms+=" -DCONFIG_NORMAL_TILE_MODE=1"
121# Android requires ssse3. Simplify the build by disabling everything above that
122# and RTCD.
123all_platforms+=" -DENABLE_SSE4_1=0"
124all_platforms+=" -DCONFIG_RUNTIME_CPU_DETECT=0"
125
126toolchain="-DCMAKE_TOOLCHAIN_FILE=${SRC}/build/cmake/toolchains"
127
128reset_dirs x86
Johann3d220f92019-01-11 12:43:22 -0800129gen_config_files x86 "${toolchain}/x86-linux.cmake ${all_platforms} -DCONFIG_PIC=1"
Johann39f13222019-01-09 11:48:14 -0800130
131# libaom_srcs.gni and aom_version.h are shared.
132cp libaom_srcs.gni "${BASE}"
133cp config/aom_version.h "${CFG}/config/"
134
135reset_dirs x86_64
136gen_config_files x86_64 "${all_platforms}"
137
138reset_dirs arm
139gen_config_files arm "${toolchain}/armv7-linux-gcc.cmake ${all_platforms}"
140
141reset_dirs arm64
142gen_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
Johann38edf102019-01-11 12:45:55 -0800154rm -f "${BASE}/Android.bp"
Ray Essick247da042018-11-29 14:14:00 -0800155(
156 echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT"
157 echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate"
158 echo
Johann39f13222019-01-09 11:48:14 -0800159 cat "${BASE}/libaom_srcs.gni" |
160 grep -v ^\# |
161 sed 's/\/\/third_party\/libaom\/source\///' |
162 grep -v h\",$ |
163 grep -v pl\",$
James Zernc69f4f72021-10-14 12:23:33 -0700164 echo
Johann39f13222019-01-09 11:48:14 -0800165 cat "${BASE}/Android.bp.in"
166) > "${BASE}/Android.bp"
Johann38edf102019-01-11 12:45:55 -0800167
Johann39f13222019-01-09 11:48:14 -0800168rm -f "${BASE}/libaom_srcs.gni"
Johann38edf102019-01-11 12:45:55 -0800169bpfmt -w "${BASE}/Android.bp" || echo "bpfmt not found: format Android.bp manually."
Ray Essick247da042018-11-29 14:14:00 -0800170
Ray Essick247da042018-11-29 14:14:00 -0800171
Johann39f13222019-01-09 11:48:14 -0800172clean