1 # AST_GCC_ATTRIBUTE([attribute name])
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
5 AC_MSG_CHECKING(for compiler 'attribute $1' support)
7 AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
10 AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
14 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
16 AC_DEFUN([AST_EXT_LIB_SETUP],
20 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),[
26 ac_mandatory_list="${ac_mandatory_list} $1"
30 ac_mandatory_list="${ac_mandatory_list} $1"
36 AC_SUBST([$1_INCLUDE])
40 # Check whether any of the mandatory modules are not present, and
41 # print error messages in case.
43 AC_DEFUN([AST_CHECK_MANDATORY],
45 AC_MSG_CHECKING([for mandatory modules: ${ac_mandatory_list}])
47 for i in ${ac_mandatory_list}; do
49 if test "x${a}" = "x1" ; then continue; fi
50 if test ${err} = "0" ; then AC_MSG_RESULT(fail) ; fi
52 eval "a=\${${i}_OPTION}"
54 AC_MSG_NOTICE([*** The $i installation appears to be missing or broken.])
55 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
56 AC_MSG_NOTICE([*** including --without-${a}.])
59 if test $err = 1 ; then exit 1; fi
63 #-- The following two tests are only performed if PBX_$1 != 1,
64 # so you can use multiple tests and stop at the first matching one.
65 # On success, set PBX_$1 = 1, and also #define HAVE_$1 1
66 # and #define HAVE_$1_VERSION ${last_argument} so you can tell which
68 # They should be called after AST_EXT_LIB_SETUP($1, ...)
70 # Check if a given macro is defined in a certain header.
72 # AST_C_DEFINE_CHECK([package symbol name], [macro name], [header file], [version])
73 AC_DEFUN([AST_C_DEFINE_CHECK],
75 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
76 AC_MSG_CHECKING([for $2 in $3])
77 saved_cppflags="${CPPFLAGS}"
78 if test "x${$1_DIR}" != "x"; then
79 $1_INCLUDE= "-I${$1_DIR}/include"
81 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
84 [ AC_LANG_PROGRAM( [#include <$3>], [int foo = $2;]) ],
87 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
88 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
92 CPPFLAGS="${saved_cppflags}"
97 # Check for existence of a given package ($1), either looking up a function
98 # in a library, or, if no function is supplied, only check for the
99 # existence of the header files.
101 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data], [version])
102 AC_DEFUN([AST_EXT_LIB_CHECK],
104 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
106 if test "x${$1_DIR}" != "x"; then
107 if test -d ${$1_DIR}/lib; then
108 pbxlibdir="-L${$1_DIR}/lib"
110 pbxlibdir="-L${$1_DIR}"
114 if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
117 AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
120 if test "${AST_$1_FOUND}" = "yes"; then
123 if test "x${$1_DIR}" != "x"; then
124 $1_LIB="${pbxlibdir} ${$1_LIB}"
125 $1_INCLUDE="-I${$1_DIR}/include"
126 saved_cppflags="${CPPFLAGS}"
127 CPPFLAGS="${CPPFLAGS} -I${$1_DIR}/include"
128 if test "x$4" != "x" ; then
129 AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
131 CPPFLAGS="${saved_cppflags}"
133 if test "x$4" != "x" ; then
134 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
137 if test "x${$1_HEADER_FOUND}" = "x0" ; then
141 if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
145 # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
146 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
147 AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$6], [Define to indicate the ${$1_DESCRIP} library version])
155 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
156 GNU_MAKE='Not Found' ;
157 GNU_MAKE_VERSION_MAJOR=0 ;
158 GNU_MAKE_VERSION_MINOR=0 ;
159 for a in make gmake gnumake ; do
160 if test -z "$a" ; then continue ; fi ;
161 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
163 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
164 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
169 if test "x$GNU_MAKE" = "xNot Found" ; then
170 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
181 if test "${PWLIBDIR:-unset}" != "unset" ; then
182 AC_CHECK_FILE(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
184 if test "${HAS_PWLIB:-unset}" = "unset" ; then
185 if test "${OPENH323DIR:-unset}" != "unset"; then
186 AC_CHECK_FILE(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
188 if test "${HAS_PWLIB:-unset}" != "unset" ; then
189 PWLIBDIR="${OPENH323DIR}/../pwlib"
191 AC_CHECK_FILE(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
192 if test "${HAS_PWLIB:-unset}" != "unset" ; then
193 PWLIBDIR="${HOME}/pwlib"
195 AC_CHECK_FILE(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
196 if test "${HAS_PWLIB:-unset}" != "unset" ; then
197 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
198 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
199 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
201 PWLIB_INCDIR="/usr/local/include"
202 if test "x$LIB64" != "x"; then
203 PWLIB_LIBDIR="/usr/local/lib64"
205 PWLIB_LIBDIR="/usr/local/lib"
208 AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
209 if test "${HAS_PWLIB:-unset}" != "unset" ; then
210 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
211 PWLIB_INCDIR="/usr/include"
212 if test "x$LIB64" != "x"; then
213 PWLIB_LIBDIR="/usr/lib64"
215 PWLIB_LIBDIR="/usr/lib"
223 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
224 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
228 if test "${HAS_PWLIB:-unset}" != "unset" ; then
229 if test "${PWLIBDIR:-unset}" = "unset" ; then
230 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
231 PWLIBDIR=`$PTLIB_CONFIG --prefix`
233 echo "Cannot find ptlib-config - please install and try again"
238 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
239 PWLIBDIR="/usr/share/pwlib"
240 PWLIB_INCDIR="/usr/include"
241 if test "x$LIB64" != "x"; then
242 PWLIB_LIBDIR="/usr/lib64"
244 PWLIB_LIBDIR="/usr/lib"
247 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
248 PWLIBDIR="/usr/local/share/pwlib"
249 PWLIB_INCDIR="/usr/local/include"
250 if test "x$LIB64" != "x"; then
251 PWLIB_LIBDIR="/usr/local/lib64"
253 PWLIB_LIBDIR="/usr/local/lib"
257 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
258 PWLIB_INCDIR="${PWLIBDIR}/include"
260 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
261 PWLIB_LIBDIR="${PWLIBDIR}/lib"
265 AC_SUBST([PWLIB_INCDIR])
266 AC_SUBST([PWLIB_LIBDIR])
272 [AST_CHECK_OPENH323_PLATFORM], [
275 linux*) PWLIB_OSTYPE=linux ;
277 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
279 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
280 ENDLDLIBS="-lossaudio" ;
282 netbsd* ) PWLIB_OSTYPE=NetBSD ;
283 ENDLDLIBS="-lossaudio" ;
285 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
287 darwin* ) PWLIB_OSTYPE=Darwin ;
289 beos*) PWLIB_OSTYPE=beos ;
290 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
292 cygwin*) PWLIB_OSTYPE=cygwin ;
294 mingw*) PWLIB_OSTYPE=mingw ;
295 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
296 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
298 * ) PWLIB_OSTYPE="$host_os" ;
299 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
305 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
308 x86_64) PWLIB_MACHTYPE=x86_64 ;
313 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
317 sparc ) PWLIB_MACHTYPE=sparc ;
320 powerpc ) PWLIB_MACHTYPE=ppc ;
323 ppc ) PWLIB_MACHTYPE=ppc ;
326 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
331 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
336 ia64) PWLIB_MACHTYPE=ia64 ;
340 s390x) PWLIB_MACHTYPE=s390x ;
345 s390) PWLIB_MACHTYPE=s390 ;
348 * ) PWLIB_MACHTYPE="$host_cpu";
349 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
352 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
354 AC_SUBST([PWLIB_PLATFORM])
359 [AST_CHECK_OPENH323], [
362 if test "${OPENH323DIR:-unset}" != "unset" ; then
363 AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
365 if test "${HAS_OPENH323:-unset}" = "unset" ; then
366 AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
367 if test "${HAS_OPENH323:-unset}" != "unset" ; then
368 OPENH323DIR="${PWLIBDIR}/../openh323"
369 AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
371 AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
372 if test "${HAS_OPENH323:-unset}" != "unset" ; then
373 OPENH323DIR="${HOME}/openh323"
375 AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
376 if test "${HAS_OPENH323:-unset}" != "unset" ; then
377 OPENH323DIR="/usr/local/share/openh323"
378 OPENH323_INCDIR="/usr/local/include/openh323"
379 if test "x$LIB64" != "x"; then
380 OPENH323_LIBDIR="/usr/local/lib64"
382 OPENH323_LIBDIR="/usr/local/lib"
385 AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
386 if test "${HAS_OPENH323:-unset}" != "unset" ; then
387 OPENH323DIR="/usr/share/openh323"
388 OPENH323_INCDIR="/usr/include/openh323"
389 if test "x$LIB64" != "x"; then
390 OPENH323_LIBDIR="/usr/lib64"
392 OPENH323_LIBDIR="/usr/lib"
400 if test "${HAS_OPENH323:-unset}" != "unset" ; then
401 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
402 OPENH323_INCDIR="${OPENH323DIR}/include"
404 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
405 OPENH323_LIBDIR="${OPENH323DIR}/lib"
408 AC_SUBST([OPENH323DIR])
409 AC_SUBST([OPENH323_INCDIR])
410 AC_SUBST([OPENH323_LIBDIR])
416 [AST_CHECK_PWLIB_VERSION], [
417 if test "${HAS_$2:-unset}" != "unset"; then
418 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
419 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
420 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
421 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
422 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
423 let $2_REQ=$4*10000+$5*100+$6
425 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
426 if test ${$2_VER} -lt ${$2_REQ}; then
437 [AST_CHECK_PWLIB_BUILD], [
438 if test "${HAS_$2:-unset}" != "unset"; then
439 AC_MSG_CHECKING($1 installation validity)
441 saved_cppflags="${CPPFLAGS}"
443 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
444 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
449 [AC_LANG_PROGRAM([$4],[$5])],
461 CPPFLAGS="${saved_cppflags}"
463 if test "${ac_cv_lib_$2}" = "yes"; then
464 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
465 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
467 $2_LIB="-l${PLATFORM_$2}"
469 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
470 $2_INCLUDE="-I${$2_INCDIR}"
473 AC_DEFINE([HAVE_$2], 1, [$3])
479 [AST_CHECK_OPENH323_BUILD], [
480 if test "${HAS_OPENH323:-unset}" != "unset"; then
481 AC_MSG_CHECKING(OpenH323 build option)
483 files=`ls -l ${OPENH323_LIBDIR}/libh323_${PWLIB_PLATFORM}_*.so*`
485 if test -n "$files"; then
487 if test -f $f -a ! -L $f; then
488 libfile=`basename $f`
493 if test "${libfile:-unset}" != "unset"; then
494 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/libh323_${PWLIB_PLATFORM}_\(@<:@^.@:>@*\)\..*/\1/'"`
496 case "${OPENH323_SUFFIX}" in
498 OPENH323_BUILD="notrace";;
500 OPENH323_BUILD="opt";;
502 OPENH323_BUILD="debug";;
504 OPENH323_BUILD="notrace";;
506 AC_MSG_RESULT(${OPENH323_BUILD})
508 AC_SUBST([OPENH323_SUFFIX])
509 AC_SUBST([OPENH323_BUILD])
516 AN_FUNCTION([fork], [AST_FUNC_FORK])
517 AN_FUNCTION([vfork], [AST_FUNC_FORK])
518 AC_DEFUN([AST_FUNC_FORK],
519 [AC_REQUIRE([AC_TYPE_PID_T])dnl
520 AC_CHECK_HEADERS(vfork.h)
521 AC_CHECK_FUNCS(fork vfork)
522 if test "x$ac_cv_func_fork" = xyes; then
525 ac_cv_func_fork_works=$ac_cv_func_fork
527 if test "x$ac_cv_func_fork_works" = xcross; then
529 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* )
530 # Override, as these systems have only a dummy fork() stub
531 ac_cv_func_fork_works=no
534 ac_cv_func_fork_works=yes
537 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
539 ac_cv_func_vfork_works=$ac_cv_func_vfork
540 if test "x$ac_cv_func_vfork" = xyes; then
543 if test "x$ac_cv_func_fork_works" = xcross; then
544 ac_cv_func_vfork_works=$ac_cv_func_vfork
545 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
548 if test "x$ac_cv_func_vfork_works" = xyes; then
549 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
551 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
553 if test "x$ac_cv_func_fork_works" = xyes; then
554 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
561 AC_DEFUN([_AST_FUNC_FORK],
562 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
564 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
566 /* By Ruediger Kuhlmann. */
569 [ac_cv_func_fork_works=yes],
570 [ac_cv_func_fork_works=no],
571 [ac_cv_func_fork_works=cross])])]
576 # find the pathname to the GNU or non-GNU linker
577 AC_DEFUN([AST_PROG_LD],
578 [AC_ARG_WITH([gnu-ld],
579 [AC_HELP_STRING([--with-gnu-ld],
580 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
581 [test "$withval" = no || with_gnu_ld=yes],
583 AC_REQUIRE([AST_PROG_SED])dnl
584 AC_REQUIRE([AC_PROG_CC])dnl
585 AC_REQUIRE([AC_CANONICAL_HOST])dnl
586 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
588 if test "$GCC" = yes; then
589 # Check if gcc -print-prog-name=ld gives a path.
590 AC_MSG_CHECKING([for ld used by $CC])
593 # gcc leaves a trailing carriage return which upsets mingw
594 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
596 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
599 # Accept absolute paths.
600 [[\\/]]* | ?:[[\\/]]*)
601 re_direlt='/[[^/]][[^/]]*/\.\./'
602 # Canonicalize the pathname of ld
603 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
604 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
605 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
607 test -z "$LD" && LD="$ac_prog"
610 # If it fails, then pretend we aren't using GCC.
614 # If it is relative, then search for the first ld in PATH.
618 elif test "$with_gnu_ld" = yes; then
619 AC_MSG_CHECKING([for GNU ld])
621 AC_MSG_CHECKING([for non-GNU ld])
623 AC_CACHE_VAL(lt_cv_path_LD,
624 [if test -z "$LD"; then
625 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
626 for ac_dir in $PATH; do
628 test -z "$ac_dir" && ac_dir=.
629 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
630 lt_cv_path_LD="$ac_dir/$ac_prog"
631 # Check to see if the program is GNU ld. I'd rather use --version,
632 # but apparently some variants of GNU ld only accept -v.
633 # Break only if it was the GNU/non-GNU ld that we prefer.
634 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
635 *GNU* | *'with BFD'*)
636 test "$with_gnu_ld" != no && break
639 test "$with_gnu_ld" != yes && break
646 lt_cv_path_LD="$LD" # Let the user override the test with a path.
649 if test -n "$LD"; then
654 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
661 AC_DEFUN([AST_PROG_LD_GNU],
662 [AC_REQUIRE([AST_PROG_EGREP])dnl
663 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
664 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
665 case `$LD -v 2>&1 </dev/null` in
666 *GNU* | *'with BFD'*)
667 lt_cv_prog_gnu_ld=yes
673 with_gnu_ld=$lt_cv_prog_gnu_ld
678 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
679 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
680 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
681 then ac_cv_prog_egrep='grep -E'
682 else ac_cv_prog_egrep='egrep'
684 EGREP=$ac_cv_prog_egrep
686 ])]) # AST_PROG_EGREP
690 # Check for a fully functional sed program that truncates
691 # as few characters as possible. Prefer GNU sed if found.
692 AC_DEFUN([AST_PROG_SED],
693 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
694 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
695 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
696 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
697 for ac_i in 1 2 3 4 5 6 7; do
698 ac_script="$ac_script$as_nl$ac_script"
700 echo "$ac_script" | sed 99q >conftest.sed
701 $as_unset ac_script || ac_script=
702 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
703 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
704 ["$ac_path_SED" -f conftest.sed])])])
705 SED="$ac_cv_path_SED"
710 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
712 dnl @summary figure out how to build C programs using POSIX threads
714 dnl This macro figures out how to build C programs using POSIX threads.
715 dnl It sets the PTHREAD_LIBS output variable to the threads library and
716 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
717 dnl C compiler flags that are needed. (The user can also force certain
718 dnl compiler flags/libs to be tested by setting these environment
721 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
722 dnl multi-threaded programs (defaults to the value of CC otherwise).
723 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
725 dnl NOTE: You are assumed to not only compile your program with these
726 dnl flags, but also link it with them as well. e.g. you should link
727 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
730 dnl If you are only building threads programs, you may wish to use
731 dnl these variables in your default LIBS, CFLAGS, and CC:
733 dnl LIBS="$PTHREAD_LIBS $LIBS"
734 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
737 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
738 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
739 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
741 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
742 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
743 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
744 dnl default action will define HAVE_PTHREAD.
746 dnl Please let the authors know if this macro fails on any platform, or
747 dnl if you have any other suggestions or comments. This macro was based
748 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
749 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
750 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
751 dnl We are also grateful for the helpful feedback of numerous users.
753 dnl @category InstalledPackages
754 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
755 dnl @version 2006-05-29
756 dnl @license GPLWithACException
758 AC_DEFUN([ACX_PTHREAD], [
759 AC_REQUIRE([AC_CANONICAL_HOST])
764 # We used to check for pthread.h first, but this fails if pthread.h
765 # requires special compiler flags (e.g. on True64 or Sequent).
766 # It gets checked for in the link test anyway.
768 # First of all, check if the user has set any of the PTHREAD_LIBS,
769 # etcetera environment variables, and if threads linking works using
771 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
772 save_CFLAGS="$CFLAGS"
773 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
775 LIBS="$PTHREAD_LIBS $LIBS"
776 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
777 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
778 AC_MSG_RESULT($acx_pthread_ok)
779 if test x"$acx_pthread_ok" = xno; then
784 CFLAGS="$save_CFLAGS"
787 # We must check for the threads library under a number of different
788 # names; the ordering is very important because some systems
789 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
790 # libraries is broken (non-POSIX).
792 # Create a list of thread flags to try. Items starting with a "-" are
793 # C compiler flags, and other items are library names, except for "none"
794 # which indicates that we try without any flags at all, and "pthread-config"
795 # which is a program returning the flags for the Pth emulation library.
797 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
799 # The ordering *is* (sometimes) important. Some notes on the
800 # individual items follow:
802 # pthreads: AIX (must check this before -lpthread)
803 # none: in case threads are in libc; should be tried before -Kthread and
804 # other compiler flags to prevent continual compiler warnings
805 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
806 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
807 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
808 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
809 # -pthreads: Solaris/gcc
810 # -mthreads: Mingw32/gcc, Lynx/gcc
811 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
812 # doesn't hurt to check since this sometimes defines pthreads too;
813 # also defines -D_REENTRANT)
814 # ... -mt is also the pthreads flag for HP/aCC
815 # pthread: Linux, etcetera
816 # --thread-safe: KAI C++
817 # pthread-config: use pthread-config program (for GNU Pth library)
819 case "${host_cpu}-${host_os}" in
822 # On Solaris (at least, for some versions), libc contains stubbed
823 # (non-functional) versions of the pthreads routines, so link-based
824 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
825 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
826 # a function called by this macro, so we could check for that, but
827 # who knows whether they'll stub that too in a future libc.) So,
828 # we'll just look for -pthreads and -lpthread first:
830 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
834 if test x"$acx_pthread_ok" = xno; then
835 for flag in $acx_pthread_flags; do
839 AC_MSG_CHECKING([whether pthreads work without any flags])
843 AC_MSG_CHECKING([whether pthreads work with $flag])
844 PTHREAD_CFLAGS="$flag"
848 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
849 if test x"$acx_pthread_config" = xno; then continue; fi
850 PTHREAD_CFLAGS="`pthread-config --cflags`"
851 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
855 AC_MSG_CHECKING([for the pthreads library -l$flag])
856 PTHREAD_LIBS="-l$flag"
861 save_CFLAGS="$CFLAGS"
862 LIBS="$PTHREAD_LIBS $LIBS"
863 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
865 # Check for various functions. We must include pthread.h,
866 # since some functions may be macros. (On the Sequent, we
867 # need a special flag -Kthread to make this header compile.)
868 # We check for pthread_join because it is in -lpthread on IRIX
869 # while pthread_create is in libc. We check for pthread_attr_init
870 # due to DEC craziness with -lpthreads. We check for
871 # pthread_cleanup_push because it is one of the few pthread
872 # functions on Solaris that doesn't have a non-functional libc stub.
873 # We try pthread_create on general principles.
874 AC_TRY_LINK([#include <pthread.h>],
875 [pthread_t th; pthread_join(th, 0);
876 pthread_attr_init(0); pthread_cleanup_push(0, 0);
877 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
878 [acx_pthread_ok=yes])
881 CFLAGS="$save_CFLAGS"
883 AC_MSG_RESULT($acx_pthread_ok)
884 if test "x$acx_pthread_ok" = xyes; then
893 # Various other checks:
894 if test "x$acx_pthread_ok" = xyes; then
896 LIBS="$PTHREAD_LIBS $LIBS"
897 save_CFLAGS="$CFLAGS"
898 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
900 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
901 AC_MSG_CHECKING([for joinable pthread attribute])
903 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
904 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
905 [attr_name=$attr; break])
907 AC_MSG_RESULT($attr_name)
908 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
909 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
910 [Define to necessary symbol if this constant
911 uses a non-standard name on your system.])
914 AC_MSG_CHECKING([if more special flags are required for pthreads])
916 case "${host_cpu}-${host_os}" in
917 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
918 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
920 AC_MSG_RESULT(${flag})
921 if test "x$flag" != xno; then
922 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
926 CFLAGS="$save_CFLAGS"
928 # More AIX lossage: must compile with xlc_r or cc_r
929 if test x"$GCC" != xyes; then
930 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
938 AC_SUBST(PTHREAD_LIBS)
939 AC_SUBST(PTHREAD_CFLAGS)
942 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
943 if test x"$acx_pthread_ok" = xyes; then
944 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])