xref: /freebsd/contrib/xz/doxygen/update-doxygen (revision 3b35e7ee8de9b0260149a2b77e87a2b9c7a36244)
1c917796cSXin LI#!/bin/sh
2*3b35e7eeSXin LI# SPDX-License-Identifier: 0BSD
3*3b35e7eeSXin LI
4c917796cSXin LI#############################################################################
5c917796cSXin LI#
6*3b35e7eeSXin LI# While it's possible to use the Doxyfile as is to generate liblzma API
7*3b35e7eeSXin LI# documentation, it is recommended to use this script because this adds
8*3b35e7eeSXin LI# the XZ Utils version number to the generated HTML.
9c917796cSXin LI#
10*3b35e7eeSXin LI# Other features:
11*3b35e7eeSXin LI#  - Generate documentation of the XZ Utils internals.
12*3b35e7eeSXin LI#  - Set input and output paths for out-of-tree builds.
13c917796cSXin LI#
14c917796cSXin LI#############################################################################
15c917796cSXin LI#
16c917796cSXin LI# Authors: Jia Tan
17c917796cSXin LI#          Lasse Collin
18c917796cSXin LI#
19c917796cSXin LI#############################################################################
20c917796cSXin LI
21c917796cSXin LIset -e
22c917796cSXin LI
23*3b35e7eeSXin LIshow_usage()
24*3b35e7eeSXin LI{
25*3b35e7eeSXin LI	echo "Usage: $0 <api|internal> [ABS_TOP_SRCDIR ABS_OUTDIR]"
26*3b35e7eeSXin LI	echo
27*3b35e7eeSXin LI	echo "Supported modes:"
28*3b35e7eeSXin LI	echo " - 'api' (default): liblzma API docs into doc/api"
29*3b35e7eeSXin LI	echo " - 'internal': internal docs into doc/internal"
30*3b35e7eeSXin LI	echo
31*3b35e7eeSXin LI	echo "Absolute source and output dirs may be set" \
32*3b35e7eeSXin LI		"to do an out-of-tree build."
33*3b35e7eeSXin LI	echo "The output directory must already exist."
34*3b35e7eeSXin LI	exit 1
35*3b35e7eeSXin LI}
36*3b35e7eeSXin LI
37*3b35e7eeSXin LIcase $1 in
38*3b35e7eeSXin LI	api|internal)
39*3b35e7eeSXin LI		;;
40*3b35e7eeSXin LI	*)
41*3b35e7eeSXin LI		show_usage
42*3b35e7eeSXin LI		;;
43*3b35e7eeSXin LIesac
44*3b35e7eeSXin LI
45c917796cSXin LIif type doxygen > /dev/null 2>&1; then
46c917796cSXin LI	:
47c917796cSXin LIelse
48*3b35e7eeSXin LI	echo "$0: 'doxygen' command not found" >&2
49c917796cSXin LI	exit 1
50c917796cSXin LIfi
51c917796cSXin LI
52*3b35e7eeSXin LIcase $# in
53*3b35e7eeSXin LI	1)
54*3b35e7eeSXin LI		# One argument: Building inside the source tree
55*3b35e7eeSXin LI		ABS_TOP_SRCDIR=`dirname "$0"`/..
56*3b35e7eeSXin LI		ABS_OUTDIR=$ABS_TOP_SRCDIR/doc
57*3b35e7eeSXin LI		;;
58*3b35e7eeSXin LI	3)
59*3b35e7eeSXin LI		# Three arguments: Possibly an out of tree build
60*3b35e7eeSXin LI		ABS_TOP_SRCDIR=$2
61*3b35e7eeSXin LI		ABS_OUTDIR=$3
62*3b35e7eeSXin LI		;;
63*3b35e7eeSXin LI	*)
64*3b35e7eeSXin LI		show_usage
65*3b35e7eeSXin LI		;;
66*3b35e7eeSXin LIesac
67*3b35e7eeSXin LI
68*3b35e7eeSXin LIif test ! -f "$ABS_TOP_SRCDIR/doxygen/Doxyfile"; then
69*3b35e7eeSXin LI	echo "$0: Source dir '$ABS_TOP_SRCDIR/doxygen/Doxyfile' not found" >&2
70c917796cSXin LI	exit 1
71c917796cSXin LIfi
72*3b35e7eeSXin LIif test ! -d "$ABS_OUTDIR"; then
73*3b35e7eeSXin LI	echo "$0: Output dir '$ABS_OUTDIR' not found" >&2
74*3b35e7eeSXin LI	exit 1
75c917796cSXin LIfi
76c917796cSXin LI
77c917796cSXin LI# Get the package version so that it can be included in the generated docs.
78*3b35e7eeSXin LIPACKAGE_VERSION=`cd "$ABS_TOP_SRCDIR" && sh build-aux/version.sh`
79c917796cSXin LI
80c917796cSXin LIcase $1 in
81*3b35e7eeSXin LI	api)
82c917796cSXin LI		# Remove old documentation before re-generating the new.
83*3b35e7eeSXin LI		rm -rf "$ABS_OUTDIR/api"
84c917796cSXin LI
85c917796cSXin LI		# Generate the HTML documentation by preparing the Doxyfile
86c917796cSXin LI		# in stdin and piping the result to the doxygen command.
87c917796cSXin LI		# With Doxygen, the last assignment of a value to a tag will
88c917796cSXin LI		# override any earlier assignment. So, we can use this
89c917796cSXin LI		# feature to override the tags that need to change between
90c917796cSXin LI		# "api" and "internal" modes.
91*3b35e7eeSXin LI		ABS_SRCDIR=$ABS_TOP_SRCDIR/src/liblzma/api
92c917796cSXin LI		(
93*3b35e7eeSXin LI			cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
94c917796cSXin LI			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
95*3b35e7eeSXin LI			echo "OUTPUT_DIRECTORY       = $ABS_OUTDIR"
96*3b35e7eeSXin LI			echo "STRIP_FROM_PATH        = $ABS_SRCDIR"
97*3b35e7eeSXin LI			echo "INPUT                  = $ABS_SRCDIR"
98*3b35e7eeSXin LI		) | doxygen -q -
99c917796cSXin LI		;;
100c917796cSXin LI
101c917796cSXin LI	internal)
102*3b35e7eeSXin LI		rm -rf "$ABS_OUTDIR/internal"
103c917796cSXin LI		(
104*3b35e7eeSXin LI			cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
105c917796cSXin LI			echo 'PROJECT_NAME           = "XZ Utils"'
106*3b35e7eeSXin LI			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
107*3b35e7eeSXin LI			echo "OUTPUT_DIRECTORY       = $ABS_OUTDIR"
108*3b35e7eeSXin LI			echo "STRIP_FROM_PATH        = $ABS_TOP_SRCDIR"
109*3b35e7eeSXin LI			echo "INPUT                  = $ABS_TOP_SRCDIR/src"
110c917796cSXin LI			echo 'HTML_OUTPUT            = internal'
111c917796cSXin LI			echo 'SEARCHENGINE           = YES'
112*3b35e7eeSXin LI		) | doxygen -q -
113c917796cSXin LI		;;
114c917796cSXin LIesac
115