]> git.donarmstrong.com Git - lilypond.git/blob - guile18/acinclude.m4
New upstream version 2.19.65
[lilypond.git] / guile18 / acinclude.m4
1 dnl  On the NeXT, #including <utime.h> doesn't give you a definition for
2 dnl  struct utime, unless you #define _POSIX_SOURCE.
3
4 AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
5   AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
6     guile_cv_struct_utimbuf_needs_posix,
7     [AC_TRY_CPP([
8 #ifdef __EMX__
9 #include <sys/utime.h>
10 #else
11 #include <utime.h>
12 #endif
13 struct utime blah;
14 ],
15                 guile_cv_struct_utimbuf_needs_posix=no,
16                 guile_cv_struct_utimbuf_needs_posix=yes)])
17   if test "$guile_cv_struct_utimbuf_needs_posix" = yes; then
18      AC_DEFINE([UTIMBUF_NEEDS_POSIX], 1,
19        [Define this if <utime.h> doesn't define struct utimbuf unless
20         _POSIX_SOURCE is defined.  See GUILE_STRUCT_UTIMBUF in aclocal.m4.])
21   fi])
22
23
24
25
26 dnl
27 dnl Apparently, at CMU they have a weird version of libc.h that is
28 dnl installed in /usr/local/include and conflicts with unistd.h.
29 dnl In these situations, we should not #include libc.h.
30 dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
31 dnl present on the system, and is safe to #include.
32 dnl
33 AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
34   [
35     AC_CHECK_HEADERS(libc.h unistd.h)
36     AC_CACHE_CHECK(
37       [whether libc.h and unistd.h can be included together],
38       guile_cv_header_libc_with_unistd,
39       [
40         if test "$ac_cv_header_libc_h" = "no"; then
41           guile_cv_header_libc_with_unistd="no"
42         elif test "$ac_cv_header_unistd_h" = "no"; then
43           guile_cv_header_libc_with_unistd="yes"
44         else
45           AC_TRY_COMPILE(
46             [
47 #             include <libc.h>
48 #             include <unistd.h>
49             ],
50             [],
51             [guile_cv_header_libc_with_unistd=yes],
52             [guile_cv_header_libc_with_unistd=no]
53           )
54         fi
55       ]
56     )
57     if test "$guile_cv_header_libc_with_unistd" = yes; then
58       AC_DEFINE(LIBC_H_WITH_UNISTD_H, 1,
59         [Define this if we should include <libc.h> when we've already
60          included <unistd.h>.  On some systems, they conflict, and libc.h
61          should be omitted.  See GUILE_HEADER_LIBC_WITH_UNISTD in
62          aclocal.m4.])
63     fi
64   ]
65 )
66
67
68
69 dnl This is needed when we want to check for the same function repeatedly
70 dnl with other parameters, such as libraries, varying.
71 dnl
72 dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
73 dnl                        [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
74 AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
75 [AC_MSG_CHECKING([for $1])
76 AC_CACHE_VAL(ac_cv_func_$1_$2,
77 [AC_TRY_LINK(
78 dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
79 dnl which includes <sys/select.h> which contains a prototype for
80 dnl select.  Similarly for bzero.
81 [/* System header to define __stub macros and hopefully few prototypes,
82     which can conflict with char $1(); below.  */
83 #include <assert.h>
84 /* Override any gcc2 internal prototype to avoid an error.  */
85 #ifdef __cplusplus
86 extern "C"
87 #endif
88 /* We use char because int might match the return type of a gcc2
89     builtin and then its argument prototype would still apply.  */
90 char $1();
91 ], [
92 /* The GNU C library defines this for functions which it implements
93     to always fail with ENOSYS.  Some functions are actually named
94     something starting with __ and the normal name is an alias.  */
95 #if defined (__stub_$1) || defined (__stub___$1)
96 choke me
97 #else
98 $1();
99 #endif
100 ], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
101 if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
102   AC_MSG_RESULT(yes)
103   ifelse([$3], , :, [$3])
104 else
105   AC_MSG_RESULT(no)
106 ifelse([$4], , , [$4
107 ])dnl
108 fi
109 ])
110
111
112
113
114 dnl Available from the Autoconf Macro Archive at:
115 dnl http://autoconf-archive.cryp.to/acx_pthread.html
116 dnl
117 AC_DEFUN([ACX_PTHREAD], [
118 AC_REQUIRE([AC_CANONICAL_HOST])
119 AC_LANG_SAVE
120 AC_LANG_C
121 acx_pthread_ok=no
122
123 # We used to check for pthread.h first, but this fails if pthread.h
124 # requires special compiler flags (e.g. on True64 or Sequent).
125 # It gets checked for in the link test anyway.
126
127 # First of all, check if the user has set any of the PTHREAD_LIBS,
128 # etcetera environment variables, and if threads linking works using
129 # them:
130 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
131         save_CFLAGS="$CFLAGS"
132         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
133         save_LIBS="$LIBS"
134         LIBS="$PTHREAD_LIBS $LIBS"
135         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
136         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
137         AC_MSG_RESULT($acx_pthread_ok)
138         if test x"$acx_pthread_ok" = xno; then
139                 PTHREAD_LIBS=""
140                 PTHREAD_CFLAGS=""
141         fi
142         LIBS="$save_LIBS"
143         CFLAGS="$save_CFLAGS"
144 fi
145
146 # We must check for the threads library under a number of different
147 # names; the ordering is very important because some systems
148 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
149 # libraries is broken (non-POSIX).
150
151 # Create a list of thread flags to try.  Items starting with a "-" are
152 # C compiler flags, and other items are library names, except for "none"
153 # which indicates that we try without any flags at all, and "pthread-config"
154 # which is a program returning the flags for the Pth emulation library.
155
156 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
157
158 # The ordering *is* (sometimes) important.  Some notes on the
159 # individual items follow:
160
161 # pthreads: AIX (must check this before -lpthread)
162 # none: in case threads are in libc; should be tried before -Kthread and
163 #       other compiler flags to prevent continual compiler warnings
164 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
165 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
166 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
167 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
168 # -pthreads: Solaris/gcc
169 # -mthreads: Mingw32/gcc, Lynx/gcc
170 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
171 #      doesn't hurt to check since this sometimes defines pthreads too;
172 #      also defines -D_REENTRANT)
173 #      ... -mt is also the pthreads flag for HP/aCC
174 # pthread: Linux, etcetera
175 # --thread-safe: KAI C++
176 # pthread-config: use pthread-config program (for GNU Pth library)
177
178 case "${host_cpu}-${host_os}" in
179         *solaris*)
180
181         # On Solaris (at least, for some versions), libc contains stubbed
182         # (non-functional) versions of the pthreads routines, so link-based
183         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
184         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
185         # a function called by this macro, so we could check for that, but
186         # who knows whether they'll stub that too in a future libc.)  So,
187         # we'll just look for -pthreads and -lpthread first:
188
189         acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
190         ;;
191 esac
192
193 if test x"$acx_pthread_ok" = xno; then
194 for flag in $acx_pthread_flags; do
195
196         case $flag in
197                 none)
198                 AC_MSG_CHECKING([whether pthreads work without any flags])
199                 ;;
200
201                 -*)
202                 AC_MSG_CHECKING([whether pthreads work with $flag])
203                 PTHREAD_CFLAGS="$flag"
204                 ;;
205
206                 pthread-config)
207                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
208                 if test x"$acx_pthread_config" = xno; then continue; fi
209                 PTHREAD_CFLAGS="`pthread-config --cflags`"
210                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
211                 ;;
212
213                 *)
214                 AC_MSG_CHECKING([for the pthreads library -l$flag])
215                 PTHREAD_LIBS="-l$flag"
216                 ;;
217         esac
218
219         save_LIBS="$LIBS"
220         save_CFLAGS="$CFLAGS"
221         LIBS="$PTHREAD_LIBS $LIBS"
222         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
223
224         # Check for various functions.  We must include pthread.h,
225         # since some functions may be macros.  (On the Sequent, we
226         # need a special flag -Kthread to make this header compile.)
227         # We check for pthread_join because it is in -lpthread on IRIX
228         # while pthread_create is in libc.  We check for pthread_attr_init
229         # due to DEC craziness with -lpthreads.  We check for
230         # pthread_cleanup_push because it is one of the few pthread
231         # functions on Solaris that doesn't have a non-functional libc stub.
232         # We try pthread_create on general principles.
233         AC_TRY_LINK([#include <pthread.h>],
234                     [pthread_t th; pthread_join(th, 0);
235                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
236                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
237                     [acx_pthread_ok=yes])
238
239         LIBS="$save_LIBS"
240         CFLAGS="$save_CFLAGS"
241
242         AC_MSG_RESULT($acx_pthread_ok)
243         if test "x$acx_pthread_ok" = xyes; then
244                 break;
245         fi
246
247         PTHREAD_LIBS=""
248         PTHREAD_CFLAGS=""
249 done
250 fi
251
252 # Various other checks:
253 if test "x$acx_pthread_ok" = xyes; then
254         save_LIBS="$LIBS"
255         LIBS="$PTHREAD_LIBS $LIBS"
256         save_CFLAGS="$CFLAGS"
257         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
258
259         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
260         AC_MSG_CHECKING([for joinable pthread attribute])
261         attr_name=unknown
262         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
263             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
264                         [attr_name=$attr; break])
265         done
266         AC_MSG_RESULT($attr_name)
267         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
268             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
269                                [Define to necessary symbol if this constant
270                                 uses a non-standard name on your system.])
271         fi
272
273         AC_MSG_CHECKING([if more special flags are required for pthreads])
274         flag=no
275         case "${host_cpu}-${host_os}" in
276             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
277             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
278         esac
279         AC_MSG_RESULT(${flag})
280         if test "x$flag" != xno; then
281             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
282         fi
283
284         LIBS="$save_LIBS"
285         CFLAGS="$save_CFLAGS"
286
287         # More AIX lossage: must compile with xlc_r or cc_r
288         if test x"$GCC" != xyes; then
289           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
290         else
291           PTHREAD_CC=$CC
292         fi
293 else
294         PTHREAD_CC="$CC"
295 fi
296
297 AC_SUBST(PTHREAD_LIBS)
298 AC_SUBST(PTHREAD_CFLAGS)
299 AC_SUBST(PTHREAD_CC)
300
301 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
302 if test x"$acx_pthread_ok" = xyes; then
303         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
304         :
305 else
306         acx_pthread_ok=no
307         $2
308 fi
309 AC_LANG_RESTORE
310 ])dnl ACX_PTHREAD