]> git.saurik.com Git - wxWidgets.git/blame - src/tiff/m4/acinclude.m4
xti changes
[wxWidgets.git] / src / tiff / m4 / acinclude.m4
CommitLineData
8414a40c
VZ
1dnl ---------------------------------------------------------------------------
2dnl Message output
3dnl ---------------------------------------------------------------------------
4AC_DEFUN([LOC_MSG],[echo "$1"])
5
6dnl ---------------------------------------------------------------------------
7dnl Available from the GNU Autoconf Macro Archive at:
8dnl http://www.gnu.org/software/ac-archive/vl_prog_cc_warnings.html
9dnl ---------------------------------------------------------------------------
10
11dnl @synopsis VL_PROG_CC_WARNINGS([ANSI])
12dnl
13dnl Enables a reasonable set of warnings for the C compiler.
14dnl Optionally, if the first argument is nonempty, turns on flags which
15dnl enforce and/or enable proper ANSI C if such are known with the
16dnl compiler used.
17dnl
18dnl Currently this macro knows about GCC, Solaris C compiler, Digital
19dnl Unix C compiler, C for AIX Compiler, HP-UX C compiler, IRIX C
20dnl compiler, NEC SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos
21dnl 10.0.0.8) C compiler.
22dnl
23dnl @category C
24dnl @author Ville Laurikari <vl@iki.fi>
25dnl @version 2002-04-04
26dnl @license AllPermissive
27
28AC_DEFUN([VL_PROG_CC_WARNINGS], [
29 ansi=$1
30 if test -z "$ansi"; then
31 msg="for C compiler warning flags"
32 else
33 msg="for C compiler warning and ANSI conformance flags"
34 fi
35 AC_CACHE_CHECK($msg, vl_cv_prog_cc_warnings, [
36 if test -n "$CC"; then
37 cat > conftest.c <<EOF
38int main(int argc, char **argv) { return 0; }
39EOF
40
41 dnl GCC. -W option has been renamed in -wextra in latest gcc versions.
42 if test "$GCC" = "yes"; then
43 if test -z "$ansi"; then
44 vl_cv_prog_cc_warnings="-Wall -W"
45 else
46 vl_cv_prog_cc_warnings="-Wall -W -ansi -pedantic"
47 fi
48
49 dnl Most compilers print some kind of a version string with some command
50 dnl line options (often "-V"). The version string should be checked
51 dnl before doing a test compilation run with compiler-specific flags.
52 dnl This is because some compilers (like the Cray compiler) only
53 dnl produce a warning message for unknown flags instead of returning
54 dnl an error, resulting in a false positive. Also, compilers may do
55 dnl erratic things when invoked with flags meant for a different
56 dnl compiler.
57
58 dnl Solaris C compiler
59 elif $CC -V 2>&1 | grep -i "WorkShop" > /dev/null 2>&1 &&
60 $CC -c -v -Xc conftest.c > /dev/null 2>&1 &&
61 test -f conftest.o; then
62 if test -z "$ansi"; then
63 vl_cv_prog_cc_warnings="-v"
64 else
65 vl_cv_prog_cc_warnings="-v -Xc"
66 fi
67
68 dnl Digital Unix C compiler
69 elif $CC -V 2>&1 | grep -i "Digital UNIX Compiler" > /dev/null 2>&1 &&
70 $CC -c -verbose -w0 -warnprotos -std1 conftest.c > /dev/null 2>&1 &&
71 test -f conftest.o; then
72 if test -z "$ansi"; then
73 vl_cv_prog_cc_warnings="-verbose -w0 -warnprotos"
74 else
75 vl_cv_prog_cc_warnings="-verbose -w0 -warnprotos -std1"
76 fi
77
78 dnl C for AIX Compiler
79 elif $CC 2>&1 | grep -i "C for AIX Compiler" > /dev/null 2>&1 &&
80 $CC -c -qlanglvl=ansi -qinfo=all conftest.c > /dev/null 2>&1 &&
81 test -f conftest.o; then
82 if test -z "$ansi"; then
83 vl_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd"
84 else
85 vl_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd -qlanglvl=ansi"
86 fi
87
88 dnl IRIX C compiler
89 elif $CC -version 2>&1 | grep -i "MIPSpro Compilers" > /dev/null 2>&1 &&
90 $CC -c -fullwarn -ansi -ansiE conftest.c > /dev/null 2>&1 &&
91 test -f conftest.o; then
92 if test -z "$ansi"; then
93 vl_cv_prog_cc_warnings="-fullwarn"
94 else
95 vl_cv_prog_cc_warnings="-fullwarn -ansi -ansiE"
96 fi
97
98 dnl HP-UX C compiler
99 elif what $CC 2>&1 | grep -i "HP C Compiler" > /dev/null 2>&1 &&
100 $CC -c -Aa +w1 conftest.c > /dev/null 2>&1 &&
101 test -f conftest.o; then
102 if test -z "$ansi"; then
103 vl_cv_prog_cc_warnings="+w1"
104 else
105 vl_cv_prog_cc_warnings="+w1 -Aa"
106 fi
107
108 dnl The NEC SX-5 (Super-UX 10) C compiler
109 elif $CC -V 2>&1 | grep "/SX" > /dev/null 2>&1 &&
110 $CC -c -pvctl[,]fullmsg -Xc conftest.c > /dev/null 2>&1 &&
111 test -f conftest.o; then
112 if test -z "$ansi"; then
113 vl_cv_prog_cc_warnings="-pvctl[,]fullmsg"
114 else
115 vl_cv_prog_cc_warnings="-pvctl[,]fullmsg -Xc"
116 fi
117
118 dnl The Cray C compiler (Unicos)
119 elif $CC -V 2>&1 | grep -i "Cray" > /dev/null 2>&1 &&
120 $CC -c -h msglevel 2 conftest.c > /dev/null 2>&1 &&
121 test -f conftest.o; then
122 if test -z "$ansi"; then
123 vl_cv_prog_cc_warnings="-h msglevel 2"
124 else
125 vl_cv_prog_cc_warnings="-h msglevel 2 -h conform"
126 fi
127
128 fi
129 rm -f conftest.*
130 fi
131 if test -n "$vl_cv_prog_cc_warnings"; then
132 CFLAGS="$CFLAGS $vl_cv_prog_cc_warnings"
133 else
134 vl_cv_prog_cc_warnings="unknown"
135 fi
136 ])
137])dnl
138
139dnl ---------------------------------------------------------------------------
140dnl Available from the GNU Autoconf Macro Archive at:
141dnl http://autoconf-archive.cryp.to/ax_lang_compiler_ms.html
142dnl ---------------------------------------------------------------------------
143
144dnl @synopsis AX_LANG_COMPILER_MS
145dnl
146dnl Check whether the compiler for the current language is Microsoft.
147dnl
148dnl This macro is modeled after _AC_LANG_COMPILER_GNU in the GNU
149dnl Autoconf implementation.
150dnl
151dnl @category InstalledPackages
152dnl @author Braden McDaniel <braden@endoframe.com>
153dnl @version 2004-11-15
154dnl @license AllPermissive
155
156AC_DEFUN([AX_LANG_COMPILER_MS],
157[AC_CACHE_CHECK([whether we are using the Microsoft _AC_LANG compiler],
158 [ax_cv_[]_AC_LANG_ABBREV[]_compiler_ms],
159[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef _MSC_VER
160 choke me
161#endif
162]])],
163 [ax_compiler_ms=yes],
164 [ax_compiler_ms=no])
165ax_cv_[]_AC_LANG_ABBREV[]_compiler_ms=$ax_compiler_ms
166])])
167
168dnl ---------------------------------------------------------------------------
169dnl Available from the GNU Autoconf Macro Archive at:
170dnl http://www.gnu.org/software/ac-archive/ax_check_gl.html
171dnl ---------------------------------------------------------------------------
172
173dnl @synopsis AX_CHECK_GL
174dnl
175dnl Check for an OpenGL implementation. If GL is found, the required
176dnl compiler and linker flags are included in the output variables
177dnl "GL_CFLAGS" and "GL_LIBS", respectively. This macro adds the
178dnl configure option "--with-apple-opengl-framework", which users can
179dnl use to indicate that Apple's OpenGL framework should be used on Mac
180dnl OS X. If Apple's OpenGL framework is used, the symbol
181dnl "HAVE_APPLE_OPENGL_FRAMEWORK" is defined. If no GL implementation
182dnl is found, "no_gl" is set to "yes".
183dnl
184dnl @category InstalledPackages
185dnl @author Braden McDaniel <braden@endoframe.com>
186dnl @version 2004-11-15
187dnl @license AllPermissive
188
189AC_DEFUN([AX_CHECK_GL],
190[AC_REQUIRE([AC_PATH_X])dnl
191AC_REQUIRE([ACX_PTHREAD])dnl
192
193#
194# There isn't a reliable way to know we should use the Apple OpenGL framework
195# without a configure option. A Mac OS X user may have installed an
196# alternative GL implementation (e.g., Mesa), which may or may not depend on X.
197#
198AC_ARG_WITH([apple-opengl-framework],
199 [AC_HELP_STRING([--with-apple-opengl-framework],
200 [use Apple OpenGL framework (Mac OS X only)])])
201if test "X$with_apple_opengl_framework" = "Xyes"; then
202 AC_DEFINE([HAVE_APPLE_OPENGL_FRAMEWORK], [1],
203 [Use the Apple OpenGL framework.])
204 GL_LIBS="-framework OpenGL"
205else
206 AC_LANG_PUSH(C)
207
208 AX_LANG_COMPILER_MS
209 if test X$ax_compiler_ms = Xno; then
210 GL_CFLAGS="${PTHREAD_CFLAGS}"
211 GL_LIBS="${PTHREAD_LIBS} -lm"
212 fi
213
214 #
215 # Use x_includes and x_libraries if they have been set (presumably by
216 # AC_PATH_X).
217 #
218 if test "X$no_x" != "Xyes"; then
219 if test -n "$x_includes"; then
220 GL_CFLAGS="-I${x_includes} ${GL_CFLAGS}"
221 fi
222 if test -n "$x_libraries"; then
223 GL_LIBS="-L${x_libraries} -lX11 ${GL_LIBS}"
224 fi
225 fi
226
227 AC_CHECK_HEADERS([windows.h])
228
229 AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
230 [ax_cv_check_gl_libgl="no"
231 ax_save_CPPFLAGS="${CPPFLAGS}"
232 CPPFLAGS="${GL_CFLAGS} ${CPPFLAGS}"
233 ax_save_LIBS="${LIBS}"
234 LIBS=""
235 ax_check_libs="-lopengl32 -lGL"
236 for ax_lib in ${ax_check_libs}; do
237 if test X$ax_compiler_ms = Xyes; then
238 ax_try_lib=`echo $ax_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
239 else
240 ax_try_lib="${ax_lib}"
241 fi
242 LIBS="${ax_try_lib} ${GL_LIBS} ${ax_save_LIBS}"
243 AC_LINK_IFELSE(
244 [AC_LANG_PROGRAM([[
245# if HAVE_WINDOWS_H && defined(_WIN32)
246# include <windows.h>
247# endif
248# include <GL/gl.h>]],
249 [[glBegin(0)]])],
250 [ax_cv_check_gl_libgl="${ax_try_lib}"; break])
251 done
252 LIBS=${ax_save_LIBS}
253 CPPFLAGS=${ax_save_CPPFLAGS}])
254
255 if test "X${ax_cv_check_gl_libgl}" = "Xno"; then
256 no_gl="yes"
257 GL_CFLAGS=""
258 GL_LIBS=""
259 else
260 GL_LIBS="${ax_cv_check_gl_libgl} ${GL_LIBS}"
261 fi
262 AC_LANG_POP(C)
263fi
264
265AC_SUBST([GL_CFLAGS])
266AC_SUBST([GL_LIBS])
267])dnl
268
269dnl ---------------------------------------------------------------------------
270dnl Available from the GNU Autoconf Macro Archive at:
271dnl http://www.gnu.org/software/ac-archive/ax_check_glu.html
272dnl ---------------------------------------------------------------------------
273
274dnl @synopsis AX_CHECK_GLU
275dnl
276dnl Check for GLU. If GLU is found, the required preprocessor and
277dnl linker flags are included in the output variables "GLU_CFLAGS" and
278dnl "GLU_LIBS", respectively. This macro adds the configure option
279dnl "--with-apple-opengl-framework", which users can use to indicate
280dnl that Apple's OpenGL framework should be used on Mac OS X. If
281dnl Apple's OpenGL framework is used, the symbol
282dnl "HAVE_APPLE_OPENGL_FRAMEWORK" is defined. If no GLU implementation
283dnl is found, "no_glu" is set to "yes".
284dnl
285dnl @category InstalledPackages
286dnl @author Braden McDaniel <braden@endoframe.com>
287dnl @version 2004-11-15
288dnl @license AllPermissive
289
290AC_DEFUN([AX_CHECK_GLU],
291[AC_REQUIRE([AX_CHECK_GL])dnl
292AC_REQUIRE([AC_PROG_CXX])dnl
293GLU_CFLAGS="${GL_CFLAGS}"
294if test "X${with_apple_opengl_framework}" != "Xyes"; then
295 AC_CACHE_CHECK([for OpenGL Utility library], [ax_cv_check_glu_libglu],
296 [ax_cv_check_glu_libglu="no"
297 ax_save_CPPFLAGS="${CPPFLAGS}"
298 CPPFLAGS="${GL_CFLAGS} ${CPPFLAGS}"
299 ax_save_LIBS="${LIBS}"
300 LIBS=""
301 ax_check_libs="-lglu32 -lGLU"
302 for ax_lib in ${ax_check_libs}; do
303 if test X$ax_compiler_ms = Xyes; then
304 ax_try_lib=`echo $ax_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
305 else
306 ax_try_lib="${ax_lib}"
307 fi
308 LIBS="${ax_try_lib} ${GL_LIBS} ${ax_save_LIBS}"
309 #
310 # libGLU typically links with libstdc++ on POSIX platforms. However,
311 # setting the language to C++ means that test program source is named
312 # "conftest.cc"; and Microsoft cl doesn't know what to do with such a
313 # file.
314 #
315 AC_LANG_PUSH([C++])
316 if test X$ax_compiler_ms = Xyes; then
317 AC_LANG_PUSH([C])
318 fi
319 AC_LINK_IFELSE(
320 [AC_LANG_PROGRAM([[
321# if HAVE_WINDOWS_H && defined(_WIN32)
322# include <windows.h>
323# endif
324# include <GL/glu.h>]],
325 [[gluBeginCurve(0)]])],
326 [ax_cv_check_glu_libglu="${ax_try_lib}"; break])
327 if test X$ax_compiler_ms = Xyes; then
328 AC_LANG_POP([C])
329 fi
330 AC_LANG_POP([C++])
331 done
332 LIBS=${ax_save_LIBS}
333 CPPFLAGS=${ax_save_CPPFLAGS}])
334 if test "X${ax_cv_check_glu_libglu}" = "Xno"; then
335 no_glu="yes"
336 GLU_CFLAGS=""
337 GLU_LIBS=""
338 else
339 GLU_LIBS="${ax_cv_check_glu_libglu} ${GL_LIBS}"
340 fi
341fi
342AC_SUBST([GLU_CFLAGS])
343AC_SUBST([GLU_LIBS])
344])
345
346dnl ---------------------------------------------------------------------------
347dnl Available from the GNU Autoconf Macro Archive at:
348dnl http://www.gnu.org/software/ac-archive/ax_check_glut.html
349dnl ---------------------------------------------------------------------------
350
351dnl @synopsis AX_CHECK_GLUT
352dnl
353dnl Check for GLUT. If GLUT is found, the required compiler and linker
354dnl flags are included in the output variables "GLUT_CFLAGS" and
355dnl "GLUT_LIBS", respectively. This macro adds the configure option
356dnl "--with-apple-opengl-framework", which users can use to indicate
357dnl that Apple's OpenGL framework should be used on Mac OS X. If
358dnl Apple's OpenGL framework is used, the symbol
359dnl "HAVE_APPLE_OPENGL_FRAMEWORK" is defined. If GLUT is not found,
360dnl "no_glut" is set to "yes".
361dnl
362dnl @category InstalledPackages
363dnl @author Braden McDaniel <braden@endoframe.com>
364dnl @version 2004-11-15
365dnl @license AllPermissive
366
367AC_DEFUN([AX_CHECK_GLUT],
368[AC_REQUIRE([AX_CHECK_GLU])dnl
369AC_REQUIRE([AC_PATH_XTRA])dnl
370
371if test "X$with_apple_opengl_framework" = "Xyes"; then
372 GLUT_CFLAGS="${GLU_CFLAGS}"
373 GLUT_LIBS="-framework GLUT -lobjc ${GL_LIBS}"
374else
375 GLUT_CFLAGS=${GLU_CFLAGS}
376 GLUT_LIBS=${GLU_LIBS}
377
378 #
379 # If X is present, assume GLUT depends on it.
380 #
381 if test "X${no_x}" != "Xyes"; then
382 GLUT_LIBS="${X_PRE_LIBS} -lXmu -lXi ${X_EXTRA_LIBS} ${GLUT_LIBS}"
383 fi
384
385 AC_LANG_PUSH(C)
386
387 ax_save_CPPFLAGS="${CPPFLAGS}"
388 CPPFLAGS="${GLUT_CFLAGS} ${CPPFLAGS}"
389
390 AC_CACHE_CHECK([for GLUT library], [ax_cv_check_glut_libglut],
391 [ax_cv_check_glut_libglut="no"
392 ax_save_LIBS="${LIBS}"
393 LIBS=""
394 ax_check_libs="-lglut32 -lglut"
395 for ax_lib in ${ax_check_libs}; do
396 if test X$ax_compiler_ms = Xyes; then
397 ax_try_lib=`echo $ax_lib | sed -e 's/^-l//' -e 's/$/.lib/'`
398 else
399 ax_try_lib="${ax_lib}"
400 fi
401 LIBS="${ax_try_lib} ${GLUT_LIBS} ${ax_save_LIBS}"
402 AC_LINK_IFELSE(
403 [AC_LANG_PROGRAM([[
404# if HAVE_WINDOWS_H && defined(_WIN32)
405# include <windows.h>
406# endif
407# include <GL/glut.h>]],
408 [[glutMainLoop()]])],
409 [ax_cv_check_glut_libglut="${ax_try_lib}"; break])
410
411 done
412 LIBS=${ax_save_LIBS}
413 ])
414 CPPFLAGS="${ax_save_CPPFLAGS}"
415 AC_LANG_POP(C)
416
417 if test "X${ax_cv_check_glut_libglut}" = "Xno"; then
418 no_glut="yes"
419 GLUT_CFLAGS=""
420 GLUT_LIBS=""
421 else
422 GLUT_LIBS="${ax_cv_check_glut_libglut} ${GLUT_LIBS}"
423 fi
424fi
425
426AC_SUBST([GLUT_CFLAGS])
427AC_SUBST([GLUT_LIBS])
428])dnl
429
430dnl ---------------------------------------------------------------------------
431dnl Available from the GNU Autoconf Macro Archive at:
432dnl http://www.gnu.org/software/ac-archive/acx_pthread.html
433dnl ---------------------------------------------------------------------------
434
435dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
436dnl
437dnl This macro figures out how to build C programs using POSIX threads.
438dnl It sets the PTHREAD_LIBS output variable to the threads library and
439dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
440dnl C compiler flags that are needed. (The user can also force certain
441dnl compiler flags/libs to be tested by setting these environment
442dnl variables.)
443dnl
444dnl Also sets PTHREAD_CC to any special C compiler that is needed for
445dnl multi-threaded programs (defaults to the value of CC otherwise).
446dnl (This is necessary on AIX to use the special cc_r compiler alias.)
447dnl
448dnl NOTE: You are assumed to not only compile your program with these
449dnl flags, but also link it with them as well. e.g. you should link
450dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
451dnl $LIBS
452dnl
453dnl If you are only building threads programs, you may wish to use
454dnl these variables in your default LIBS, CFLAGS, and CC:
455dnl
456dnl LIBS="$PTHREAD_LIBS $LIBS"
457dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
458dnl CC="$PTHREAD_CC"
459dnl
460dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
461dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
462dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
463dnl
464dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
465dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
466dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
467dnl default action will define HAVE_PTHREAD.
468dnl
469dnl Please let the authors know if this macro fails on any platform, or
470dnl if you have any other suggestions or comments. This macro was based
471dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
472dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
473dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
474dnl We are also grateful for the helpful feedback of numerous users.
475dnl
476dnl @category InstalledPackages
477dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
478dnl @version 2005-01-14
479dnl @license GPLWithACException
480
481AC_DEFUN([ACX_PTHREAD], [
482AC_REQUIRE([AC_CANONICAL_HOST])
483AC_LANG_SAVE
484AC_LANG_C
485acx_pthread_ok=no
486
487# We used to check for pthread.h first, but this fails if pthread.h
488# requires special compiler flags (e.g. on True64 or Sequent).
489# It gets checked for in the link test anyway.
490
491# First of all, check if the user has set any of the PTHREAD_LIBS,
492# etcetera environment variables, and if threads linking works using
493# them:
494if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
495 save_CFLAGS="$CFLAGS"
496 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
497 save_LIBS="$LIBS"
498 LIBS="$PTHREAD_LIBS $LIBS"
499 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
500 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
501 AC_MSG_RESULT($acx_pthread_ok)
502 if test x"$acx_pthread_ok" = xno; then
503 PTHREAD_LIBS=""
504 PTHREAD_CFLAGS=""
505 fi
506 LIBS="$save_LIBS"
507 CFLAGS="$save_CFLAGS"
508fi
509
510# We must check for the threads library under a number of different
511# names; the ordering is very important because some systems
512# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
513# libraries is broken (non-POSIX).
514
515# Create a list of thread flags to try. Items starting with a "-" are
516# C compiler flags, and other items are library names, except for "none"
517# which indicates that we try without any flags at all, and "pthread-config"
518# which is a program returning the flags for the Pth emulation library.
519
520acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
521
522# The ordering *is* (sometimes) important. Some notes on the
523# individual items follow:
524
525# pthreads: AIX (must check this before -lpthread)
526# none: in case threads are in libc; should be tried before -Kthread and
527# other compiler flags to prevent continual compiler warnings
528# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
529# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
530# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
531# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
532# -pthreads: Solaris/gcc
533# -mthreads: Mingw32/gcc, Lynx/gcc
534# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
535# doesn't hurt to check since this sometimes defines pthreads too;
536# also defines -D_REENTRANT)
537# pthread: Linux, etcetera
538# --thread-safe: KAI C++
539# pthread-config: use pthread-config program (for GNU Pth library)
540
541case "${host_cpu}-${host_os}" in
542 *solaris*)
543
544 # On Solaris (at least, for some versions), libc contains stubbed
545 # (non-functional) versions of the pthreads routines, so link-based
546 # tests will erroneously succeed. (We need to link with -pthread or
547 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
548 # a function called by this macro, so we could check for that, but
549 # who knows whether they'll stub that too in a future libc.) So,
550 # we'll just look for -pthreads and -lpthread first:
551
552 acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
553 ;;
554esac
555
556if test x"$acx_pthread_ok" = xno; then
557for flag in $acx_pthread_flags; do
558
559 case $flag in
560 none)
561 AC_MSG_CHECKING([whether pthreads work without any flags])
562 ;;
563
564 -*)
565 AC_MSG_CHECKING([whether pthreads work with $flag])
566 PTHREAD_CFLAGS="$flag"
567 ;;
568
569 pthread-config)
570 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
571 if test x"$acx_pthread_config" = xno; then continue; fi
572 PTHREAD_CFLAGS="`pthread-config --cflags`"
573 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
574 ;;
575
576 *)
577 AC_MSG_CHECKING([for the pthreads library -l$flag])
578 PTHREAD_LIBS="-l$flag"
579 ;;
580 esac
581
582 save_LIBS="$LIBS"
583 save_CFLAGS="$CFLAGS"
584 LIBS="$PTHREAD_LIBS $LIBS"
585 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
586
587 # Check for various functions. We must include pthread.h,
588 # since some functions may be macros. (On the Sequent, we
589 # need a special flag -Kthread to make this header compile.)
590 # We check for pthread_join because it is in -lpthread on IRIX
591 # while pthread_create is in libc. We check for pthread_attr_init
592 # due to DEC craziness with -lpthreads. We check for
593 # pthread_cleanup_push because it is one of the few pthread
594 # functions on Solaris that doesn't have a non-functional libc stub.
595 # We try pthread_create on general principles.
596 AC_TRY_LINK([#include <pthread.h>],
597 [pthread_t th; pthread_join(th, 0);
598 pthread_attr_init(0); pthread_cleanup_push(0, 0);
599 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
600 [acx_pthread_ok=yes])
601
602 LIBS="$save_LIBS"
603 CFLAGS="$save_CFLAGS"
604
605 AC_MSG_RESULT($acx_pthread_ok)
606 if test "x$acx_pthread_ok" = xyes; then
607 break;
608 fi
609
610 PTHREAD_LIBS=""
611 PTHREAD_CFLAGS=""
612done
613fi
614
615# Various other checks:
616if test "x$acx_pthread_ok" = xyes; then
617 save_LIBS="$LIBS"
618 LIBS="$PTHREAD_LIBS $LIBS"
619 save_CFLAGS="$CFLAGS"
620 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
621
622 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
623 AC_MSG_CHECKING([for joinable pthread attribute])
624 attr_name=unknown
625 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
626 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr;],
627 [attr_name=$attr; break])
628 done
629 AC_MSG_RESULT($attr_name)
630 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
631 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
632 [Define to necessary symbol if this constant
633 uses a non-standard name on your system.])
634 fi
635
636 AC_MSG_CHECKING([if more special flags are required for pthreads])
637 flag=no
638 case "${host_cpu}-${host_os}" in
639 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
640 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
641 esac
642 AC_MSG_RESULT(${flag})
643 if test "x$flag" != xno; then
644 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
645 fi
646
647 LIBS="$save_LIBS"
648 CFLAGS="$save_CFLAGS"
649
650 # More AIX lossage: must compile with cc_r
651 AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
652else
653 PTHREAD_CC="$CC"
654fi
655
656AC_SUBST(PTHREAD_LIBS)
657AC_SUBST(PTHREAD_CFLAGS)
658AC_SUBST(PTHREAD_CC)
659
660# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
661if test x"$acx_pthread_ok" = xyes; then
662 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
663 :
664else
665 acx_pthread_ok=no
666 $2
667fi
668AC_LANG_RESTORE
669])dnl ACX_PTHREAD