From b79173943ac93078e9faf27b775eba78fa6b9d1a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 18 Jul 2020 16:54:13 +0200 Subject: [PATCH] Fix problem with caching in sub-configure scripts Since the changes of ef2b015e39 (Export CC and similar variables for sub-configure scripts, 2018-10-20), using "-C" option with configure didn't work any longer when also using built-in libtiff or expat, as their configure scripts aborted due to detecting inconsistent build environment because the values of exported CC etc variables they saw differed from the values in the cache file. Fixing this seems to be difficult, as we'd need to update the cache before running the sub-configure scripts (which is simple enough), but also remove the cached entries from it after doing it, as otherwise we'd get the same inconsistent build environment problem simply by running "configure -C" without any other options twice in a row, because the first run would cache CC=gcc etc. So work around this instead by disabling cache when exporting these variables. And to make this workaround less annoying, restrict it to only the cases when it's really needed, i.e. when we do modify these variables in a non-trivial way. With these changes, "configure -C" works again, but only uses caching if possible. --- configure | 16 +++++++++++++++- configure.in | 29 +++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 9698d321ea..2580e5dfba 100755 --- a/configure +++ b/configure @@ -18656,6 +18656,8 @@ fi fi +export_compiler_flags=no + if test "$USE_DARWIN" = 1; then retest_macosx_linking=no @@ -18708,6 +18710,8 @@ $as_echo "$as_me: WARNING: Disabling precompiled headers due to universal binary OBJCXXFLAGS="$OSX_ARCH_OPTS $OBJCXXFLAGS" OBJCFLAGS="$OSX_ARCH_OPTS $OBJCFLAGS" LDFLAGS="$OSX_ARCH_OPTS $LDFLAGS" + + export_compiler_flags=yes fi if test "$wxUSE_MAC" = 1; then @@ -18893,6 +18897,8 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu + + export_compiler_flags=yes fi fi @@ -19095,7 +19101,15 @@ if test "$USE_UNIX" = 1 ; then fi -export CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS LDD LDFLAGS OBJCFLAGS OBJCXXFLAGS +if test "$export_compiler_flags" = "yes"; then + export CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS LDD LDFLAGS OBJCFLAGS OBJCXXFLAGS + + if test "$cache_file" != "/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling caching due to a change in compiler options." >&5 +$as_echo "$as_me: WARNING: Disabling caching due to a change in compiler options." >&2;} + cache_file="/dev/null" + fi +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 diff --git a/configure.in b/configure.in index 91cc451dbd..69284c308e 100644 --- a/configure.in +++ b/configure.in @@ -1177,6 +1177,11 @@ dnl --------------------------------------------------------------------------- dnl Mac-specific SDK/architectures checks dnl --------------------------------------------------------------------------- +dnl If we modify compiler or compiler flags variables in non-trivial way (e.g. +dnl by specifying the non-default architecture to use), we need to export them +dnl after doing it, so that sub-configure scripts use the same values too. +export_compiler_flags=no + dnl Note that some checks here are OS-specific, and need to be done for any dnl port, while others are wxOSX-specific and are performed only for it inside dnl another test below. @@ -1250,6 +1255,8 @@ if test "x$OSX_ARCH_OPTS" != "x"; then OBJCXXFLAGS="$OSX_ARCH_OPTS $OBJCXXFLAGS" OBJCFLAGS="$OSX_ARCH_OPTS $OBJCFLAGS" LDFLAGS="$OSX_ARCH_OPTS $LDFLAGS" + + export_compiler_flags=yes fi if test "$wxUSE_MAC" = 1; then @@ -1384,6 +1391,12 @@ version or omitting it entirely." [AC_MSG_FAILURE([$error_message])] ) AC_LANG_POP() + + dnl If we are here, we must have set retest_macosx_linking to yes above, + dnl i.e. we must have modified compiler/linker variables to set + dnl SDK/availability options, and so we must export them to build any + dnl bundled third party libraries with them too. + export_compiler_flags=yes fi fi dnl USE_DARWIN @@ -1541,8 +1554,20 @@ if test "$USE_UNIX" = 1 ; then fi dnl Values of these variables shouldn't change any longer from now on, we -dnl export them to ensure they're picked up by sub-configure scripts. -export CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS LDD LDFLAGS OBJCFLAGS OBJCXXFLAGS +dnl export them to ensure they're picked up by sub-configure scripts if they +dnl were modified above. +if test "$export_compiler_flags" = "yes"; then + export CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS LDD LDFLAGS OBJCFLAGS OBJCXXFLAGS + + if test "$cache_file" != "/dev/null"; then + dnl We must do this to avoid fatal errors due to inconsistent build + dnl environment from sub-configure scripts. We could do it just before + dnl actually running them, but doing it here is simpler and more robust + dnl (e.g. in case we add other sub-configure scripts later). + AC_MSG_WARN([Disabling caching due to a change in compiler options.]) + cache_file="/dev/null" + fi +fi dnl ------------------------------------------------------------------------ dnl Check for headers