12b15cb3dSCy Schubert# NTP_CACHEVERSION(component, version)
22b15cb3dSCy Schubert# ------------------------------------
32b15cb3dSCy Schubert# compare this configure script's cache version stamp with the stamp
42b15cb3dSCy Schubert# saved by the prior run in config.cache.  If they differ, clear all
52b15cb3dSCy Schubert# cache variables to avoid using results cached with a script that
62b15cb3dSCy Schubert# is known to differ in a cache-invalidating manner.
72b15cb3dSCy Schubert#
82b15cb3dSCy Schubert# Note: use immediately following AC_INIT in configure.ac, as clearing
92b15cb3dSCy Schubert# all _cv_ variables only makes sense immediately after loading, before
102b15cb3dSCy Schubert# use or modification.
112b15cb3dSCy Schubert#
122b15cb3dSCy Schubert# The top-level configure.ac in a subtree using NTP_CACHEVERSION
132b15cb3dSCy Schubert# will clear a previous cache lacking any saved cache version number,
142b15cb3dSCy Schubert# while children do not.  This comes into play only when introducing
152b15cb3dSCy Schubert# NTP_CACHEVERSION where it had not been previously used:  Previous
162b15cb3dSCy Schubert# cached results are presumed incompatible and not used.  The reason
17*a466cc55SCy Schubert# children do not flush the cache is it is shared with the parent and
182b15cb3dSCy Schubert# the children can rely on the parent having cleared any cache variables
192b15cb3dSCy Schubert# predating this mechanism.  Therefore the child can rely on the
202b15cb3dSCy Schubert# config.cache generated by the parent on the first run despite not
212b15cb3dSCy Schubert# finding the child version stamp in it.
222b15cb3dSCy Schubert#
232b15cb3dSCy Schubert# See html/copyright.html or COPYRIGHT in plain text.
242b15cb3dSCy Schubert
252b15cb3dSCy SchubertAC_DEFUN_ONCE([NTP_CACHEVERSION], [
262b15cb3dSCy Schubert    AC_BEFORE([$0], [AM_INIT_AUTOMAKE])dnl
272b15cb3dSCy Schubert    AC_BEFORE([$0], [AC_CONFIG_HEADERS])dnl
282b15cb3dSCy Schubert    AC_BEFORE([$0], [AC_PROG_CC])dnl
292b15cb3dSCy Schubert    AC_BEFORE([$0], [AC_CONFIG_SUBDIRS])dnl
302b15cb3dSCy Schubert
312b15cb3dSCy Schubert    ntp_cache_flush=1
322b15cb3dSCy Schubert
332b15cb3dSCy Schubert    case "$ntp_cv_[$1]_cache_version" in
342b15cb3dSCy Schubert     [$2])
352b15cb3dSCy Schubert	# same version, good
362b15cb3dSCy Schubert	ntp_cache_flush=0
372b15cb3dSCy Schubert	;;
382b15cb3dSCy Schubert     '')
392b15cb3dSCy Schubert	# No cache, predates ntp_cv_$1_cache_version, or is empty.
402b15cb3dSCy Schubert	case "$cache_file" in
412b15cb3dSCy Schubert	 /dev/null)
422b15cb3dSCy Schubert	    ntp_cache_flush=0
432b15cb3dSCy Schubert	    ;;
442b15cb3dSCy Schubert	 *)
452b15cb3dSCy Schubert	    case "$NTP_CACHEVERSION_PARENT" in
462b15cb3dSCy Schubert	     '')
472b15cb3dSCy Schubert		# Do not clear the cache immediately after it is created
482b15cb3dSCy Schubert		# empty as it is noisy.  Differentiate a newly-created
492b15cb3dSCy Schubert		# config.cache from one predating the cache version
502b15cb3dSCy Schubert		# mechanism by looking for the first cached variable set
512b15cb3dSCy Schubert		# by Autoconf
522b15cb3dSCy Schubert		case "$ac_cv_path_install" in
532b15cb3dSCy Schubert		 '')
542b15cb3dSCy Schubert		    # empty config.cache file
552b15cb3dSCy Schubert		    ntp_cache_flush=0
562b15cb3dSCy Schubert		esac
572b15cb3dSCy Schubert		;;
582b15cb3dSCy Schubert	     *)
592b15cb3dSCy Schubert		# Parent configure just created cache from empty,
602b15cb3dSCy Schubert		# flushing would be counterproductive.
612b15cb3dSCy Schubert		ntp_cache_flush=0;
622b15cb3dSCy Schubert		;;
632b15cb3dSCy Schubert	    esac
642b15cb3dSCy Schubert	esac
652b15cb3dSCy Schubert	;;
662b15cb3dSCy Schubert     *)
672b15cb3dSCy Schubert	# configure cache version mismatches config.cache version
682b15cb3dSCy Schubert	;;
692b15cb3dSCy Schubert    esac
702b15cb3dSCy Schubert
712b15cb3dSCy Schubert    case "$ntp_cache_flush" in
722b15cb3dSCy Schubert     1)
732b15cb3dSCy Schubert	c_version="${ntp_cv_[$1]_cache_version:-(no version found)}"
742b15cb3dSCy Schubert
752b15cb3dSCy Schubert	# Do we flush all variables or exclude others' version stamps?
762b15cb3dSCy Schubert
772b15cb3dSCy Schubert	case "$NTP_CACHEVERSION_PARENT" in
782b15cb3dSCy Schubert	 '')
792b15cb3dSCy Schubert	    # Clear all *_cv_* variables including our child subdirs'
802b15cb3dSCy Schubert	    # ntp_cv_*_cache_version variables.  This prevents subdir
812b15cb3dSCy Schubert	    # configure scripts from noticing a version mismatch just
822b15cb3dSCy Schubert	    # after the top configure in the invocation cleared and
832b15cb3dSCy Schubert	    # recreated the cache.
842b15cb3dSCy Schubert
852b15cb3dSCy Schubert	    c_varname_list=`set |
862b15cb3dSCy Schubert			    sed -n -e 's/=.*$//' \
872b15cb3dSCy Schubert				   -e '/_cv_/p'
882b15cb3dSCy Schubert			   `
892b15cb3dSCy Schubert	    ;;
902b15cb3dSCy Schubert	 *)
912b15cb3dSCy Schubert	    # This is not the top configure this particular invocation.
922b15cb3dSCy Schubert	    # Clear all *_cv_* variables sparing the version stamps
932b15cb3dSCy Schubert	    # of other configure scripts, so we don't trigger
942b15cb3dSCy Schubert	    # useless repeated clearings.
952b15cb3dSCy Schubert
962b15cb3dSCy Schubert	    c_varname_list=`set |
972b15cb3dSCy Schubert			    sed -n -e 's/=.*$//' \
982b15cb3dSCy Schubert				   -e '/ntp_cv_.*_cache_version/d' \
992b15cb3dSCy Schubert				   -e '/_cv_/p'
1002b15cb3dSCy Schubert			   `
1012b15cb3dSCy Schubert	esac
1022b15cb3dSCy Schubert
1032b15cb3dSCy Schubert	for c_varname in $c_varname_list
1042b15cb3dSCy Schubert	do
105*a466cc55SCy Schubert	    AS_UNSET([$c_varname])
1062b15cb3dSCy Schubert	done
1072b15cb3dSCy Schubert
1082b15cb3dSCy Schubert	AC_MSG_NOTICE([[$cache_file saved by another version, ignored.]])
1092b15cb3dSCy Schubert	AC_MSG_NOTICE([[configure script cache version: ]][$2])
1102b15cb3dSCy Schubert	AC_MSG_NOTICE([[$cache_file version: $c_version]])
1112b15cb3dSCy Schubert	AS_UNSET([c_varname])
1122b15cb3dSCy Schubert	AS_UNSET([c_varname_list])
1132b15cb3dSCy Schubert	AS_UNSET([c_version])
1142b15cb3dSCy Schubert    esac
1152b15cb3dSCy Schubert
1162b15cb3dSCy Schubert    AS_UNSET([ntp_cache_flush])
1172b15cb3dSCy Schubert
1182b15cb3dSCy Schubert    # save configure version in config.cache for next time
1192b15cb3dSCy Schubert    ntp_cv_[$1]_cache_version="[$2]"
1202b15cb3dSCy Schubert
1212b15cb3dSCy Schubert    # let any subdir configure.ac NTP_CACHEVERSION invocations
1222b15cb3dSCy Schubert    # know they are not the top level.
1232b15cb3dSCy Schubert    NTP_CACHEVERSION_PARENT='[$1]' ; export NTP_CACHEVERSION_PARENT
1242b15cb3dSCy Schubert])dnl
125