From 36bb8dbd85673436a22cfa22a67afab0be7a53ea Mon Sep 17 00:00:00 2001
From: Jorrit Fahlke <joe@dune-project.org>
Date: Mon, 11 Jan 2010 17:13:45 +0000
Subject: [PATCH] * Fix some bugs in the mpi stuff which were introduced in the
 last commit. * Infrastructure to warn about the use of deprecated
 preprocessor make   variables. * Use that infrastructure to war about
 MPI_CPPFLAGS.

[[Imported from SVN: r5807]]
---
 configure.ac                                  |  1 +
 doc/buildsystem/buildsystem.tex               |  2 +-
 dune/common/Makefile.am                       |  2 +-
 dune/common/warnings/.gitignore               |  2 +
 dune/common/warnings/Makefile.am              |  7 +++
 .../warnings/mpi_cppflags_deprecation.hh      | 12 +++++
 m4/Makefile.am                                |  4 +-
 m4/dune_cppincludeopt.m4                      | 50 +++++++++++++++++++
 m4/dune_mpi.m4                                | 13 +++--
 m4/mpi-config.m4                              | 14 +++---
 10 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 dune/common/warnings/.gitignore
 create mode 100644 dune/common/warnings/Makefile.am
 create mode 100644 dune/common/warnings/mpi_cppflags_deprecation.hh
 create mode 100644 m4/dune_cppincludeopt.m4

