blob: ca5aeed69b4c961dc8ad5bfbd7dbe725ca1bd106 [file] [log] [blame]
Lajos Molnar5a208a02024-01-23 09:39:32 -08001#!/bin/bash
2# Copyright (C) 2024 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# =============================================================================
17# DOCUMENTATION GENERATION
18# =============================================================================
19
20if [ -z "$ANDROID_BUILD_TOP" ]; then
21 echo "error: Android build is not set up. Run this command after lunch." >&2
22 exit 2
23fi
24
25OUT_DIR=$ANDROID_BUILD_TOP/out
26
27# Codec 2.0 source and target paths
28C2_ROOT=$(dirname "$0")
29C2_DOCS_ROOT=$OUT_DIR/target/common/docs/codec2
30C2_OUT_TEMP=$ANDROID_PRODUCT_OUT/gen/ETC/Codec2-docs_intermediates
31
32# Doxygen path
33DOXY=$(which doxygen)
34DOXY_MAC="/Applications/Doxygen.app/Contents/Resources/doxygen"
35if [ -z "$DOXY" -a -x "$DOXY_MAC" ]; then
36 DOXY=$DOXY_MAC
37fi
38
39if [ -z "$DOXY" ]; then
40 echo "error: doxygen is not available" >&2
41 exit 2
42fi
43
44# Create doxygen config
45# ---------------------
46gen_doxy() {
47 local variant=$1
48 local variant_lc=$(echo $variant | tr A-Z a-z)
49 mkdir -p $C2_OUT_TEMP
50 if [ "$variant_lc" == "api" ]; then
51 # only document include directory, no internal sections
52 sed 's/\(^INPUT *=.*\)/\1core\/include\//;
53 s/\(^INTERNAL_DOCS *= *\).*/\1NO/;
54 s/\(^ENABLED_SECTIONS *=.*\)INTERNAL\(.*\).*/\1\2/;
55 s:\(^OUTPUT_DIRECTORY *= \)out\(.*\)api:\1'$OUT_DIR'\2'$variant_lc':;' \
56 $C2_ROOT/docs/doxygen.config > $C2_OUT_TEMP/doxy-$variant_lc.config
57
58 ls -la $C2_OUT_TEMP/doxy-$variant_lc.config
59 else
60 sed 's:\(^OUTPUT_DIRECTORY *= \)out\(.*\)api:\1'$OUT_DIR'\2'$variant_lc':;' \
61 $C2_ROOT/docs/doxygen.config > $C2_OUT_TEMP/doxy-$variant_lc.config
62 fi
63
64 echo $variant docs are building in $C2_DOCS_ROOT/$variant_lc
65 rm -rf $C2_DOCS_ROOT/$variant_lc
66 mkdir -p $C2_DOCS_ROOT/$variant_lc
67 pushd $ANDROID_BUILD_TOP
68 $DOXY $C2_OUT_TEMP/doxy-$variant_lc.config
69 popd
70}
71
72usage() {
73 echo "usage: $(basename "$0") [target]"
74 echo " where target can be one of:"
75 echo " all: build both API and internal docs (default)"
76 echo " api: build API docs only"
77 echo " internal: build internal docs which include implementation details"
78}
79
80TARGET=${1:-all}
81case "$TARGET" in
82 api) gen_doxy API;;
83 internal) gen_doxy Internal;;
84 all) gen_doxy API; gen_doxy Internal;;
85 -h) usage; exit 0;;
86 *) echo "unknown target '$TARGET'" >&2; usage; exit 2;;
87esac