summaryrefslogtreecommitdiff
path: root/sntp/m4/ntp_cacheversion.m4
blob: 3619a603f524a5bb93ac912c651dfd04de0ac4ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# NTP_CACHEVERSION(component, version)
# ------------------------------------
# compare this configure script's cache version stamp with the stamp
# saved by the prior run in config.cache.  If they differ, clear all
# cache variables to avoid using results cached with a script that
# is known to differ in a cache-invalidating manner.
#
# Note: use immediately following AC_INIT in configure.ac, as clearing
# all _cv_ variables only makes sense immediately after loading, before
# use or modification.
#
# The top-level configure.ac in a subtree using NTP_CACHEVERSION
# will clear a previous cache lacking any saved cache version number,
# while children do not.  This comes into play only when introducing
# NTP_CACHEVERSION where it had not been previously used:  Previous
# cached results are presumed incompatible and not used.  The reason
# children do not flush the cached is it is shared with the parent and
# the children can rely on the parent having cleared any cache variables
# predating this mechanism.  Therefore the child can rely on the 
# config.cache generated by the parent on the first run despite not 
# finding the child version stamp in it.
#
# See html/copyright.html or COPYRIGHT in plain text.

AC_DEFUN_ONCE([NTP_CACHEVERSION], [
    AC_BEFORE([$0], [AM_INIT_AUTOMAKE])dnl
    AC_BEFORE([$0], [AC_CONFIG_HEADERS])dnl
    AC_BEFORE([$0], [AC_PROG_CC])dnl
    AC_BEFORE([$0], [AC_CONFIG_SUBDIRS])dnl

    ntp_cache_flush=1
    
    case "$ntp_cv_[$1]_cache_version" in
     [$2])
	# same version, good
	ntp_cache_flush=0
	;;
     '')
	# No cache, predates ntp_cv_$1_cache_version, or is empty.
	case "$cache_file" in
	 /dev/null)
	    ntp_cache_flush=0
	    ;;
	 *)
	    case "$NTP_CACHEVERSION_PARENT" in
	     '')
		# Do not clear the cache immediately after it is created
		# empty as it is noisy.  Differentiate a newly-created 
		# config.cache from one predating the cache version 
		# mechanism by looking for the first cached variable set 
		# by Autoconf
		case "$ac_cv_path_install" in
		 '')
		    # empty config.cache file
		    ntp_cache_flush=0
		esac
		;;
	     *)
		# Parent configure just created cache from empty,
		# flushing would be counterproductive.
		ntp_cache_flush=0;
		;;
	    esac
	esac
	;;
     *)
	# configure cache version mismatches config.cache version
	;;
    esac
    
    case "$ntp_cache_flush" in
     1)
	c_version="${ntp_cv_[$1]_cache_version:-(no version found)}"
	
	# Do we flush all variables or exclude others' version stamps?

	case "$NTP_CACHEVERSION_PARENT" in
	 '')
	    # Clear all *_cv_* variables including our child subdirs'
	    # ntp_cv_*_cache_version variables.  This prevents subdir
	    # configure scripts from noticing a version mismatch just
	    # after the top configure in the invocation cleared and
	    # recreated the cache.
	
	    c_varname_list=`set |
			    sed -n -e 's/=.*$//' \
				   -e '/_cv_/p'
			   `
	    ;;
	 *)
	    # This is not the top configure this particular invocation.
	    # Clear all *_cv_* variables sparing the version stamps
	    # of other configure scripts, so we don't trigger
	    # useless repeated clearings.

	    c_varname_list=`set |
			    sed -n -e 's/=.*$//' \
				   -e '/ntp_cv_.*_cache_version/d' \
				   -e '/_cv_/p'
			   `
	esac
	
	for c_varname in $c_varname_list
	do
	    dnl AS_UNSET([$c_varname])
	    dnl With Autoconf 2.61 and automake 1.10.3, using AS_UNSET
	    dnl here triggers generation of a syntax error in configure.
	    dnl Once we require a newer Autoconf we can revert to the
	    dnl AS_UNSET code.
	    { eval $c_varname=; unset $c_varname; }
	done
	
	AC_MSG_NOTICE([[$cache_file saved by another version, ignored.]])
	AC_MSG_NOTICE([[configure script cache version: ]][$2])
	AC_MSG_NOTICE([[$cache_file version: $c_version]])
	AS_UNSET([c_varname])
	AS_UNSET([c_varname_list])
	AS_UNSET([c_version])
    esac

    AS_UNSET([ntp_cache_flush])

    # save configure version in config.cache for next time
    ntp_cv_[$1]_cache_version="[$2]"

    # let any subdir configure.ac NTP_CACHEVERSION invocations
    # know they are not the top level.
    NTP_CACHEVERSION_PARENT='[$1]' ; export NTP_CACHEVERSION_PARENT
])dnl