autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I don't understand test caching


From: Alexandre Duret-Lutz
Subject: Re: I don't understand test caching
Date: 22 May 2001 09:10:11 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

| Caching sort of works: I can see the proper value set in config.cache,
| and on the first clean run the appropriate #define gets set in
| config.h.  On subsequent runs, the config.h value remains commented
| out.  Here's one of my macros, to check for SysV IPC headers:
| 
| AC_DEFUN([ETR_SYSV_IPC],
| [ AC_CACHE_CHECK([for System V IPC headers], ac_cv_sysv_ipc, [
| 
|     AC_TRY_COMPILE(
|         [
|             #include <sys/types.h>
|             #include <sys/ipc.h>
|             #include <sys/msg.h>
|             #include <sys/sem.h>
|             #include <sys/shm.h>
|         ],, ac_cv_sysv_ipc=yes, ac_cv_sysv_ipc=no)
|     if test x"$ac_cv_sysv_ipc" = "xyes"
|     then
|         AC_DEFINE(HAVE_SYSV_IPC, 1, [ Define if you have System V IPC])
|     fi
| ])]) dnl ETR_SYSV_IPC

Don't use AC_DEFINE in AC_CACHE_CHECK or it will never be run
when the cache is used.  Instead move that `if test ... fi'
after AC_CACHE_CHECK.  For reference, the manual (section
Caching Results) reads as follow:

|    It is very common to find buggy macros using `AC_CACHE_VAL'
| or `AC_CACHE_CHECK', because people are tempted to call
| `AC_DEFINE' in the COMMANDS-TO-SET-IT. Instead, the code that
| _follows_ the call to `AC_CACHE_VAL' should call `AC_DEFINE', by
| examining the value of the cache variable.  For instance, the
| following macro is broken:
| 
|      AC_DEFUN([AC_SHELL_TRUE],
|      [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
|                      [ac_cv_shell_true_works=no
|                       true && ac_cv_shell_true_works=yes
|                       if test $ac_cv_shell_true_works = yes; then
|                         AC_DEFINE([TRUE_WORKS], 1
|                                   [Define if `true(1)' works properly.])
|                       fi])
|      ])
| 
| This fails if the cache is enabled: the second time this macro
| is run, `TRUE_WORKS' _will not be defined_.  The proper
| implementation is:
| 
|      AC_DEFUN([AC_SHELL_TRUE],
|      [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
|                      [ac_cv_shell_true_works=no
|                       true && ac_cv_shell_true_works=yes])
|       if test $ac_cv_shell_true_works = yes; then
|         AC_DEFINE([TRUE_WORKS], 1
|                   [Define if `true(1)' works properly.])
|       fi
|      ])
   
-- 
Alexandre Duret-Lutz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]