xref: /freebsd-src/contrib/xz/doxygen/update-doxygen (revision c917796c041664a04153af24c2e68cc963fe52bc)
1*c917796cSXin LI#!/bin/sh
2*c917796cSXin LI#
3*c917796cSXin LI#############################################################################
4*c917796cSXin LI#
5*c917796cSXin LI# Updates the Doxygen generated documentation files in the source tree.
6*c917796cSXin LI# If the doxygen command is not installed, it will exit with an error.
7*c917796cSXin LI# This script can generate Doxygen documentation for all source files or for
8*c917796cSXin LI# just liblzma API header files.
9*c917796cSXin LI#
10*c917796cSXin LI# It is recommended to use this script to update the Doxygen-generated HTML
11*c917796cSXin LI# files since this will include the package version in the output and,
12*c917796cSXin LI# in case of liblzma API docs, strip JavaScript files from the output.
13*c917796cSXin LI#
14*c917796cSXin LI#############################################################################
15*c917796cSXin LI#
16*c917796cSXin LI# Authors: Jia Tan
17*c917796cSXin LI#          Lasse Collin
18*c917796cSXin LI#
19*c917796cSXin LI# This file has been put into the public domain.
20*c917796cSXin LI# You can do whatever you want with this file.
21*c917796cSXin LI#
22*c917796cSXin LI#############################################################################
23*c917796cSXin LI
24*c917796cSXin LIset -e
25*c917796cSXin LI
26*c917796cSXin LIif type doxygen > /dev/null 2>&1; then
27*c917796cSXin LI	:
28*c917796cSXin LIelse
29*c917796cSXin LI	echo "doxygen/update-doxygen: 'doxygen' command not found." >&2
30*c917796cSXin LI	echo "doxygen/update-doxygen: Skipping Doxygen docs generation." >&2
31*c917796cSXin LI	exit 1
32*c917796cSXin LIfi
33*c917796cSXin LI
34*c917796cSXin LIif test ! -f Doxyfile; then
35*c917796cSXin LI	cd `dirname "$0"` || exit 1
36*c917796cSXin LI	if test ! -f Doxyfile; then
37*c917796cSXin LI		echo "doxygen/update-doxygen: Cannot find Doxyfile" >&2
38*c917796cSXin LI		exit 1
39*c917796cSXin LI	fi
40*c917796cSXin LIfi
41*c917796cSXin LI
42*c917796cSXin LI# Get the package version so that it can be included in the generated docs.
43*c917796cSXin LIPACKAGE_VERSION=`cd .. && sh build-aux/version.sh` || exit 1
44*c917796cSXin LI
45*c917796cSXin LI# If no arguments are specified, default to generating liblzma API header
46*c917796cSXin LI# documentation only.
47*c917796cSXin LIcase $1 in
48*c917796cSXin LI	'' | api)
49*c917796cSXin LI		# Remove old documentation before re-generating the new.
50*c917796cSXin LI		rm -rf ../doc/api
51*c917796cSXin LI
52*c917796cSXin LI		# Generate the HTML documentation by preparing the Doxyfile
53*c917796cSXin LI		# in stdin and piping the result to the doxygen command.
54*c917796cSXin LI		# With Doxygen, the last assignment of a value to a tag will
55*c917796cSXin LI		# override any earlier assignment. So, we can use this
56*c917796cSXin LI		# feature to override the tags that need to change between
57*c917796cSXin LI		# "api" and "internal" modes.
58*c917796cSXin LI		(
59*c917796cSXin LI			cat Doxyfile
60*c917796cSXin LI			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
61*c917796cSXin LI		) | doxygen -
62*c917796cSXin LI
63*c917796cSXin LI		# As of Doxygen 1.8.0 - 1.9.6 and the Doxyfile options we use,
64*c917796cSXin LI		# the output is good without any JavaScript. Unfortunately
65*c917796cSXin LI		# Doxygen doesn't have an option to disable JavaScript usage
66*c917796cSXin LI		# completely so we strip it away with the hack below.
67*c917796cSXin LI		#
68*c917796cSXin LI		# Omitting the JavaScript code avoids some license hassle
69*c917796cSXin LI		# as jquery.js is fairly big, it contains more than jQuery
70*c917796cSXin LI		# itself, and doesn't include the actual license text (it
71*c917796cSXin LI		# only refers to the MIT license by name).
72*c917796cSXin LI		echo "Stripping JavaScript from Doxygen output..."
73*c917796cSXin LI		for F in ../doc/api/*.html
74*c917796cSXin LI		do
75*c917796cSXin LI			sed 's/<script [^>]*><\/script>//g
76*c917796cSXin LI				s/onclick="[^"]*"//g' \
77*c917796cSXin LI				"$F" > ../doc/api/tmp
78*c917796cSXin LI			mv -f ../doc/api/tmp "$F"
79*c917796cSXin LI		done
80*c917796cSXin LI		rm -f ../doc/api/*.js
81*c917796cSXin LI		;;
82*c917796cSXin LI
83*c917796cSXin LI	internal)
84*c917796cSXin LI		# The docs from internal aren't for distribution so
85*c917796cSXin LI		# the JavaScript files aren't an issue here.
86*c917796cSXin LI		rm -rf ../doc/internal
87*c917796cSXin LI		(
88*c917796cSXin LI			cat Doxyfile
89*c917796cSXin LI			echo "PROJECT_NUMBER         = $PACKAGE_VERSION"
90*c917796cSXin LI			echo 'PROJECT_NAME           = "XZ Utils"'
91*c917796cSXin LI			echo 'STRIP_FROM_PATH        = ../src'
92*c917796cSXin LI			echo 'INPUT                  = ../src'
93*c917796cSXin LI			echo 'HTML_OUTPUT            = internal'
94*c917796cSXin LI			echo 'EXTRACT_PRIVATE        = YES'
95*c917796cSXin LI			echo 'EXTRACT_STATIC         = YES'
96*c917796cSXin LI			echo 'EXTRACT_LOCAL_CLASSES  = YES'
97*c917796cSXin LI			echo 'SEARCHENGINE           = YES'
98*c917796cSXin LI		) | doxygen -
99*c917796cSXin LI		;;
100*c917796cSXin LI
101*c917796cSXin LI	*)
102*c917796cSXin LI		echo "doxygen/update-doxygen: Error: mode argument '$1'" \
103*c917796cSXin LI			"is not supported." >&2
104*c917796cSXin LI		echo "doxygen/update-doxygen: Supported modes:" >&2
105*c917796cSXin LI		echo "doxygen/update-doxygen: - 'api' (default):" \
106*c917796cSXin LI			"liblzma API docs into doc/api" >&2
107*c917796cSXin LI		echo "doxygen/update-doxygen: - 'internal':"\
108*c917796cSXin LI			"internal docs into doc/internal" >&2
109*c917796cSXin LI		exit 1
110*c917796cSXin LI		;;
111*c917796cSXin LIesac
112