]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/sntp/m4/ntp_cacheversion.m4
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / sntp / m4 / ntp_cacheversion.m4
1 # NTP_CACHEVERSION(component, version)
2 # ------------------------------------
3 # compare this configure script's cache version stamp with the stamp
4 # saved by the prior run in config.cache.  If they differ, clear all
5 # cache variables to avoid using results cached with a script that
6 # is known to differ in a cache-invalidating manner.
7 #
8 # Note: use immediately following AC_INIT in configure.ac, as clearing
9 # all _cv_ variables only makes sense immediately after loading, before
10 # use or modification.
11 #
12 # The top-level configure.ac in a subtree using NTP_CACHEVERSION
13 # will clear a previous cache lacking any saved cache version number,
14 # while children do not.  This comes into play only when introducing
15 # NTP_CACHEVERSION where it had not been previously used:  Previous
16 # cached results are presumed incompatible and not used.  The reason
17 # children do not flush the cached is it is shared with the parent and
18 # the children can rely on the parent having cleared any cache variables
19 # predating this mechanism.  Therefore the child can rely on the 
20 # config.cache generated by the parent on the first run despite not 
21 # finding the child version stamp in it.
22 #
23 # See html/copyright.html or COPYRIGHT in plain text.
24
25 AC_DEFUN_ONCE([NTP_CACHEVERSION], [
26     AC_BEFORE([$0], [AM_INIT_AUTOMAKE])dnl
27     AC_BEFORE([$0], [AC_CONFIG_HEADERS])dnl
28     AC_BEFORE([$0], [AC_PROG_CC])dnl
29     AC_BEFORE([$0], [AC_CONFIG_SUBDIRS])dnl
30
31     ntp_cache_flush=1
32     
33     case "$ntp_cv_[$1]_cache_version" in
34      [$2])
35         # same version, good
36         ntp_cache_flush=0
37         ;;
38      '')
39         # No cache, predates ntp_cv_$1_cache_version, or is empty.
40         case "$cache_file" in
41          /dev/null)
42             ntp_cache_flush=0
43             ;;
44          *)
45             case "$NTP_CACHEVERSION_PARENT" in
46              '')
47                 # Do not clear the cache immediately after it is created
48                 # empty as it is noisy.  Differentiate a newly-created 
49                 # config.cache from one predating the cache version 
50                 # mechanism by looking for the first cached variable set 
51                 # by Autoconf
52                 case "$ac_cv_path_install" in
53                  '')
54                     # empty config.cache file
55                     ntp_cache_flush=0
56                 esac
57                 ;;
58              *)
59                 # Parent configure just created cache from empty,
60                 # flushing would be counterproductive.
61                 ntp_cache_flush=0;
62                 ;;
63             esac
64         esac
65         ;;
66      *)
67         # configure cache version mismatches config.cache version
68         ;;
69     esac
70     
71     case "$ntp_cache_flush" in
72      1)
73         c_version="${ntp_cv_[$1]_cache_version:-(no version found)}"
74         
75         # Do we flush all variables or exclude others' version stamps?
76
77         case "$NTP_CACHEVERSION_PARENT" in
78          '')
79             # Clear all *_cv_* variables including our child subdirs'
80             # ntp_cv_*_cache_version variables.  This prevents subdir
81             # configure scripts from noticing a version mismatch just
82             # after the top configure in the invocation cleared and
83             # recreated the cache.
84         
85             c_varname_list=`set |
86                             sed -n -e 's/=.*$//' \
87                                    -e '/_cv_/p'
88                            `
89             ;;
90          *)
91             # This is not the top configure this particular invocation.
92             # Clear all *_cv_* variables sparing the version stamps
93             # of other configure scripts, so we don't trigger
94             # useless repeated clearings.
95
96             c_varname_list=`set |
97                             sed -n -e 's/=.*$//' \
98                                    -e '/ntp_cv_.*_cache_version/d' \
99                                    -e '/_cv_/p'
100                            `
101         esac
102         
103         for c_varname in $c_varname_list
104         do
105             dnl AS_UNSET([$c_varname])
106             dnl With Autoconf 2.61 and automake 1.10.3, using AS_UNSET
107             dnl here triggers generation of a syntax error in configure.
108             dnl Once we require a newer Autoconf we can revert to the
109             dnl AS_UNSET code.
110             { eval $c_varname=; unset $c_varname; }
111         done
112         
113         AC_MSG_NOTICE([[$cache_file saved by another version, ignored.]])
114         AC_MSG_NOTICE([[configure script cache version: ]][$2])
115         AC_MSG_NOTICE([[$cache_file version: $c_version]])
116         AS_UNSET([c_varname])
117         AS_UNSET([c_varname_list])
118         AS_UNSET([c_version])
119     esac
120
121     AS_UNSET([ntp_cache_flush])
122
123     # save configure version in config.cache for next time
124     ntp_cv_[$1]_cache_version="[$2]"
125
126     # let any subdir configure.ac NTP_CACHEVERSION invocations
127     # know they are not the top level.
128     NTP_CACHEVERSION_PARENT='[$1]' ; export NTP_CACHEVERSION_PARENT
129 ])dnl