From 0ab6d927e01cfca32ea8b6debd58a7a8e9a294cc Mon Sep 17 00:00:00 2001
From: Jorrit Fahlke <joe@dune-project.org>
Date: Mon, 3 Sep 2012 09:26:10 +0000
Subject: [PATCH] [DUNE_ADD_ALL_PKG] Document usage better, and correctly use
 it in hdf5.m4.

[[Imported from SVN: r6953]]
---
 m4/dune.m4     |  4 +++-
 m4/dune_mpi.m4 |  2 ++
 m4/hdf5.m4     | 15 ++++++++++++---
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/m4/dune.m4 b/m4/dune.m4
index 943343af9..0580c6202 100644
--- a/m4/dune.m4
+++ b/m4/dune.m4
@@ -58,7 +58,9 @@ AS_VAR_SET([$1], ["$_dune_va_tmp"$2])])
 # LIBS The libraries to add.
 #
 # All arguments allow shell substitutions.  Each argument should be suitable
-# for use inside shell double quotes.
+# for use inside shell double quotes.  The flags given as argument here should
+# not include the flags of dependend libraries that already call
+# DUNE_ADD_ALL_PKG themselves; e.g. HDF5 should not add the DUNEMPI* flags.
 #
 # configure/shell variables:
 #   ALL_PKG_CPPFLAGS
diff --git a/m4/dune_mpi.m4 b/m4/dune_mpi.m4
index 05dffaadc..6fc8339e2 100644
--- a/m4/dune_mpi.m4
+++ b/m4/dune_mpi.m4
@@ -204,6 +204,8 @@ AC_DEFUN([DUNE_MPI],[
   AC_SUBST(DUNEMPILIBS)
   AC_SUBST(MPI_VERSION, $dune_MPI_VERSION)
 
+  # NOTE: If you intent to copy-n-paste this line, try to avoid including any
+  # flags of dependent libraries that call DUNE_ADD_ALL_PKG themselves.
   DUNE_ADD_ALL_PKG([MPI], [\${DUNEMPICPPFLAGS}], [\${DUNEMPILDFLAGS}], [\${DUNEMPILIBS}])
 
   AM_CONDITIONAL(MPI, [test "x$with_mpi" != "xno"])
diff --git a/m4/hdf5.m4 b/m4/hdf5.m4
index 4f8d4b502..9c933f255 100644
--- a/m4/hdf5.m4
+++ b/m4/hdf5.m4
@@ -65,8 +65,11 @@ AC_DEFUN([DUNE_PATH_HDF5],[
 
  CPPFLAGS="$CPPFLAGS $_dune_hdf5_incpath"
 
+ nodep_HDF5_CPPFLAGS="$_dune_hdf5_incpath"
  HDF5_CPPFLAGS="$_dune_hdf5_incpath"
+ nodep_HDF5_LDFLAGS=""
  HDF5_LDFLAGS=""
+ nodep_HDF5_LIBS=""
  HDF5_LIBS=""
  HDF5_PARALLEL=0
  # test if we are parallel
@@ -89,7 +92,10 @@ AC_DEFUN([DUNE_PATH_HDF5],[
  # test for lib
  if test x$HAVE_HDF5 = x1 ; then
    AC_CHECK_LIB([hdf5], [H5open],
-     [HDF5_LIBS="$_dune_hdf5_libpath -lhdf5 $with_hdf5_libs $HDF5_LIBS"],
+     [
+       nodep_HDF5_LIBS="$_dune_hdf5_libpath -lhdf5 $with_hdf5_libs $nodep_HDF5_LIBS"
+       HDF5_LIBS="$_dune_hdf5_libpath -lhdf5 $with_hdf5_libs $HDF5_LIBS"
+     ],
      [HAVE_HDF5=0], ["$with_hdf5_libs"])
  fi
 
@@ -107,8 +113,11 @@ AC_DEFUN([DUNE_PATH_HDF5],[
    fi
  else
    # clear variables
+   nodep_HDF5_CPPFLAGS=
    HDF5_CPPFLAGS=
+   nodep_HDF5_LDFLAGS=
    HDF5_LDFLAGS=
+   nodep_HDF5_LIBS=
    HDF5_LIBS=
    HDF5_PARALLEL=0
  fi
@@ -121,8 +130,8 @@ AC_DEFUN([DUNE_PATH_HDF5],[
  AM_CONDITIONAL(HDF5, test x$HAVE_HDF5 = x1)
 
  # add to global list
- DUNE_ADD_ALL_PKG([HDF5], [\${HDF5_CPPFLAGS}],
-                  [\${HDF5_LDFLAGS}], [\${HDF5_LIBS}])    
+ DUNE_ADD_ALL_PKG([HDF5], [$nodep_HDF5_CPPFLAGS],
+                  [$nodep_HDF5_LDFLAGS], [$nodep_HDF5_LIBS])
 
  # reset values					    
  LIBS="$ac_save_LIBS"
-- 
GitLab