build: start the configure cache cold when its answers may be stale

Three cases kept a cached answer that no longer held:

A new configure script. A package with an autoreconf fixup regenerates
configure with the staged autoconf, automake and libtool, and a new
version of one of them can change what a cache variable means. The site
script now keeps a checksum of configure beside the cache and drops the
cache when the checksum changes. A new patch to configure is covered too.

A changed precious variable. configure aborts when LIBS, CPP or another
precious variable differs from the value in the cache, and because
nothing removes the cache, it aborts on every later run as well:

  configure: error: 'LIBS' was not set in the previous run
  configure: error: changes in the environment can compromise the build

The site script now makes the same comparison before configure does and
drops the cache on a difference.

Paths under other names. The libtool answers lt_cv_path_*, acl_cv_path_*
and lt_cv_sys_global_symbol_*, and gmp_cv_prog_m4, hold the path of a
system tool or of the staged sed and m4, and survived a wipe of
staging_dir. The site script now drops them with the ac_cv_path_ answers.

m4 and gmp still configure the same way with a warm cache as they do
without one, and still read it: the m4 configure stage takes 1.5 s warm
against 23 s cold.

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin committed 2026-09-22 20:29:59 +02:00
1 parent 37f7186e75
commit 18a2ea702c
2 files changed
+37 -7

No files matched your search

+35 -5
View File
@@ -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
+2 -2
View File
@@ -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