build: Fix AX_PROG_{CC,CXX}_FOR_BUILD macros
authorThierry Reding <thierry.reding@avionic-design.de>
Tue, 20 Nov 2012 15:50:35 +0000 (16:50 +0100)
committerMatt Turner <mattst88@gmail.com>
Thu, 13 Dec 2012 18:58:11 +0000 (10:58 -0800)
Override the cross_compiling and ac_tool_prefix variables by reassigning
to them instead of redefining the macros. Redefining them will actually
cause the variable names to be replaced instead of their content.

Furthermore push the definition of CPPFLAGS before running the checks
for the build tools to avoid the host CPPFLAGS from leaking into the
build CPPFLAGS.

While at it drop the redefinition of AC_TRY_COMPILER which hasn't been
used since autoconf 2.50 and make sure that all definitions are properly
popped when done (LDFLAGS, ac_cv_prog_CPP, ac_cv_prog_CXXCPP).

Acked-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
m4/ax_prog_cc_for_build.m4
m4/ax_prog_cxx_for_build.m4

index 08095a83dfccb0926eaf92d33a0927df888045af..6369809aadd79c9561831be3a37ee4c7cf05c718 100644 (file)
@@ -40,30 +40,9 @@ AC_REQUIRE([AC_PROG_CC])dnl
 AC_REQUIRE([AC_PROG_CPP])dnl
 AC_REQUIRE([AC_EXEEXT])dnl
 AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl
-dnl
-pushdef([AC_TRY_COMPILER], [
-cat > conftest.$ac_ext << EOF
-#line __oline__ "configure"
-#include "confdefs.h"
-[$1]
-EOF
-# If we can't run a trivial program, we are probably using a cross
-compiler.
-# Fail miserably.
-if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} && (./conftest;
-exit) 2>/dev/null; then
-  [$2]=yes
-else
-  echo "configure: failed program was:" >&AC_FD_CC
-  cat conftest.$ac_ext >&AC_FD_CC
-  [$2]=no
-fi
-[$3]=no
-rm -fr conftest*])dnl
 
 dnl Use the standard macros, but make them use other variable names
 dnl
