From 847b1d4ed17843929f1b6ab7df0309bf13eb4a28 Mon Sep 17 00:00:00 2001
From: Joshua Judson Rosen <jrosen@harvestai.com>
Date: Wed, 2 Dec 2015 16:46:05 -0500
Subject: [PATCH] AX_CXX_COMPILE_STDCXX: don't break "make CXXFLAGS=..."

Make C++ std-selection macros modify $(CXX), not $(CXXFLAGS).

Using $(CXXFLAGS) prevents users from being able to
rebuild with different CXXFLAGS (e.g.: to try out
different optimisations or to change debug levels)
unless they re-run ./configure with their CFLAGS.

This is more like what the mainline Autoconf macros do
(e.g.: AC_PROG_CC_C99, AC_PROG_CC_STD, etc. modify $(CC),
not $(CCFLAGS)), presmuably for much the same reasons:
if you need to specify a standard to the compiler,
it doesn't really make sense to separate that from
$(CC)/$(CXX) since $(CC)/$(CXX) aren't usable without it.
---
 m4/ax_cxx_compile_stdcxx.m4    |   18 +++++++++---------
 m4/ax_cxx_compile_stdcxx_0x.m4 |   12 ++++++------
 m4/ax_cxx_compile_stdcxx_11.m4 |    2 +-
 m4/ax_cxx_compile_stdcxx_14.m4 |    2 +-
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4
index 079e17d..0cdc163 100644
--- a/m4/ax_cxx_compile_stdcxx.m4
+++ b/m4/ax_cxx_compile_stdcxx.m4
@@ -9,7 +9,7 @@
 # DESCRIPTION
 #
 #   Check for baseline language coverage in the compiler for the specified
-#   version of the C++ standard.  If necessary, add switches to CXXFLAGS to
+#   version of the C++ standard.  If necessary, add switches to CXX to
 #   enable support.  VERSION may be '11' (for the C++11 standard) or '14'
 #   (for the C++14 standard).
 #
@@ -74,14 +74,14 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
       AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
                      $cachevar,
-        [ac_save_CXXFLAGS="$CXXFLAGS"
-         CXXFLAGS="$CXXFLAGS $switch"
+        [ac_save_CXX="$CXX"
+         CXX="$CXX $switch"
          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
           [eval $cachevar=yes],
           [eval $cachevar=no])
-         CXXFLAGS="$ac_save_CXXFLAGS"])
+         CXX="$ac_save_CXX"])
       if eval test x\$$cachevar = xyes; then
-        CXXFLAGS="$CXXFLAGS $switch"
+        CXX="$CXX $switch"
         ac_success=yes
         break
       fi
@@ -97,14 +97,14 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
       AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
                      $cachevar,
-        [ac_save_CXXFLAGS="$CXXFLAGS"
-         CXXFLAGS="$CXXFLAGS $switch"
+        [ac_save_CXX="$CXX"
+         CXX="$CXX $switch"
          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
           [eval $cachevar=yes],
           [eval $cachevar=no])
-         CXXFLAGS="$ac_save_CXXFLAGS"])
+         CXX="$ac_save_CXX"])
       if eval test x\$$cachevar = xyes; then
-        CXXFLAGS="$CXXFLAGS $switch"
+        CXX="$CXX $switch"
         ac_success=yes
         break
       fi
diff --git a/m4/ax_cxx_compile_stdcxx_0x.m4 b/m4/ax_cxx_compile_stdcxx_0x.m4
index a49f430..66ae680 100644
--- a/m4/ax_cxx_compile_stdcxx_0x.m4
+++ b/m4/ax_cxx_compile_stdcxx_0x.m4
@@ -55,8 +55,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [
   ax_cv_cxx_compile_cxx0x_cxx,
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
-  ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=c++0x"
+  ac_save_CXX="$CXX"
+  CXX="$CXX -std=c++0x"
   AC_TRY_COMPILE([
   template <typename T>
     struct check
@@ -73,7 +73,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [
     check_type c;
     check_type&& cr = static_cast<check_type&&>(c);],,
   ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no)
-  CXXFLAGS="$ac_save_CXXFLAGS"
+  CXX="$ac_save_CXX"
   AC_LANG_RESTORE
   ])
 
@@ -81,8 +81,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [
   ax_cv_cxx_compile_cxx0x_gxx,
   [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
-  ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -std=gnu++0x"
+  ac_save_CXX="$CXX"
+  CXX="$CXX -std=gnu++0x"
   AC_TRY_COMPILE([
   template <typename T>
     struct check
@@ -99,7 +99,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [
     check_type c;
     check_type&& cr = static_cast<check_type&&>(c);],,
   ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no)
-  CXXFLAGS="$ac_save_CXXFLAGS"
+  CXX="$ac_save_CXX"
   AC_LANG_RESTORE
   ])
 
diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4
index 09db383..b7b4676 100644
--- a/m4/ax_cxx_compile_stdcxx_11.m4
+++ b/m4/ax_cxx_compile_stdcxx_11.m4
@@ -9,7 +9,7 @@
 # DESCRIPTION
 #
 #   Check for baseline language coverage in the compiler for the C++11
-#   standard; if necessary, add switches to CXXFLAGS to enable support.
+#   standard; if necessary, add switches to CXX to enable support.
 #
 #   This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
 #   macro with the version set to C++11.  The two optional arguments are
diff --git a/m4/ax_cxx_compile_stdcxx_14.m4 b/m4/ax_cxx_compile_stdcxx_14.m4
index bd68432..4e59c62 100644
--- a/m4/ax_cxx_compile_stdcxx_14.m4
+++ b/m4/ax_cxx_compile_stdcxx_14.m4
@@ -9,7 +9,7 @@
 # DESCRIPTION
 #
 #   Check for baseline language coverage in the compiler for the C++14
-#   standard; if necessary, add switches to CXXFLAGS to enable support.
+#   standard; if necessary, add switches to CXX to enable support.
 #
 #   This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
 #   macro with the version set to C++14.  The two optional arguments are
-- 
1.7.10.4

