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