-pushdef([cross_compiling], [#])dnl
 pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
 pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
 pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
@@ -91,16 +70,21 @@ pushdef([ac_cv_host_os], ac_cv_build_os)dnl
 pushdef([ac_cpp], ac_build_cpp)dnl
 pushdef([ac_compile], ac_build_compile)dnl
 pushdef([ac_link], ac_build_link)dnl
-pushdef([ac_tool_prefix], [#])dnl
+
+save_cross_compiling=$cross_compiling
+save_ac_tool_prefix=$ac_tool_prefix
+cross_compiling=no
+ac_tool_prefix=
 
 AC_PROG_CC
 AC_PROG_CPP
 AC_EXEEXT
 
+ac_tool_prefix=$save_ac_tool_prefix
+cross_compiling=$save_cross_compiling
+
 dnl Restore the old definitions
 dnl
-popdef([AC_TRY_COMPILER])dnl
-popdef([ac_tool_prefix])dnl
 popdef([ac_link])dnl
 popdef([ac_compile])dnl
 popdef([ac_cpp])dnl
@@ -114,6 +98,7 @@ popdef([host_vendor])dnl
 popdef([host_cpu])dnl
 popdef([host_alias])dnl
 popdef([host])dnl
+popdef([LDFLAGS])dnl
 popdef([CPPFLAGS])dnl
 popdef([CFLAGS])dnl
 popdef([CPP])dnl
@@ -123,10 +108,10 @@ popdef([ac_exeext])dnl
 popdef([ac_cv_objext])dnl
 popdef([ac_cv_exeext])dnl
 popdef([ac_cv_prog_cc_g])dnl
-popdef([ac_cv_prog_cc_works])dnl
 popdef([ac_cv_prog_cc_cross])dnl
+popdef([ac_cv_prog_cc_works])dnl
 popdef([ac_cv_prog_gcc])dnl
-popdef([cross_compiling])dnl
+popdef([ac_cv_prog_CPP])dnl
 
 dnl Finally, set Makefile variables
 dnl
index 4a099f9fbd8693d6156e8eac8b5cb6a80d41eac0..ecf8db94e4888ef9d70228c58421092c9d6c005c 100644 (file)
@@ -38,30 +38,9 @@ AC_REQUIRE([AX_PROG_CC_FOR_BUILD])dnl
 AC_REQUIRE([AC_PROG_CXX])dnl
 AC_REQUIRE([AC_PROG_CXXCPP])dnl
 AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl
-dnl
-pushdef([AC_TRY_COMPILER], [
-cat > conftest.$ac_ext << EOF
-#line __oline__ "configure"
-#include "confdefs.h"
-[$1]
-EOF
-# If we can't run a trivial program, we are probably using a cross
-compiler.
-# Fail miserably.
-if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} && (./conftest;
-exit) 2>/dev/null; then
-  [$2]=yes
-else
-  echo "configure: failed program was:" >&AC_FD_CC
-  cat conftest.$ac_ext >&AC_FD_CC
-  [$2]=no
-fi
-[$3]=no
-rm -fr conftest*])dnl
 
 dnl Use the standard macros, but make them use other variable names
 dnl
-pushdef([cross_compiling], [#])dnl
 pushdef([ac_cv_prog_CXXCPP], ac_cv_build_prog_CXXCPP)dnl
 pushdef([ac_cv_prog_gxx], ac_cv_build_prog_gxx)dnl
 pushdef([ac_cv_prog_cxx_works], ac_cv_build_prog_cxx_works)dnl
@@ -70,6 +49,7 @@ pushdef([ac_cv_prog_cxx_g], ac_cv_build_prog_cxx_g)dnl
 pushdef([CXX], CXX_FOR_BUILD)dnl
 pushdef([CXXCPP], CXXCPP_FOR_BUILD)dnl
 pushdef([CXXFLAGS], CXXFLAGS_FOR_BUILD)dnl
+pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
 pushdef([CXXCPPFLAGS], CXXCPPFLAGS_FOR_BUILD)dnl
 pushdef([host], build)dnl
 pushdef([host_alias], build_alias)dnl
@@ -84,15 +64,20 @@ pushdef([ac_cv_host_os], ac_cv_build_os)dnl
 pushdef([ac_cxxcpp], ac_build_cxxcpp)dnl
 pushdef([ac_compile], ac_build_compile)dnl
 pushdef([ac_link], ac_build_link)dnl
-pushdef([ac_tool_prefix], [#])dnl
+
+save_cross_compiling=$cross_compiling
+save_ac_tool_prefix=$ac_tool_prefix
+cross_compiling=no
+ac_tool_prefix=
 
 AC_PROG_CXX
 AC_PROG_CXXCPP
 
+ac_tool_prefix=$save_ac_tool_prefix
+cross_compiling=$save_cross_compiling
+
 dnl Restore the old definitions
 dnl
-popdef([AC_TRY_COMPILER])dnl
-popdef([ac_tool_prefix])dnl
 popdef([ac_link])dnl
 popdef([ac_compile])dnl
 popdef([ac_cxxcpp])dnl
@@ -107,14 +92,15 @@ popdef([host_cpu])dnl
 popdef([host_alias])dnl
 popdef([host])dnl
 popdef([CXXCPPFLAGS])dnl
+popdef([CPPFLAGS])dnl
 popdef([CXXFLAGS])dnl
 popdef([CXXCPP])dnl
 popdef([CXX])dnl
 popdef([ac_cv_prog_cxx_g])dnl
-popdef([ac_cv_prog_cxx_works])dnl
 popdef([ac_cv_prog_cxx_cross])dnl
+popdef([ac_cv_prog_cxx_works])dnl
 popdef([ac_cv_prog_gxx])dnl
-popdef([cross_compiling])dnl
+popdef([ac_cv_prog_CXXCPP])dnl
 
 dnl Finally, set Makefile variables
 dnl