1275970Scy# NTP_CACHEVERSION(component, version)
2275970Scy# ------------------------------------
3275970Scy# compare this configure script's cache version stamp with the stamp
4275970Scy# saved by the prior run in config.cache.  If they differ, clear all
5275970Scy# cache variables to avoid using results cached with a script that
6275970Scy# is known to differ in a cache-invalidating manner.
7275970Scy#
8275970Scy# Note: use immediately following AC_INIT in configure.ac, as clearing
9275970Scy# all _cv_ variables only makes sense immediately after loading, before
10275970Scy# use or modification.
11275970Scy#
12275970Scy# The top-level configure.ac in a subtree using NTP_CACHEVERSION
13275970Scy# will clear a previous cache lacking any saved cache version number,
14275970Scy# while children do not.  This comes into play only when introducing
15275970Scy# NTP_CACHEVERSION where it had not been previously used:  Previous
16275970Scy# cached results are presumed incompatible and not used.  The reason
17275970Scy# children do not flush the cached is it is shared with the parent and
18275970Scy# the children can rely on the parent having cleared any cache variables
19275970Scy# predating this mechanism.  Therefore the child can rely on the 
20275970Scy# config.cache generated by the parent on the first run despite not 
21275970Scy# finding the child version stamp in it.
22275970Scy#
23275970Scy# See html/copyright.html or COPYRIGHT in plain text.
24275970Scy
25275970ScyAC_DEFUN_ONCE([NTP_CACHEVERSION], [
26275970Scy    AC_BEFORE([$0], [AM_INIT_AUTOMAKE])dnl
27275970Scy    AC_BEFORE([$0], [AC_CONFIG_HEADERS])dnl
28275970Scy    AC_BEFORE([$0], [AC_PROG_CC])dnl
29275970Scy    AC_BEFORE([$0], [AC_CONFIG_SUBDIRS])dnl
30275970Scy
31275970Scy    ntp_cache_flush=1
32275970Scy    
33275970Scy    case "$ntp_cv_[$1]_cache_version" in
34275970Scy     [$2])
35275970Scy	# same version, good
36275970Scy	ntp_cache_flush=0
37275970Scy	;;
38275970Scy     '')
39275970Scy	# No cache, predates ntp_cv_$1_cache_version, or is empty.
40275970Scy	case "$cache_file" in
41275970Scy	 /dev/null)
42275970Scy	    ntp_cache_flush=0
43275970Scy	    ;;
44275970Scy	 *)
45275970Scy	    case "$NTP_CACHEVERSION_PARENT" in
46275970Scy	     '')
47275970Scy		# Do not clear the cache immediately after it is created
48275970Scy		# empty as it is noisy.  Differentiate a newly-created 
49275970Scy		# config.cache from one predating the cache version 
50275970Scy		# mechanism by looking for the first cached variable set 
51275970Scy		# by Autoconf
52275970Scy		case "$ac_cv_path_install" in
53275970Scy		 '')
54275970Scy		    # empty config.cache file
55275970Scy		    ntp_cache_flush=0
56275970Scy		esac
57275970Scy		;;
58275970Scy	     *)
59275970Scy		# Parent configure just created cache from empty,
60275970Scy		# flushing would be counterproductive.
61275970Scy		ntp_cache_flush=0;
62275970Scy		;;
63275970Scy	    esac
64275970Scy	esac
65275970Scy	;;
66275970Scy     *)
67275970Scy	# configure cache version mismatches config.cache version
68275970Scy	;;
69275970Scy    esac
70275970Scy    
71275970Scy    case "$ntp_cache_flush" in
72275970Scy     1)
73275970Scy	c_version="${ntp_cv_[$1]_cache_version:-(no version found)}"
74275970Scy	
75275970Scy	# Do we flush all variables or exclude others' version stamps?
76275970Scy
77275970Scy	case "$NTP_CACHEVERSION_PARENT" in
78275970Scy	 '')
79275970Scy	    # Clear all *_cv_* variables including our child subdirs'
80275970Scy	    # ntp_cv_*_cache_version variables.  This prevents subdir
81275970Scy	    # configure scripts from noticing a version mismatch just
82275970Scy	    # after the top configure in the invocation cleared and
83275970Scy	    # recreated the cache.
84275970Scy	
85275970Scy	    c_varname_list=`set |
86275970Scy			    sed -n -e 's/=.*$//' \
87275970Scy				   -e '/_cv_/p'
88275970Scy			   `
89275970Scy	    ;;
90275970Scy	 *)
91275970Scy	    # This is not the top configure this particular invocation.
92275970Scy	    # Clear all *_cv_* variables sparing the version stamps
93275970Scy	    # of other configure scripts, so we don't trigger
94275970Scy	    # useless repeated clearings.
95275970Scy
96275970Scy	    c_varname_list=`set |
97275970Scy			    sed -n -e 's/=.*$//' \
98275970Scy				   -e '/ntp_cv_.*_cache_version/d' \
99275970Scy				   -e '/_cv_/p'
100275970Scy			   `
101275970Scy	esac
102275970Scy	
103275970Scy	for c_varname in $c_varname_list
104275970Scy	do
105275970Scy	    dnl AS_UNSET([$c_varname])
106275970Scy	    dnl With Autoconf 2.61 and automake 1.10.3, using AS_UNSET
107275970Scy	    dnl here triggers generation of a syntax error in configure.
108275970Scy	    dnl Once we require a newer Autoconf we can revert to the
109275970Scy	    dnl AS_UNSET code.
110275970Scy	    { eval $c_varname=; unset $c_varname; }
111275970Scy	done
112275970Scy	
113275970Scy	AC_MSG_NOTICE([[$cache_file saved by another version, ignored.]])
114275970Scy	AC_MSG_NOTICE([[configure script cache version: ]][$2])
115275970Scy	AC_MSG_NOTICE([[$cache_file version: $c_version]])
116275970Scy	AS_UNSET([c_varname])
117275970Scy	AS_UNSET([c_varname_list])
118275970Scy	AS_UNSET([c_version])
119275970Scy    esac
120275970Scy
121275970Scy    AS_UNSET([ntp_cache_flush])
122275970Scy
123275970Scy    # save configure version in config.cache for next time
124275970Scy    ntp_cv_[$1]_cache_version="[$2]"
125275970Scy
126275970Scy    # let any subdir configure.ac NTP_CACHEVERSION invocations
127275970Scy    # know they are not the top level.
128275970Scy    NTP_CACHEVERSION_PARENT='[$1]' ; export NTP_CACHEVERSION_PARENT
129275970Scy])dnl
130