diff --git a/configure.ac b/configure.ac
index 606d44321..b58819e36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ AC_CONFIG_FILES([Makefile
      dune/common/Makefile
      dune/common/test/Makefile
      dune/common/exprtmpl/Makefile
+     dune/common/warnings/Makefile
      doc/Makefile
      doc/devel/Makefile
      doc/layout/Makefile
diff --git a/doc/buildsystem/buildsystem.tex b/doc/buildsystem/buildsystem.tex
index 9d3f4ace1..87d3ed613 100644
--- a/doc/buildsystem/buildsystem.tex
+++ b/doc/buildsystem/buildsystem.tex
@@ -850,7 +850,7 @@ target_LIBADD =
   In addition, this macro substitutes \texttt{MPI\_VERSION} a text string
   identifying the detected version of MPI.  It defines the following
   preprocessor defines: \texttt{MPI\_2}, defined if the detected MPI supports
-  the MPI-2 standard.  \texttt{HAVE_MPI}, 1 if MPI is detected and enabled.
+  the MPI-2 standard.  \texttt{HAVE\_MPI}, 1 if MPI is detected and enabled.
   It also defines the automake conditional \texttt{MPI}.
 \end{description}
 
diff --git a/dune/common/Makefile.am b/dune/common/Makefile.am
index d0bd1c930..44295e82d 100644
--- a/dune/common/Makefile.am
+++ b/dune/common/Makefile.am
@@ -1,6 +1,6 @@
 # $Id$
 
-SUBDIRS = . test exprtmpl
+SUBDIRS = . test exprtmpl warnings
 
 # the standard debug streams are put into the libdune
 noinst_LTLIBRARIES = libcommon.la
diff --git a/dune/common/warnings/.gitignore b/dune/common/warnings/.gitignore
new file mode 100644
index 000000000..282522db0
--- /dev/null
+++ b/dune/common/warnings/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/dune/common/warnings/Makefile.am b/dune/common/warnings/Makefile.am
new file mode 100644
index 000000000..ef6ff56d9
--- /dev/null
+++ b/dune/common/warnings/Makefile.am
@@ -0,0 +1,7 @@
+# $Id$
+
+warningsincludedir = $(includedir)/dune/common/warnings
+warningsinclude_HEADERS =			\
+	mpi_cppflags_deprecation.hh
+
+include $(top_srcdir)/am/global-rules
diff --git a/dune/common/warnings/mpi_cppflags_deprecation.hh b/dune/common/warnings/mpi_cppflags_deprecation.hh
new file mode 100644
index 000000000..f5521b7c3
--- /dev/null
+++ b/dune/common/warnings/mpi_cppflags_deprecation.hh
@@ -0,0 +1,12 @@
+// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vi: set et ts=4 sw=2 sts=2:
+#ifndef DUNE_MPI_CPPFLAGS_DEPRECATION
+#define DUNE_MPI_CPPFLAGS_DEPRECATION
+
+#warning The MPI_CPPFLAGS configure substitute is deprecated.  Please change
+#warning your Makefile.am to use DUNEMPICPPFLAGS instead.  Note that it is a
+#warning good idea to change any occurance of MPI_LDFLAGS into DUNEMPILIBS and
+#warning DUNEMPILDFLAGS as apropriate, since it is not possible to issue a
+#warning deprecation warning in that case.
+
+#endif // DUNE_MPI_CPPFLAGS_DEPRECATION
diff --git a/m4/Makefile.am b/m4/Makefile.am
index d00e9dbb3..fe4d3c97e 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -2,7 +2,9 @@
 
 ALLM4S = acx_blas.m4 acx_lapack.m4 acx_mpi.m4 acx_pthread.m4 \
          ax_check_gl.m4 ax_lang_compiler_ms.m4 dune_all.m4 \
-         dune_autobuild.m4 dune_common.m4 dune_compiler.m4 dune_deprecated.m4 \
+         dune_autobuild.m4 dune_common.m4 dune_compiler.m4	\
+	 dune_cppincludeopt.m4					\
+	 dune_deprecated.m4					\
          dune_docu.m4 dune_exprtmpl.m4  dune_linkcxx.m4 \
 	 dune.m4 \
          dune_mpi.m4 dune_streams.m4 \
diff --git a/m4/dune_cppincludeopt.m4 b/m4/dune_cppincludeopt.m4
new file mode 100644
index 000000000..7f4e95133
--- /dev/null
+++ b/m4/dune_cppincludeopt.m4
@@ -0,0 +1,50 @@
+dnl -*- autoconf -*-
+# Determine how to make the C preprocessor include a certain file before the
+# main input file from the command line.  Sets the following configure
+# substitution:
+#
+# CPPINCLUDEOPT The include option.  This is something like "-include " (note
+#   trailing space).  If no such option could determined, this variable will
+#   be set to something like "-D DUMMY=".  This means it must be used like
+#   CPPFLAGS="$CPPINCLUDEOPT$header" (note: no whitespace between
+#   $CPPINCLUDEOPT and $header).
+#
+# Sets the following automake conditional:
+#
+# HAVE_CPPINCLUDEOPT
+AC_DEFUN([DUNE_CPPINCLUDEOPT],
+[
+  AC_LANG_PUSH([C])
+  AC_REQUIRE([AC_PROG_CPP])
+
+  AC_MSG_CHECKING([for preprocessor option to preinclude a header])
+
+  cat >conftestpreinc.h <<EOF
+#define PREINC_WORKS
+EOF
+  ac_save_CPPFLAGS="$CPPFLAGS"
+  HAVE_CPPINCLUDEOPT=no
+
+  if ! test yes = "$HAVE_CPPINCLUDEOPT"; then
+    # check for -include
+    CPPINCLUDEOPT="-include "
+    CPPFLAGS="$ac_save_CPPFLAGS ${CPPINCLUDEOPT}conftestpreinc.h"
+    AC_COMPILE_IFELSE([
+#ifdef PREINC_WORKS
+/* OK */
+#else
+#error preinc does not work
+#endif
+    ],[HAVE_CPPINCLUDEOPT=yes])
+  fi
+
+  rm -f conftestpreinc.h
+  if ! test yes = "$HAVE_CPPINCLUDEOPT"; then
+    CPPINCLUDEOPT="-D DUMMY="
+  fi
+  AC_MSG_RESULT([$HAVE_CPPINCLUDEOPT (${CPPINCLUDEOPT}file.h)])
+  AC_SUBST([CPPINCLUDEOPT])
+  AM_CONDITIONAL([HAVE_CPPINCLUDEOPT], [test yes = "$HAVE_CPPINCLUDEOPT"])
+  CPPFLAGS="$ac_save_CPPFLAGS"
+  AC_LANG_POP([C])
+])
diff --git a/m4/dune_mpi.m4 b/m4/dune_mpi.m4
index 3e3a172eb..1dd9e8e90 100644
--- a/m4/dune_mpi.m4
+++ b/m4/dune_mpi.m4
@@ -1,3 +1,4 @@
+dnl -*- autoconf -*-
 # $Id$
 
 # wrapper for the autoconf-archive check. Note: compiling MPI-stuff sucks!
@@ -52,6 +53,7 @@
 
 AC_DEFUN([DUNE_MPI],[
   AC_PREREQ(2.50) dnl for AC_LANG_CASE
+  AC_REQUIRE([DUNE_CPPINCLUDEOPT])
 
   # get compilation script
   AC_LANG_CASE([C],[
@@ -160,15 +162,16 @@ AC_DEFUN([DUNE_MPI],[
   ])
     
   # set flags
-  MPI_CPPFLAGS="$DUNEMPICPPFLAGS"
-  MPI_LDFLAGS="$DUNEMPILDFLAGS $DUNEMPILIBS"
+  AS_IF([test yes = "$HAVE_CPPINCLUDEOPT"],
+    [dune_mpicppflagswarn="${CPPINCLUDEOPT}dune/common/warnings/mpi_cppflags_deprecation.hh"],
+    [dune_mpicppflagswarn=""])
   AS_IF([test "x$with_mpi" != "xno"],[
     AC_SUBST(DUNEMPICPPFLAGS, $DUNEMPICPPFLAGS)
     AC_SUBST(DUNEMPILDFLAGS, $DUNEMPILDFLAGS)
     AC_SUBST(DUNEMPILIBS, $DUNEMPILIBS)
 
-    AC_SUBST(MPI_CPPFLAGS, $MPI_CPPFLAGS)
-    AC_SUBST(MPI_LDFLAGS, $MPI_LDFLAGS)
+    AC_SUBST(MPI_CPPFLAGS, "$dune_mpicppflagswarn $DUNEMPICPPFLAGS")
+    AC_SUBST(MPI_LDFLAGS, "$DUNEMPILDFLAGS $DUNEMPILIBS")
     AC_SUBST(MPI_VERSION, $dune_MPI_VERSION)
     AC_DEFINE(HAVE_MPI,ENABLE_MPI,[Define if you have the MPI library.
     This is only true if MPI was found by configure _and_ if the application
@@ -178,7 +181,7 @@ AC_DEFUN([DUNE_MPI],[
     AC_SUBST(DUNEMPILDFLAGS, "")
     AC_SUBST(DUNEMPILIBS, "")
 
-    AC_SUBST(MPI_CPPFLAGS, "")
+    AC_SUBST(MPI_CPPFLAGS, "$dune_mpicppflagswarn")
     AC_SUBST(MPI_LDFLAGS, "")
   ])
 
diff --git a/m4/mpi-config.m4 b/m4/mpi-config.m4
index 4b09587a4..63dcebccc 100644
--- a/m4/mpi-config.m4
+++ b/m4/mpi-config.m4
@@ -55,18 +55,18 @@ _EOF
       if test x"$DUNEMPICPPFLAGS" = x; then
         DUNEMPICPPFLAGS="$retval"
       fi
-      if x"$DUNEMPILIBS" = x; then
+      if test x"$DUNEMPILIBS" = x; then
         mpi_getflags "-showme:link"
         DUNEMPILIBS="$retval"
       fi
     else
       dune_MPI_VERSION="LAM < 7.1"
       # use -showme and dummy parameters to extract flags        
-      if x"$DUNEMPICPPFLAGS" = x; then
+      if test x"$DUNEMPICPPFLAGS" = x; then
         mpi_getflags "-showme" "-c $MPISOURCE"
         DUNEMPICPPFLAGS="$retval"
       fi
-      if x"$DUNEMPILIBS" = x; then
+      if test x"$DUNEMPILIBS" = x; then
         mpi_getflags "-showme" "dummy.o -o dummy"
         DUNEMPILIBS="$retval"
       fi
@@ -94,7 +94,7 @@ mpi_getmpichflags() {
     DUNEMPICPPFLAGS="$retval"
   fi
     
-  if x"$DUNEMPILIBS" = x; then
+  if test x"$DUNEMPILIBS" = x; then
     # get linker options
     mpi_getflags "-link_info"
     DUNEMPILIBS="$retval"
@@ -120,7 +120,7 @@ mpi_getmpich2flags() {
     DUNEMPICPPFLAGS="$retval"
   fi
     
-  if x"$DUNEMPILIBS" = x; then
+  if test x"$DUNEMPILIBS" = x; then
     # get linker options
     mpi_getflags "-show" "-o"
     DUNEMPILIBS="$retval"
@@ -196,7 +196,7 @@ _EOF
       mpi_getflags "-showme:compile"
       DUNEMPICPPFLAGS="$retval"
     fi
-    if x"$DUNEMPILIBS" = x; then
+    if test x"$DUNEMPILIBS" = x; then
       mpi_getflags "-showme:link"
       DUNEMPILIBS="$retval"
     fi
@@ -269,7 +269,7 @@ test_ibmmpi() {
         DUNEMPICPPFLAGS="$retval"
       fi
   
-      if x"$DUNEMPILIBS" = x; then
+      if test x"$DUNEMPILIBS" = x; then
         mpi_getflags "-v" "dummy.o -o dummy"
         DUNEMPILIBS="$retval"
       fi
-- 
GitLab