1#
2# Copyright 2007 Oren Ben-Kiki
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,
11# software distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.  See the License for the specific language governing
14# permissions and limitations under the License.
15#
16
17
18# Generate automatic documentation using Doxygen. Works in concert with the
19# aminclude.m4 file and a compatible doxygen configuration file. Defines the
20# following public macros:
21#
22# DX_???_FEATURE(ON|OFF) - control the default setting fo a Doxygen feature.
23# Supported features are 'DOXYGEN' itself, 'DOT' for generating graphics,
24# 'HTML' for plain HTML, 'CHM' for compressed HTML help (for MS users), 'CHI'
25# for generating a separate .chi file by the .chm file, and 'MAN', 'RTF',
26# 'XML', 'PDF' and 'PS' for the appropriate output formats. The environment
27# variable DOXYGEN_PAPER_SIZE may be specified to override the default 'a4wide'
28# paper size.
29#
30# By default, HTML, PDF and PS documentation is generated as this seems to be
31# the most popular and portable combination. MAN pages created by Doxygen are
32# usually problematic, though by picking an appropriate subset and doing some
33# massaging they might be better than nothing. CHM and RTF are specific for MS
34# (note that you can't generate both HTML and CHM at the same time). The XML is
35# rather useless unless you apply specialized post-processing to it.
36#
37# The macro mainly controls the default state of the feature. The use can
38# override the default by specifying --enable or --disable. The macros ensure
39# that contradictory flags are not given (e.g., --enable-doxygen-html and
40# --enable-doxygen-chm, --enable-doxygen-anything with --disable-doxygen, etc.)
41# Finally, each feature will be automatically disabled (with a warning) if the
42# required programs are missing.
43#
44# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN with
45# the following parameters: a one-word name for the project for use as a
46# filename base etc., an optional configuration file name (the default is
47# 'Doxyfile', the same as Doxygen's default), and an optional output directory
48# name (the default is 'doxygen-doc').
49
50## ----------##
51## Defaults. ##
52## ----------##
53
54DX_ENV=""
55AC_DEFUN([DX_FEATURE_doc],  ON)
56AC_DEFUN([DX_FEATURE_dot],  ON)
57AC_DEFUN([DX_FEATURE_man],  OFF)
58AC_DEFUN([DX_FEATURE_html], ON)
59AC_DEFUN([DX_FEATURE_chm],  OFF)
60AC_DEFUN([DX_FEATURE_chi],  OFF)
61AC_DEFUN([DX_FEATURE_rtf],  OFF)
62AC_DEFUN([DX_FEATURE_xml],  OFF)
63AC_DEFUN([DX_FEATURE_pdf],  ON)
64AC_DEFUN([DX_FEATURE_ps],   ON)
65
66## --------------- ##
67## Private macros. ##
68## --------------- ##
69
70# DX_ENV_APPEND(VARIABLE, VALUE)
71# ------------------------------
72# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen.
73AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])])
74
75# DX_DIRNAME_EXPR
76# ---------------
77# Expand into a shell expression prints the directory part of a path.
78AC_DEFUN([DX_DIRNAME_EXPR],
79         [[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']])
80
81# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF)
82# -------------------------------------
83# Expands according to the M4 (static) status of the feature.
84AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])])
85
86# DX_REQUIRE_PROG(VARIABLE, PROGRAM)
87# ----------------------------------
88# Require the specified program to be found for the DX_CURRENT_FEATURE to work.
89AC_DEFUN([DX_REQUIRE_PROG], [
90AC_PATH_TOOL([$1], [$2])
91if test x"$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = x1; then
92    AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION])
93    AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0)
94fi
95])
96
97# DX_TEST_FEATURE(FEATURE)
98# ------------------------
99# Expand to a shell expression testing whether the feature is active.
100AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1])
101
102# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE)
103# -------------------------------------------------
104# Verify that a required features has the right state before trying to turn on
105# the DX_CURRENT_FEATURE.
106AC_DEFUN([DX_CHECK_DEPEND], [
107test x"$DX_FLAG_$1" = x"$2" \
108|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1,
109                            requires, contradicts) doxygen-DX_CURRENT_FEATURE])
110])
111
112# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE)
113# ----------------------------------------------------------
114# Turn off the DX_CURRENT_FEATURE if the required feature is off.
115AC_DEFUN([DX_CLEAR_DEPEND], [
116test x"$DX_FLAG_$1" = x"$2" || AC_SUBST([DX_FLAG_]DX_CURRENT_FEATURE, 0)
117])
118
119# DX_FEATURE_ARG(FEATURE, DESCRIPTION,
120#                CHECK_DEPEND, CLEAR_DEPEND,
121#                REQUIRE, DO-IF-ON, DO-IF-OFF)
122# --------------------------------------------
123# Parse the command-line option controlling a feature. CHECK_DEPEND is called
124# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND),
125# otherwise CLEAR_DEPEND is called to turn off the default state if a required
126# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional
127# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and
128# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature.
129AC_DEFUN([DX_ARG_ABLE], [
130    AC_DEFUN([DX_CURRENT_FEATURE], [$1])
131    AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2])
132    AC_ARG_ENABLE(doxygen-$1,
133                  [AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1],
134                                                      [--enable-doxygen-$1]),
135                                  DX_IF_FEATURE([$1], [don't $2], [$2]))],
136                  [
137case "$enableval" in
138#(
139y|Y|yes|Yes|YES)
140    AC_SUBST([DX_FLAG_$1], 1)
141    $3
142;; #(
143n|N|no|No|NO)
144    AC_SUBST([DX_FLAG_$1], 0)
145;; #(
146*)
147    AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1])
148;;
149esac
150], [
151AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)])
152$4
153])
154if DX_TEST_FEATURE([$1]); then
155    $5
156    :
157fi
158if DX_TEST_FEATURE([$1]); then
159    AM_CONDITIONAL(DX_COND_$1, :)
160    $6
161    :
162else
163    AM_CONDITIONAL(DX_COND_$1, false)
164    $7
165    :
166fi
167])
168
169## -------------- ##
170## Public macros. ##
171## -------------- ##
172
173# DX_XXX_FEATURE(DEFAULT_STATE)
174# -----------------------------
175AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc],  [$1])])
176AC_DEFUN([DX_MAN_FEATURE],     [AC_DEFUN([DX_FEATURE_man],  [$1])])
177AC_DEFUN([DX_HTML_FEATURE],    [AC_DEFUN([DX_FEATURE_html], [$1])])
178AC_DEFUN([DX_CHM_FEATURE],     [AC_DEFUN([DX_FEATURE_chm],  [$1])])
179AC_DEFUN([DX_CHI_FEATURE],     [AC_DEFUN([DX_FEATURE_chi],  [$1])])
180AC_DEFUN([DX_RTF_FEATURE],     [AC_DEFUN([DX_FEATURE_rtf],  [$1])])
181AC_DEFUN([DX_XML_FEATURE],     [AC_DEFUN([DX_FEATURE_xml],  [$1])])
182AC_DEFUN([DX_XML_FEATURE],     [AC_DEFUN([DX_FEATURE_xml],  [$1])])
183AC_DEFUN([DX_PDF_FEATURE],     [AC_DEFUN([DX_FEATURE_pdf],  [$1])])
184AC_DEFUN([DX_PS_FEATURE],      [AC_DEFUN([DX_FEATURE_ps],   [$1])])
185
186# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR])
187# ---------------------------------------------------------
188# PROJECT also serves as the base name for the documentation files.
189# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc".
190AC_DEFUN([DX_INIT_DOXYGEN], [
191
192# Files:
193AC_SUBST([DX_PROJECT], [$1])
194AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])])
195AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])])
196
197# Environment variables used inside doxygen.cfg:
198SRCDIR=`cd $srcdir; pwd`
199DX_ENV_APPEND(SRCDIR, $SRCDIR)
200DX_ENV_APPEND(PROJECT, $DX_PROJECT)
201DX_ENV_APPEND(DOCDIR, $DX_DOCDIR)
202DX_ENV_APPEND(VERSION, $PACKAGE_VERSION)
203
204# Doxygen itself:
205DX_ARG_ABLE(doc, [generate any doxygen documentation],
206            [],
207            [],
208            [DX_REQUIRE_PROG([DX_DOXYGEN], doxygen)
209             DX_REQUIRE_PROG([DX_PERL], perl)],
210            [DX_ENV_APPEND(PERL_PATH, $DX_PERL)])
211
212# Dot for graphics:
213DX_ARG_ABLE(dot, [generate graphics for doxygen documentation],
214            [DX_CHECK_DEPEND(doc, 1)],
215            [DX_CLEAR_DEPEND(doc, 1)],
216            [DX_REQUIRE_PROG([DX_DOT], dot)],
217            [DX_ENV_APPEND(HAVE_DOT, YES)
218             DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])],
219            [DX_ENV_APPEND(HAVE_DOT, NO)])
220
221# Man pages generation:
222DX_ARG_ABLE(man, [generate doxygen manual pages],
223            [DX_CHECK_DEPEND(doc, 1)],
224            [DX_CLEAR_DEPEND(doc, 1)],
225            [],
226            [DX_ENV_APPEND(GENERATE_MAN, YES)],
227            [DX_ENV_APPEND(GENERATE_MAN, NO)])
228
229# RTF file generation:
230DX_ARG_ABLE(rtf, [generate doxygen RTF documentation],
231            [DX_CHECK_DEPEND(doc, 1)],
232            [DX_CLEAR_DEPEND(doc, 1)],
233            [],
234            [DX_ENV_APPEND(GENERATE_RTF, YES)],
235            [DX_ENV_APPEND(GENERATE_RTF, NO)])
236
237# XML file generation:
238DX_ARG_ABLE(xml, [generate doxygen XML documentation],
239            [DX_CHECK_DEPEND(doc, 1)],
240            [DX_CLEAR_DEPEND(doc, 1)],
241            [],
242            [DX_ENV_APPEND(GENERATE_XML, YES)],
243            [DX_ENV_APPEND(GENERATE_XML, NO)])
244
245# (Compressed) HTML help generation:
246DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation],
247            [DX_CHECK_DEPEND(doc, 1)],
248            [DX_CLEAR_DEPEND(doc, 1)],
249            [DX_REQUIRE_PROG([DX_HHC], hhc)],
250            [DX_ENV_APPEND(HHC_PATH, $DX_HHC)
251             DX_ENV_APPEND(GENERATE_HTML, YES)
252             DX_ENV_APPEND(GENERATE_HTMLHELP, YES)],
253            [DX_ENV_APPEND(GENERATE_HTMLHELP, NO)])
254
255# Separate CHI file generation.
256DX_ARG_ABLE(chi, [generate doxygen separate compressed HTML help index file],
257            [DX_CHECK_DEPEND(chm, 1)],
258            [DX_CLEAR_DEPEND(chm, 1)],
259            [],
260            [DX_ENV_APPEND(GENERATE_CHI, YES)],
261            [DX_ENV_APPEND(GENERATE_CHI, NO)])
262
263# Plain HTML pages generation:
264DX_ARG_ABLE(html, [generate doxygen plain HTML documentation],
265            [DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)],
266            [DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)],
267            [],
268            [DX_ENV_APPEND(GENERATE_HTML, YES)],
269            [DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)])
270
271# PostScript file generation:
272DX_ARG_ABLE(ps, [generate doxygen PostScript documentation],
273            [DX_CHECK_DEPEND(doc, 1)],
274            [DX_CLEAR_DEPEND(doc, 1)],
275            [DX_REQUIRE_PROG([DX_LATEX], latex)
276             DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
277             DX_REQUIRE_PROG([DX_DVIPS], dvips)
278             DX_REQUIRE_PROG([DX_EGREP], egrep)])
279
280# PDF file generation:
281DX_ARG_ABLE(pdf, [generate doxygen PDF documentation],
282            [DX_CHECK_DEPEND(doc, 1)],
283            [DX_CLEAR_DEPEND(doc, 1)],
284            [DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex)
285             DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
286             DX_REQUIRE_PROG([DX_EGREP], egrep)])
287
288# LaTeX generation for PS and/or PDF:
289if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then
290    AM_CONDITIONAL(DX_COND_latex, :)
291    DX_ENV_APPEND(GENERATE_LATEX, YES)
292else
293    AM_CONDITIONAL(DX_COND_latex, false)
294    DX_ENV_APPEND(GENERATE_LATEX, NO)
295fi
296
297# Paper size for PS and/or PDF:
298AC_ARG_VAR(DOXYGEN_PAPER_SIZE,
299           [a4wide (default), a4, letter, legal or executive])
300case "$DOXYGEN_PAPER_SIZE" in
301#(
302"")
303    AC_SUBST(DOXYGEN_PAPER_SIZE, "")
304;; #(
305a4wide|a4|letter|legal|executive)
306    DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE)
307;; #(
308*)
309    AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'])
310;;
311esac
312
313#For debugging:
314#echo DX_FLAG_doc=$DX_FLAG_doc
315#echo DX_FLAG_dot=$DX_FLAG_dot
316#echo DX_FLAG_man=$DX_FLAG_man
317#echo DX_FLAG_html=$DX_FLAG_html
318#echo DX_FLAG_chm=$DX_FLAG_chm
319#echo DX_FLAG_chi=$DX_FLAG_chi
320#echo DX_FLAG_rtf=$DX_FLAG_rtf
321#echo DX_FLAG_xml=$DX_FLAG_xml
322#echo DX_FLAG_pdf=$DX_FLAG_pdf
323#echo DX_FLAG_ps=$DX_FLAG_ps
324#echo DX_ENV=$DX_ENV
325])
326