Greetings,
   I've been migrating an existing project to autoconf and automake, and 
I've encountered an interesting problem.  I've consulted the fine 
manual, mailing list archives and Google, but no satisfactory solution 
has emerged.  I wonder if anyone here has a solution to this puzzle.
   The program I'm constructing can be compiled to use either POSIX 
threads or System V IPC.  I want configure to select one of these based 
on which header files are available.  That's quite easy, but if threads 
are in use I need to link with libpthread and define _REENTRANT.
   Unfortunately AC_CHECK_HEADER and AC_CHECK_HEADERS don't define 
HAVE_<HEADER>_H as shell variables, so that leaves me with a 
configure.in with this:

     use_pthreads=no
     AC_CHECK_HEADER(pthread.h, use_pthreads=yes)
     AM_CONDITIONAL(ENABLE_PTHREADS, test "$use_pthreads" = "yes")
     if test "$use_pthread" = "yes"; then
       AC_DEFINE(HAVE_PTHREAD_H)
     else
       AC_CHECK_HEADER(sys/ipc.h, AC_DEFINE(HAVE_SYS_IPC_H))
     fi

   This is clearly unmaintainable.  For example, if I wanted to add 
Windows threads under Cygwin it would get even more ugly.  What I want 
is something like this:

     use_multi=unknown
     AC_CHECK_HEADERS(pthread.h sys/ipc.h, use_multi=$ac_safe; break)
     AM_CONDITIONAL(ENABLE_PTHREADS, test "$use_multi" = "pthread_h")

   This also works, but obviously $ac_safe is an implementation detail 
subject to change without notice.  I don't want make this a user 
selected feature or check for the same header twice.  Can anyone tell me 
what the right way to do this might be?  (Please copy on any replies as 
I'm not subscribed.)
                                              Thanks
                                                  Jeff


Reply via email to