• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
126gen_config_files arm64 "${toolchain}/arm64-linux-gcc.cmake ${all_platforms} \
127  -DENABLE_ARM_CRC32=0 -DENABLE_NEON_DOTPROD=0 -DENABLE_NEON_I8MM=0"
128
129reset_dirs riscv64
130gen_config_files riscv64 "${toolchain}/riscv-linux-gcc.cmake ${all_platforms}"
131)
132
133# libaom_srcs.gni was built for Chromium. Remove:
134# - the path prefix (//third_party/libaom/source/libaom/)
135# - comments (lines starting with #)
136# - header files
137# - inc files
138# - perl scripts (rtcd)
139
140rm -f "${BASE}/Android.bp"
141(
142  echo "// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE"
143  echo "//     CONSULT YOUR go/whichlawyer LEGAL TEAM MEMBER BEFORE"
144  echo "//     DEPENDING ON IT IN YOUR PROJECT. ***"
145  echo "// THIS FILE IS AUTOGENERATED, DO NOT EDIT"
146  echo "// Generated from Android.bp.in, run ./generate_config.sh to regenerate"
147  echo
148  cat "${BASE}/libaom_srcs.gni" |
149    grep -v ^\# |
150    sed 's/\/\/third_party\/libaom\/source\/libaom\///' |
151    grep -v -e 'h",$' -e 'inc",$' -e 'pl",$'
152  echo
153  cat "${BASE}/Android.bp.in"
154) > "${BASE}/Android.bp"
155
156rm -f "${BASE}/libaom_srcs.gni"
157bpfmt -s -w "${BASE}/Android.bp" \
158  || echo "bpfmt not found. Run 'm bpfmt' followed by" \
159          "'bpfmt -s -w ${BASE}/Android.bp'."
160
161clean
162