1dnl
2dnl/*D
3dnl AC_CACHE_LOAD - Replacement for autoconf cache load
4dnl
5dnl Notes:
6dnl Caching in autoconf is broken (at least through version 2.13).
7dnl The problem is that the cache is read
8dnl without any check for whether it makes any sense to read it.
9dnl A common problem is a build on a shared file system; connecting to
10dnl a different computer and then building within the same directory will
11dnl lead to at best error messages from configure and at worse a build that
12dnl is wrong but fails only at run time (e.g., wrong datatype sizes used).
13dnl Later versions of autoconf do include some checks for changes in the
14dnl environment that impact the choices, but still misses problems with
15dnl multiple different systems.
16dnl
17dnl This fixes that by requiring the user to explicitly enable caching
18dnl before the cache file will be loaded.
19dnl
20dnl To use this version of 'AC_CACHE_LOAD', you need to include
21dnl 'aclocal_cache.m4' in your 'aclocal.m4' file.  The sowing 'aclocal.m4'
22dnl file includes this file.
23dnl
24dnl If no --enable-cache or --disable-cache option is selected, the
25dnl command causes configure to keep track of the system being configured
26dnl in a config.system file; if the current system matches the value stored
27dnl in that file (or there is neither a config.cache nor config.system file),
28dnl configure will enable caching.  In order to ensure that the configure
29dnl tests make sense, the values of CC, F77, F90, and CXX are also included
30dnl in the config.system file.  In addition, the value of PATH is included
31dnl to ensure that changes in the PATH that might select a different version
32dnl of a program with the same name (such as a native make versus gnumake)
33dnl are detected.
34dnl
35dnl Bugs:
36dnl This does not work with the Cygnus configure because the enable arguments
37dnl are processed *after* AC_CACHE_LOAD (!).  To address this, we avoid
38dnl changing the value of enable_cache, and use real_enable_cache, duplicating
39dnl the "notgiven" value.
40dnl
41dnl The environment variable CONFIGURE_DEBUG_CACHE, if set to yes,
42dnl will cause additional data to be written out during the configure process.
43dnl This can be helpful in debugging the cache file process.
44dnl
45dnl See Also:
46dnl PAC_ARG_CACHING
47dnl D*/
48define([AC_CACHE_LOAD],
49[if test "$CONFIGURE_DEBUG_CACHE" = yes ; then
50    oldopts="$-"
51    clearMinusX=no
52    set -x
53    if test "$oldopts" != "$-" ; then
54        clearMinusX=yes
55    fi
56fi
57if test "X$cache_system" = "X" ; then
58    # A default file name, just in case
59    cache_system="config.system"
60    if test "$cache_file" != "/dev/null" ; then
61        # Get the directory for the cache file, if any
62	changequote(,)
63        dnl Be careful to ensure that there is no doubled slash
64        cache_system=`echo $cache_file | sed -e 's%^\(.*/\)[^/]*%\1config.system%'`
65	changequote([,])
66        test "x$cache_system" = "x$cache_file" && cache_system="config.system"
67#    else
68#        We must *not* set enable_cache to no because we need to know if
69#        enable_cache was not set.
70#        enable_cache=no
71    fi
72fi
73dnl
74dnl The "action-if-not-given" part of AC_ARG_ENABLE is not executed until
75dnl after the AC_CACHE_LOAD is executed (!).  Thus, the value of
76dnl enable_cache if neither --enable-cache or --disable-cache is selected
77dnl is null.  Just in case autoconf ever fixes this, we test both cases.
78dnl
79dnl Include PATH in the cache.system file since changing the path can
80dnl change which versions of programs are found (such as vendor make
81dnl or GNU make).
82dnl
83#
84# Get a test value and flag whether we should remove/replace the
85# cache_system file (do so unless cache_system_ok is yes)
86# FC and F77 should be synonyms.  Save both in case
87# We include the xxxFLAGS in case the user is using the flags to change
88# the language (either input or output) of the compiler.  E.g.,
89# using -xarch=v9 on Solaris to select 64 bit output or using -D_BSD_SOURCE
90# with gcc to get different header files on input.
91cleanargs=`echo "$CC $F77 $FC $CXX $F90 $CFLAGS $FFLAGS $CXXFLAGS $F90FLAGS $PATH" | tr '"' ' '`
92if uname -srm >/dev/null 2>&1 ; then
93    cache_system_text="`uname -srm` $cleanargs"
94else
95    cache_system_text="-no-uname- $cleanargs"
96fi
97cache_system_ok=no
98#
99if test -z "$real_enable_cache" ; then
100    real_enable_cache=$enable_cache
101    if test -z "$real_enable_cache" ; then real_enable_cache="notgiven" ; fi
102fi
103if test "X$real_enable_cache" = "Xnotgiven" ; then
104    # check for valid cache file
105    if test -z "$cache_system" ; then cache_system="config.system" ; fi
106    if uname -srm >/dev/null 2>&1 ; then
107        if test -f "$cache_system" -a -n "$cache_system_text" ; then
108	    if test "$cache_system_text" = "`cat $cache_system`" ; then
109	        real_enable_cache="yes"
110                cache_system_ok=yes
111	    fi
112        elif test ! -f "$cache_system" -a -n "$cache_system_text" ; then
113	    # remove the cache file because it may not correspond to our
114	    # system
115	    if test "$cache_file" != "/dev/null" ; then
116	        rm -f $cache_file
117	    fi
118	    real_enable_cache="yes"
119        fi
120    fi
121fi
122if test "X$real_enable_cache" = "Xyes" -a "$cache_file" = "/dev/null" ; then
123    real_enable_cache=no
124fi
125if test "X$real_enable_cache" = "Xyes" ; then
126  if test -r "$cache_file" ; then
127    echo "loading cache $cache_file"
128    if test -w "$cache_file" ; then
129        # Clean the cache file (ergh)
130	PAC_CACHE_CLEAN
131    fi
132    . $cache_file
133  else
134    echo "Configure in `pwd` creating cache $cache_file"
135    > $cache_file
136    rm -f $cache_system
137  fi
138else
139  cache_file="/dev/null"
140fi
141# Remember our location and the name of the cachefile
142pac_cv_my_conf_dir=`pwd`
143dnl do not include the cachefile name, since this may contain the process
144dnl number and cause comparisons looking for changes to the cache file
145dnl to detect a change that isn't real.
146dnl pac_cv_my_cachefile=$cachefile
147#
148# Update the cache_system file if necessary
149if test "$cache_system_ok" != yes ; then
150    if test -n "$cache_system" ; then
151        rm -f $cache_system
152        echo $cache_system_text > $cache_system
153    fi
154fi
155if test "$clearMinusX" = yes ; then
156    set +x
157fi
158])
159dnl
160dnl/*D
161dnl PAC_ARG_CACHING - Enable caching of results from a configure execution
162dnl
163dnl Synopsis:
164dnl PAC_ARG_CACHING
165dnl
166dnl Output Effects:
167dnl Adds '--enable-cache' and '--disable-cache' to the command line arguments
168dnl accepted by 'configure'.
169dnl
170dnl See Also:
171dnl AC_CACHE_LOAD
172dnl D*/
173dnl Add this call to the other ARG_ENABLE calls.  Note that the values
174dnl set here are redundant; the LOAD_CACHE call relies on the way autoconf
175dnl initially processes ARG_ENABLE commands.
176AC_DEFUN([PAC_ARG_CACHING],[
177AC_ARG_ENABLE(cache,
178	AC_HELP_STRING([--enable-cache], [Turn on configure caching]),,
179	[enable_cache="notgiven"])
180])
181
182dnl Clean the cache of extraneous quotes that AC_CACHE_SAVE may add
183dnl
184AC_DEFUN([PAC_CACHE_CLEAN],[
185    rm -f confcache
186    sed -e "s/'\\\\''//g" -e "s/'\\\\/'/" -e "s/\\\\'/'/" \
187		-e "s/'\\\\''//g" $cache_file > confcache
188    if cmp -s $cache_file confcache ; then
189        :
190    else
191        if test -w $cache_file ; then
192	    echo "updating cache $cache_file"
193            cat confcache > $cache_file
194        else
195            echo "not updating unwritable cache $cache_file"
196        fi
197    fi
198    rm -f confcache
199    if test "$DEBUG_AUTOCONF_CACHE" = "yes" ; then
200        echo "Results of cleaned cache file:"
201	echo "--------------------------------------------------------"
202	cat $cache_file
203	echo "--------------------------------------------------------"
204    fi
205])
206
207dnl/*D
208dnl PAC_SUBDIR_CACHE - Create a cache file before ac_output for subdirectory
209dnl configures.
210dnl
211dnl Synopsis:
212dnl PAC_SUBDIR_CACHE(when)
213dnl
214dnl Input Parameter:
215dnl . when - Indicates when the cache should be created (optional)
216dnl          If 'always', create a new cache file.  This option
217dnl          should be used if any of the cache parameters (such as
218dnl          CFLAGS or LDFLAGS) may have changed.
219dnl
220dnl Output Effects:
221dnl
222dnl Create a cache file before ac_output so that subdir configures don't
223dnl make mistakes.
224dnl We can't use OUTPUT_COMMANDS to remove the cache file, because those
225dnl commands are executed *before* the subdir configures.
226dnl
227dnl D*/
228AC_DEFUN([PAC_SUBDIR_CACHE],[])
229AC_DEFUN([PAC_SUBDIR_CACHE_OLD],[
230if test "x$1" = "xalways" -o \( "$cache_file" = "/dev/null" -a "X$real_enable_cache" = "Xnotgiven" \) ; then
231    # Use an absolute directory to help keep the subdir configures from getting
232    # lost
233    cache_file=`pwd`/$$conf.cache
234    touch $cache_file
235    dnl
236    dnl For Autoconf 2.52+, we should ensure that the environment is set
237    dnl for the cache.  Make sure that we get the values and set the
238    dnl xxx_set variables properly
239    ac_cv_env_CC_set=set
240    ac_cv_env_CC_value=$CC
241    ac_cv_env_CFLAGS_set=${CFLAGS+set}
242    ac_cv_env_CFLAGS_value=$CFLAGS
243    ac_cv_env_CPP_set=set
244    ac_cv_env_CPP_value=$CPP
245    ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
246    ac_cv_env_CPPFLAGS_value=$CPPFLAGS
247    ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
248    ac_cv_env_LDFLAGS_value=$LDFLAGS
249    ac_cv_env_LIBS_set=${LIBS+set}
250    ac_cv_env_LIBS_value=$LIBS
251    ac_cv_env_FC_set=${FC+set}
252    ac_cv_env_FC_value=$FC
253    ac_cv_env_F77_set=${F77+set}
254    ac_cv_env_F77_value=$F77
255    ac_cv_env_F90_set=${F90+set}
256    ac_cv_env_F90_value=$F90
257    ac_cv_env_FFLAGS_set=${FFLAGS+set}
258    ac_cv_env_FFLAGS_value=$FFLAGS
259    ac_cv_env_CXX_set=${CXX+set}
260    ac_cv_env_CXX_value=$CXX
261
262    ac_env_CC_set=set
263    ac_env_CC_value=$CC
264    ac_env_CFLAGS_set=${CFLAGS+set}
265    ac_env_CFLAGS_value=$CFLAGS
266    ac_env_CPP_set=set
267    ac_env_CPP_value=$CPP
268    ac_env_CPPFLAGS_set=${CPPFLAGS+set}
269    ac_env_CPPFLAGS_value=$CPPFLAGS
270    ac_env_LDFLAGS_set=${LDFLAGS+set}
271    ac_env_LDFLAGS_value=$LDFLAGS
272    ac_env_LIBS_set=${LIBS+set}
273    ac_env_LIBS_value=$LIBS
274    ac_env_FC_set=${FC+set}
275    ac_env_FC_value=$FC
276    ac_env_F77_set=${F77+set}
277    ac_env_F77_value=$F77
278    ac_env_F90_set=${F90+set}
279    ac_env_F90_value=$F90
280    ac_env_FFLAGS_set=${FFLAGS+set}
281    ac_env_FFLAGS_value=$FFLAGS
282    ac_env_CXX_set=${CXX+set}
283    ac_env_CXX_value=$CXX
284
285    dnl other parameters are
286    dnl build_alias, host_alias, target_alias
287
288    # It turns out that A C CACHE_SAVE can't be invoked more than once
289    # with data that contains blanks.  What happens is that the quotes
290    # that it adds get quoted and then added again.  To avoid this,
291    # we strip off the outer quotes for all cached variables
292    dnl We add pac_cv_my_conf_dir to give the source of this cachefile,
293    dnl and pac_cv_my_cachefile to indicate how it chose the cachefile.
294    pac_cv_my_conf_dir=`pwd`
295    pac_cv_my_cachefile=$cachefile
296    AC_CACHE_SAVE
297    PAC_CACHE_CLEAN
298    ac_configure_args="$ac_configure_args -enable-cache"
299fi
300dnl Unconditionally export these values.  Subdir configures break otherwise
301export CC
302export CFLAGS
303export LDFLAGS
304export LIBS
305export CPPFLAGS
306export CPP
307export FC
308export F77
309export F90
310export CXX
311export FFLAGS
312export CCFLAGS
313])
314AC_DEFUN([PAC_SUBDIR_CACHE_CLEANUP],[])
315AC_DEFUN([PAC_SUBDIR_CACHE_CLEANUP_OLD],[
316if test "$cache_file" != "/dev/null" -a "X$real_enable_cache" = "Xnotgiven" ; then
317   rm -f $cache_file
318   cache_file=/dev/null
319fi
320])
321dnl
322dnl The following three macros support the sharing of configure results
323dnl by configure scripts, including ones that are not run with
324dnl AC_CONFIG_SUBDIRS (the cachefiles managed by --enable-cache can
325dnl only be used with AC_CONFIG_SUBDIRS; creating a autoconf-style
326dnl cachefile before the the end of the autoconf process will often
327dnl cause problems.
328dnl
329AC_DEFUN([PAC_CREATE_BASE_CACHE],[
330AC_ARG_ENABLE(base-cache,
331	AC_HELP_STRING([--enable-base-cache],
332		[Enable the use of a simple cache for the subsidiary
333                 configure scripts]),,enable_base_cache=default)
334# The default case is controlled by the environment variable CONF_USE_CACHEFILE
335if test "$enable_base_cache" = "default" ; then
336    if test "$CONF_USE_CACHEFILE" = yes ; then
337        enable_base_cache=yes
338    else
339        enable_base_cache=no
340    fi
341fi
342if test "$enable_base_cache" != no ; then
343    if test "$enable_base_cache" = yes ; then
344        basecachefile=`pwd`/cache.base
345    else
346        basecachefile=`pwd`/$enable_base_cache
347    fi
348    set | grep ac_cv > $basecachefile
349    # Tell other configures to load this file
350    echo "Creating and exporting the base cache file $basecachefile"
351    CONF_BASE_CACHEFILE=$basecachefile
352    export CONF_BASE_CACHEFILE
353fi
354])
355AC_DEFUN([PAC_LOAD_BASE_CACHE],[
356if test -n "$CONF_BASE_CACHEFILE" -a -s "$CONF_BASE_CACHEFILE" ; then
357    echo "Loading base cachefile $CONF_BASE_CACHEFILE"
358    . $CONF_BASE_CACHEFILE
359    export CONF_BASE_CACHEFILE
360fi
361])
362AC_DEFUN([PAC_UPDATE_BASE_CACHE],[
363if test -n "$CONF_BASE_CACHEFILE" -a -s "$CONF_BASE_CACHEFILE" ; then
364    set | grep ac_cv > $CONF_BASE_CACHEFILE.new
365    if cmp -s $CONF_BASE_CACHEFILE.new $CONF_BASE_CACHEFILE ; then
366	:
367    else
368	echo "Replacing $CONF_BASE_CACHEFILE"
369	mv $CONF_BASE_CACHEFILE.new $CONF_BASE_CACHEFILE
370    fi
371fi
372])
373