diff --git a/include/site/cache b/include/site/cache index 7a19181c6fe..3b871602129 100644 --- a/include/site/cache +++ b/include/site/cache @@ -21,17 +21,47 @@ if [ -n "$CONFIGURE_CACHE_FILE" ]; then # A change of the configure arguments gives a new file name. Drop the # file of the previous arguments so that the directory holds one cache # per package. - for configure_cache_stale in "$configure_cache_dir"/*.cache; do + for configure_cache_stale in "$configure_cache_dir"/*.cache "$configure_cache_dir"/*.cache.sum; do [ -f "$configure_cache_stale" ] || continue - [ "$configure_cache_stale" = "$CONFIGURE_CACHE_FILE" ] || rm -f "$configure_cache_stale" + [ "${configure_cache_stale%.sum}" = "$CONFIGURE_CACHE_FILE" ] || rm -f "$configure_cache_stale" done + # An autoreconf run with a new autoconf, automake or libtool, or a new + # patch, gives a new configure script whose checks can mean something + # else under the same cache variable name. + configure_cache_sum=$(cksum < "${as_myself:-$0}") + if [ "$configure_cache_sum" != "$(cat "$CONFIGURE_CACHE_FILE.sum" 2>/dev/null)" ]; then + rm -f "$CONFIGURE_CACHE_FILE" + printf '%s\n' "$configure_cache_sum" > "$CONFIGURE_CACHE_FILE.sum" + fi + + # configure aborts when a precious variable such as LIBS or CPP differs + # from the value in the cache, and it aborts again on every later run. + # Make the same comparison here and start from a cold cache instead. + if [ -f "$CONFIGURE_CACHE_FILE" ] && ! ( + set -f + . "$CONFIGURE_CACHE_FILE" + for ac_var in $ac_precious_vars; do + eval "old_set=\$ac_cv_env_${ac_var}_set new_set=\$ac_env_${ac_var}_set" + [ "$old_set" = "$new_set" ] || exit 1 + eval "set -- \$ac_cv_env_${ac_var}_value" + old_val=$* + eval "set -- \$ac_env_${ac_var}_value" + [ "$old_val" = "$*" ] || exit 1 + done + ); then + rm -f "$CONFIGURE_CACHE_FILE" + fi + # A cached program path outlives a wipe of staging_dir, so it can name a # tool that is gone, or miss one that the build installed since. Drop # those answers and let configure search PATH again. A search runs no - # compiler, and the compiler is where the time goes. + # compiler, and the compiler is where the time goes. The libtool and gmp + # answers hold the path of the staged sed and m4. if [ -f "$CONFIGURE_CACHE_FILE" ]; then - grep -v -e '^ac_cv_path_' -e '^ac_cv_prog_' \ + grep -v -e '^[a-z]*_cv_path_' -e '^ac_cv_prog_' -e '^gmp_cv_prog_' \ + -e '^lt_cv_sys_global_symbol_' -e '^lt_cv_truncate_bin=' \ + -e '^ac_cv_AM_TEST_RUNNER_SHELL=' \ "$CONFIGURE_CACHE_FILE" > "$CONFIGURE_CACHE_FILE.tmp" mv -f "$CONFIGURE_CACHE_FILE.tmp" "$CONFIGURE_CACHE_FILE" fi @@ -40,5 +70,5 @@ if [ -n "$CONFIGURE_CACHE_FILE" ]; then # A configure script that runs further configure scripts must not hand # this cache to them. Their checks run with different flags. - unset CONFIGURE_CACHE_FILE configure_cache_dir configure_cache_stale + unset CONFIGURE_CACHE_FILE configure_cache_dir configure_cache_stale configure_cache_sum fi diff --git a/rules.mk b/rules.mk index 2eba07279e3..3adf4ec2fc0 100644 --- a/rules.mk +++ b/rules.mk @@ -220,8 +220,8 @@ endif # # The path covers everything that changes an answer: the toolchain for a target # package, the host compiler for a host package, and a hash of the configure -# arguments and build flags for both. autoconf refuses a cache that it wrote -# with different flags on top of that. +# arguments and build flags for both. include/site/cache also starts from a +# cold cache when the configure script or a precious variable changed. # # A package must opt in, because a cache is only correct for a configure script # that keeps its side effects outside the AC_CACHE_VAL body. ncurses appends