root/mpich2/branches/dev/kumudb/confdb/aclocal_cache.m4 @ 4870

Revision 4870, 12.7 KB (checked in by kumudb, 5 months ago)

Merge from trunk to kumudb r4748:r4869

Line 
1dnl
2dnl/*D
3dnl AC_CACHE_LOAD - Replacement for autoconf cache load
4dnl
5dnl Notes:
6dnl Caching in autoconf is broken (through version 2.13).  The problem is
7dnl 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[--enable-cache  - Turn on configure caching],
179enable_cache="$enableval",enable_cache="notgiven")
180])
181dnl
182
183dnl Clean the cache of extraneous quotes that AC_CACHE_SAVE may add
184dnl
185AC_DEFUN([PAC_CACHE_CLEAN],[
186    rm -f confcache
187    sed -e "s/'\\\\''//g" -e "s/'\\\\/'/" -e "s/\\\\'/'/" \
188                -e "s/'\\\\''//g" $cache_file > confcache
189    if cmp -s $cache_file confcache ; then
190        :
191    else
192        if test -w $cache_file ; then
193            echo "updating cache $cache_file"
194            cat confcache > $cache_file
195        else
196            echo "not updating unwritable cache $cache_file"
197        fi
198    fi 
199    rm -f confcache
200    if test "$DEBUG_AUTOCONF_CACHE" = "yes" ; then
201        echo "Results of cleaned cache file:"
202        echo "--------------------------------------------------------"
203        cat $cache_file
204        echo "--------------------------------------------------------"
205    fi
206])
207
208dnl/*D
209dnl PAC_SUBDIR_CACHE - Create a cache file before ac_output for subdirectory
210dnl configures.
211dnl
212dnl Synopsis:
213dnl PAC_SUBDIR_CACHE(when)
214dnl
215dnl Input Parameter:
216dnl . when - Indicates when the cache should be created (optional)
217dnl          If 'always', create a new cache file.  This option
218dnl          should be used if any of the cache parameters (such as
219dnl          CFLAGS or LDFLAGS) may have changed.
220dnl
221dnl Output Effects:
222dnl     
223dnl Create a cache file before ac_output so that subdir configures don't
224dnl make mistakes.
225dnl We can't use OUTPUT_COMMANDS to remove the cache file, because those
226dnl commands are executed *before* the subdir configures.
227dnl
228dnl D*/
229AC_DEFUN([PAC_SUBDIR_CACHE],[])
230AC_DEFUN([PAC_SUBDIR_CACHE_OLD],[
231if test "x$1" = "xalways" -o \( "$cache_file" = "/dev/null" -a "X$real_enable_cache" = "Xnotgiven" \) ; then
232    # Use an absolute directory to help keep the subdir configures from getting
233    # lost
234    cache_file=`pwd`/$$conf.cache
235    touch $cache_file
236    dnl
237    dnl For Autoconf 2.52+, we should ensure that the environment is set
238    dnl for the cache.  Make sure that we get the values and set the
239    dnl xxx_set variables properly
240    ac_cv_env_CC_set=set
241    ac_cv_env_CC_value=$CC
242    ac_cv_env_CFLAGS_set=${CFLAGS+set}
243    ac_cv_env_CFLAGS_value=$CFLAGS
244    ac_cv_env_CPP_set=set
245    ac_cv_env_CPP_value=$CPP
246    ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
247    ac_cv_env_CPPFLAGS_value=$CPPFLAGS
248    ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
249    ac_cv_env_LDFLAGS_value=$LDFLAGS
250    ac_cv_env_LIBS_set=${LIBS+set}
251    ac_cv_env_LIBS_value=$LIBS
252    ac_cv_env_FC_set=${FS+set}
253    ac_cv_env_FC_value=$FC
254    ac_cv_env_F77_set=${F77+set}
255    ac_cv_env_F77_value=$F77
256    ac_cv_env_F90_set=${F90+set}
257    ac_cv_env_F90_value=$F90
258    ac_cv_env_FFLAGS_set=${FFLAGS+set}
259    ac_cv_env_FFLAGS_value=$FFLAGS
260    ac_cv_env_CXX_set=${CXX+set}
261    ac_cv_env_CXX_value=$CXX
262
263    ac_env_CC_set=set
264    ac_env_CC_value=$CC
265    ac_env_CFLAGS_set=${CFLAGS+set}
266    ac_env_CFLAGS_value=$CFLAGS
267    ac_env_CPP_set=set
268    ac_env_CPP_value=$CPP
269    ac_env_CPPFLAGS_set=${CPPFLAGS+set}
270    ac_env_CPPFLAGS_value=$CPPFLAGS
271    ac_env_LDFLAGS_set=${LDFLAGS+set}
272    ac_env_LDFLAGS_value=$LDFLAGS
273    ac_env_LIBS_set=${LIBS+set}
274    ac_env_LIBS_value=$LIBS
275    ac_env_FC_set=${FS+set}
276    ac_env_FC_value=$FC
277    ac_env_F77_set=${F77+set}
278    ac_env_F77_value=$F77
279    ac_env_F90_set=${F90+set}
280    ac_env_F90_value=$F90
281    ac_env_FFLAGS_set=${FFLAGS+set}
282    ac_env_FFLAGS_value=$FFLAGS
283    ac_env_CXX_set=${CXX+set}
284    ac_env_CXX_value=$CXX
285
286    dnl other parameters are
287    dnl build_alias, host_alias, target_alias
288
289    # It turns out that A C CACHE_SAVE can't be invoked more than once
290    # with data that contains blanks.  What happens is that the quotes
291    # that it adds get quoted and then added again.  To avoid this,
292    # we strip off the outer quotes for all cached variables
293    dnl We add pac_cv_my_conf_dir to give the source of this cachefile,
294    dnl and pac_cv_my_cachefile to indicate how it chose the cachefile.
295    pac_cv_my_conf_dir=`pwd`
296    pac_cv_my_cachefile=$cachefile
297    AC_CACHE_SAVE
298    PAC_CACHE_CLEAN
299    ac_configure_args="$ac_configure_args -enable-cache"
300fi
301dnl Unconditionally export these values.  Subdir configures break otherwise
302export CC
303export CFLAGS
304export LDFLAGS
305export LIBS
306export CPPFLAGS
307export CPP
308export FC
309export F77
310export F90
311export CXX
312export FFLAGS
313export CCFLAGS
314])
315AC_DEFUN([PAC_SUBDIR_CACHE_CLEANUP],[])
316AC_DEFUN([PAC_SUBDIR_CACHE_CLEANUP_OLD],[
317if test "$cache_file" != "/dev/null" -a "X$real_enable_cache" = "Xnotgiven" ; then
318   rm -f $cache_file
319   cache_file=/dev/null
320fi
321])
322dnl
323dnl The following three macros support the sharing of configure results
324dnl by configure scripts, including ones that are not run with
325dnl AC_CONFIG_SUBDIRS (the cachefiles managed by --enable-cache can
326dnl only be used with AC_CONFIG_SUBDIRS; creating a autoconf-style
327dnl cachefile before the the end of the autoconf process will often
328dnl cause problems.
329dnl
330AC_DEFUN([PAC_CREATE_BASE_CACHE],[
331AC_ARG_ENABLE(base-cache,
332[--enable-base-cache - Enable the use of a simple cache for the subsidieary
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])
Note: See TracBrowser for help on using the browser.