summaryrefslogtreecommitdiffstats
path: root/doxygen/update-doxygen
blob: c5d6ad39f1b1e9ae2a14d45523262de2a9c0a023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
# SPDX-License-Identifier: 0BSD

#############################################################################
#
# While it's possible to use the Doxyfile as is to generate liblzma API
# documentation, it is recommended to use this script because this adds
# the XZ Utils version number to the generated HTML.
#
# Other features:
#  - Generate documentation of the XZ Utils internals.
#  - Set input and output paths for out-of-tree builds.
#
#############################################################################
#
# Authors: Jia Tan
#          Lasse Collin
#
#############################################################################

set -e

show_usage()
{
	echo "Usage: $0 <api|internal> [ABS_TOP_SRCDIR ABS_OUTDIR]"
	echo
	echo "Supported modes:"
	echo " - 'api' (default): liblzma API docs into doc/api"
	echo " - 'internal': internal docs into doc/internal"
	echo
	echo "Absolute source and output dirs may be set" \
		"to do an out-of-tree build."
	echo "The output directory must already exist."
	exit 1
}

case $1 in
	api|internal)
		;;
	*)
		show_usage
		;;
esac

if type doxygen > /dev/null 2>&1; then
	:
else
	echo "$0: 'doxygen' command not found" >&2
	exit 1
fi

case $# in
	1)
		# One argument: Building inside the source tree
		ABS_TOP_SRCDIR=`dirname "$0"`/..
		ABS_OUTDIR=$ABS_TOP_SRCDIR/doc
		;;
	3)
		# Three arguments: Possibly an out of tree build
		ABS_TOP_SRCDIR=$2
		ABS_OUTDIR=$3
		;;
	*)
		show_usage
		;;
esac

if test ! -f "$ABS_TOP_SRCDIR/doxygen/Doxyfile"; then
	echo "$0: Source dir '$ABS_TOP_SRCDIR/doxygen/Doxyfile' not found" >&2
	exit 1
fi
if test ! -d "$ABS_OUTDIR"; then
	echo "$0: Output dir '$ABS_OUTDIR' not found" >&2
	exit 1
fi

# Get the package version so that it can be included in the generated docs.
PACKAGE_VERSION=`cd "$ABS_TOP_SRCDIR" && sh build-aux/version.sh`

case $1 in
	api)
		# Remove old documentation before re-generating the new.
		rm -rf "$ABS_OUTDIR/api"

		# Generate the HTML documentation by preparing the Doxyfile
		# in stdin and piping the result to the doxygen command.
		# With Doxygen, the last assignment of a value to a tag will
		# override any earlier assignment. So, we can use this
		# feature to override the tags that need to change between
		# "api" and "internal" modes.
		ABS_SRCDIR=$ABS_TOP_SRCDIR/src/liblzma/api
		(
			cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
			echo "OUTPUT_DIRECTORY       = $ABS_OUTDIR"
			echo "STRIP_FROM_PATH        = $ABS_SRCDIR"
			echo "INPUT                  = $ABS_SRCDIR"
		) | doxygen -q -
		;;

	internal)
		rm -rf "$ABS_OUTDIR/internal"
		(
			cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
			echo 'PROJECT_NAME           = "XZ Utils"'
			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
			echo "OUTPUT_DIRECTORY       = $ABS_OUTDIR"
			echo "STRIP_FROM_PATH        = $ABS_TOP_SRCDIR"
			echo "INPUT                  = $ABS_TOP_SRCDIR/src"
			echo 'HTML_OUTPUT            = internal'
			echo 'SEARCHENGINE           = YES'
		) | doxygen -q -
		;;
esac