From ad25dab99057383c7e8e7317eb20086d9eaed073 Mon Sep 17 00:00:00 2001
From: Olaf Mandel <olaf@mandel.name>
Date: Tue, 13 Oct 2015 22:09:13 +0200
Subject: [PATCH] AX_PROG_DOXYGEN: allow AC_CONFIG_FILES([Doxyfile])

To allow substitutions in the used Doxyfile, two changes are needed:

1. also substitute everything put in the environment (except DOCDIR)
2. allow Doxyfiles to also reside in the builddir

The latter change is a potentially breaking one! The old behaviour was
to always prefix $(srcdir)/ to the location provided as the second
(and forth, sixth, ...) parameter. This needs to be dropped to allow
for searching in the build directory. To compensate, the default now
is $(srcdir)/Doxyfile.

So the following still works:

DX_INIT_DOXYGEN([foo])
DX_INIT_DOXYGEN([foo], , [dest-dir])

While this needs to be changed:
   DX_INIT_DOXYGEN([foo], [Doxyfile])
-> DX_INIT_DOXYGEN([foo], [$(srcdir)/Doxyfile])
---
 m4/ax_prog_doxygen.m4 |   39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/m4/ax_prog_doxygen.m4 b/m4/ax_prog_doxygen.m4
index 766043f..f785769 100644
--- a/m4/ax_prog_doxygen.m4
+++ b/m4/ax_prog_doxygen.m4
@@ -45,12 +45,13 @@
 #   Once all the feature defaults have been specified, call DX_INIT_DOXYGEN
 #   with the following parameters: a one-word name for the project for use
 #   as a filename base etc., an optional configuration file name (the
-#   default is 'Doxyfile', the same as Doxygen's default), and an optional
-#   output directory name (the default is 'doxygen-doc'). To run doxygen
-#   multiple times for different configuration files and output directories
-#   provide more parameters: the second, forth, sixth, etc parameter are
-#   configuration file names and the third, fifth, seventh, etc parameter
-#   are output directories. No checking is done to catch duplicates.
+#   default is '$(srcdir)/Doxyfile', the same as Doxygen's default), and an
+#   optional output directory name (the default is 'doxygen-doc'). To run
+#   doxygen multiple times for different configuration files and output
+#   directories provide more parameters: the second, forth, sixth, etc
+#   parameter are configuration file names and the third, fifth, seventh,
+#   etc parameter are output directories. No checking is done to catch
+#   duplicates.
 #
 #   Automake Support
 #
@@ -120,8 +121,13 @@ AC_DEFUN([DX_FEATURE_ps],   ON)
 
 # DX_ENV_APPEND(VARIABLE, VALUE)
 # ------------------------------
-# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen.
-AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])])
+# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen and add it
+# as a substitution (but not a Makefile variable).
+AC_DEFUN([DX_ENV_APPEND],
+[AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])dnl
+AC_SUBST([$1], [$2])dnl
+AM_SUBST_NOTMAKE([$1])dnl
+])
 
 # DX_DIRNAME_EXPR
 # ---------------
@@ -236,23 +242,24 @@ AC_DEFUN([DX_PS_FEATURE],      [AC_DEFUN([DX_FEATURE_ps],   [$1])])
 # DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR], ...)
 # --------------------------------------------------------------
 # PROJECT also serves as the base name for the documentation files.
-# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc".
+# The default CONFIG-FILE is "$(srcdir)/Doxyfile" and OUTPUT-DOC-DIR is
+# "doxygen-doc".
 # More arguments are interpreted as interleaved CONFIG-FILE and
 # OUTPUT-DOC-DIR values.
 AC_DEFUN([DX_INIT_DOXYGEN], [
 
 # Files:
 AC_SUBST([DX_PROJECT], [$1])
-AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])])
-AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])])
+AC_SUBST([DX_CONFIG], ['ifelse([$2], [], [$(srcdir)/Doxyfile], [$2])'])
+AC_SUBST([DX_DOCDIR], ['ifelse([$3], [], [doxygen-doc], [$3])'])
 m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 4, m4_count($@), 2,
       [AC_SUBST([DX_CONFIG]m4_eval(DX_i[/2]),
-                m4_default_nblank_quoted(m4_argn(DX_i, $@),
-                                         [Doxyfile]))])])dnl
+                'm4_default_nblank_quoted(m4_argn(DX_i, $@),
+                                          [$(srcdir)/Doxyfile])')])])dnl
 m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 5, m4_count($@,), 2,
       [AC_SUBST([DX_DOCDIR]m4_eval([(]DX_i[-1)/2]),
-                m4_default_nblank_quoted(m4_argn(DX_i, $@),
-                                         [doxygen-doc]))])])dnl
+                'm4_default_nblank_quoted(m4_argn(DX_i, $@),
+                                          [doxygen-doc])')])])dnl
 m4_define([DX_loop], m4_dquote(m4_if(m4_eval(3 < m4_count($@)), 1,
           [m4_for([DX_i], 4, m4_count($@), 2, [, m4_eval(DX_i[/2])])],
           [])))dnl
@@ -559,7 +566,7 @@ doxygen-doc: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
 m4_foreach([DX_i], [DX_loop],
 [[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag: \$(DX_CONFIG]DX_i[) \$(pkginclude_HEADERS)
 	\$(A""M_V_at)rm -rf \$(DX_DOCDIR]DX_i[)
-	\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR]DX_i[) \$(DX_DOXYGEN) \$(srcdir)/\$(DX_CONFIG]DX_i[)
+	\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR]DX_i[) \$(DX_DOXYGEN) \$(DX_CONFIG]DX_i[)
 	\$(A""M_V_at)echo Timestamp >\$][@
 
 ]])dnl
-- 
1.7.9.5

