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])
41 # Check whether any of the mandatory modules are not present, and
42 # print error messages in case.
44 AC_DEFUN([AST_CHECK_MANDATORY],
46 AC_MSG_CHECKING([for mandatory modules: ${ac_mandatory_list}])
48 for i in ${ac_mandatory_list}; do
50 if test "x${a}" = "x1" ; then continue; fi
51 if test ${err} = "0" ; then AC_MSG_RESULT(fail) ; fi
53 eval "a=\${${i}_OPTION}"
55 AC_MSG_NOTICE([*** The $i installation appears to be missing or broken.])
56 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
57 AC_MSG_NOTICE([*** including --without-${a}.])
60 if test $err = 1 ; then exit 1; fi
64 #-- The following two tests are only performed if PBX_$1 != 1,
65 # so you can use multiple tests and stop at the first matching one.
66 # On success, set PBX_$1 = 1, and also #define HAVE_$1 1
67 # and #define HAVE_$1_VERSION ${last_argument} so you can tell which
69 # They should be called after AST_EXT_LIB_SETUP($1, ...)
71 # Check if a given macro is defined in a certain header.
73 # AST_C_DEFINE_CHECK([package symbol name], [macro name], [header file], [version])
74 AC_DEFUN([AST_C_DEFINE_CHECK],
76 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
77 AC_MSG_CHECKING([for $2 in $3])
78 saved_cppflags="${CPPFLAGS}"
79 if test "x${$1_DIR}" != "x"; then
80 $1_INCLUDE= "-I${$1_DIR}/include"
82 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
85 [ AC_LANG_PROGRAM( [#include <$3>], [int foo = $2;]) ],
88 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
89 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
93 CPPFLAGS="${saved_cppflags}"
98 # Check for existence of a given package ($1), either looking up a function
99 # in a library, or, if no function is supplied, only check for the
100 # existence of the header files.
102 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data], [version])
103 AC_DEFUN([AST_EXT_LIB_CHECK],
105 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
107 if test "x${$1_DIR}" != "x"; then
108 if test -d ${$1_DIR}/lib; then
109 pbxlibdir="-L${$1_DIR}/lib"
111 pbxlibdir="-L${$1_DIR}"
115 if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
118 AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
121 if test "${AST_$1_FOUND}" = "yes"; then
124 if test "x${$1_DIR}" != "x"; then
125 $1_LIB="${pbxlibdir} ${$1_LIB}"
126 $1_INCLUDE="-I${$1_DIR}/include"
127 saved_cppflags="${CPPFLAGS}"
128 CPPFLAGS="${CPPFLAGS} -I${$1_DIR}/include"
129 if test "x$4" != "x" ; then
130 AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
132 CPPFLAGS="${saved_cppflags}"
134 if test "x$4" != "x" ; then
135 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
138 if test "x${$1_HEADER_FOUND}" = "x0" ; then
142 if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
146 # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
147 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
148 AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$6], [Define to indicate the ${$1_DESCRIP} library version])
156 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
157 GNU_MAKE='Not Found' ;
158 GNU_MAKE_VERSION_MAJOR=0 ;
159 GNU_MAKE_VERSION_MINOR=0 ;
160 for a in make gmake gnumake ; do
161 if test -z "$a" ; then continue ; fi ;
162 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
164 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
165 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
170 if test "x$GNU_MAKE" = "xNot Found" ; then
171 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
182 if test "${PWLIBDIR:-unset}" != "unset" ; then
183 AC_CHECK_FILE(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
185 if test "${HAS_PWLIB:-unset}" = "unset" ; then
186 if test "${OPENH323DIR:-unset}" != "unset"; then
187 AC_CHECK_FILE(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
189 if test "${HAS_PWLIB:-unset}" != "unset" ; then
190 PWLIBDIR="${OPENH323DIR}/../pwlib"
192 AC_CHECK_FILE(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
193 if test "${HAS_PWLIB:-unset}" != "unset" ; then
194 PWLIBDIR="${HOME}/pwlib"
196 AC_CHECK_FILE(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
197 if test "${HAS_PWLIB:-unset}" != "unset" ; then
198 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
199 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
200 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
202 PWLIB_INCDIR="/usr/local/include"
203 if test "x$LIB64" != "x"; then
204 PWLIB_LIBDIR="/usr/local/lib64"
206 PWLIB_LIBDIR="/usr/local/lib"
209 AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
210 if test "${HAS_PWLIB:-unset}" != "unset" ; then
211 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
212 PWLIB_INCDIR="/usr/include"
213 if test "x$LIB64" != "x"; then
214 PWLIB_LIBDIR="/usr/lib64"
216 PWLIB_LIBDIR="/usr/lib"
224 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
225 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
229 if test "${HAS_PWLIB:-unset}" != "unset" ; then
230 if test "${PWLIBDIR:-unset}" = "unset" ; then
231 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
232 PWLIBDIR=`$PTLIB_CONFIG --prefix`
234 echo "Cannot find ptlib-config - please install and try again"
239 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
240 PWLIBDIR="/usr/share/pwlib"
241 PWLIB_INCDIR="/usr/include"
242 if test "x$LIB64" != "x"; then
243 PWLIB_LIBDIR="/usr/lib64"
245 PWLIB_LIBDIR="/usr/lib"
248 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
249 PWLIBDIR="/usr/local/share/pwlib"
250 PWLIB_INCDIR="/usr/local/include"
251 if test "x$LIB64" != "x"; then
252 PWLIB_LIBDIR="/usr/local/lib64"
254 PWLIB_LIBDIR="/usr/local/lib"
258 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
259 PWLIB_INCDIR="${PWLIBDIR}/include"
261 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
262 PWLIB_LIBDIR="${PWLIBDIR}/lib"
266 AC_SUBST([PWLIB_INCDIR])
267 AC_SUBST([PWLIB_LIBDIR])
273 [AST_CHECK_OPENH323_PLATFORM], [
276 linux*) PWLIB_OSTYPE=linux ;
278 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
280 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
281 ENDLDLIBS="-lossaudio" ;
283 netbsd* ) PWLIB_OSTYPE=NetBSD ;
284 ENDLDLIBS="-lossaudio" ;
286 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
288 darwin* ) PWLIB_OSTYPE=Darwin ;
290 beos*) PWLIB_OSTYPE=beos ;
291 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
293 cygwin*) PWLIB_OSTYPE=cygwin ;
295 mingw*) PWLIB_OSTYPE=mingw ;
296 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
297 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
299 * ) PWLIB_OSTYPE="$host_os" ;
300 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
306 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
309 x86_64) PWLIB_MACHTYPE=x86_64 ;
314 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
318 sparc ) PWLIB_MACHTYPE=sparc ;
321 powerpc ) PWLIB_MACHTYPE=ppc ;
324 ppc ) PWLIB_MACHTYPE=ppc ;
327 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
332 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
337 ia64) PWLIB_MACHTYPE=ia64 ;
341 s390x) PWLIB_MACHTYPE=s390x ;
346 s390) PWLIB_MACHTYPE=s390 ;
349 * ) PWLIB_MACHTYPE="$host_cpu";
350 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
353 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
355 AC_SUBST([PWLIB_PLATFORM])
360 [AST_CHECK_OPENH323], [
363 if test "${OPENH323DIR:-unset}" != "unset" ; then
364 AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
366 if test "${HAS_OPENH323:-unset}" = "unset" ; then
367 AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
368 if test "${HAS_OPENH323:-unset}" != "unset" ; then
369 OPENH323DIR="${PWLIBDIR}/../openh323"
370 AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
372 AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
373 if test "${HAS_OPENH323:-unset}" != "unset" ; then
374 OPENH323DIR="${HOME}/openh323"
376 AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
377 if test "${HAS_OPENH323:-unset}" != "unset" ; then
378 OPENH323DIR="/usr/local/share/openh323"
379 OPENH323_INCDIR="/usr/local/include/openh323"
380 if test "x$LIB64" != "x"; then
381 OPENH323_LIBDIR="/usr/local/lib64"
383 OPENH323_LIBDIR="/usr/local/lib"
386 AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
387 if test "${HAS_OPENH323:-unset}" != "unset" ; then
388 OPENH323DIR="/usr/share/openh323"
389 OPENH323_INCDIR="/usr/include/openh323"
390 if test "x$LIB64" != "x"; then
391 OPENH323_LIBDIR="/usr/lib64"
393 OPENH323_LIBDIR="/usr/lib"
401 if test "${HAS_OPENH323:-unset}" != "unset" ; then
402 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
403 OPENH323_INCDIR="${OPENH323DIR}/include"
405 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
406 OPENH323_LIBDIR="${OPENH323DIR}/lib"
409 AC_SUBST([OPENH323DIR])
410 AC_SUBST([OPENH323_INCDIR])
411 AC_SUBST([OPENH323_LIBDIR])
417 [AST_CHECK_PWLIB_VERSION], [
418 if test "${HAS_$2:-unset}" != "unset"; then
419 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
420 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
421 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
422 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
423 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
424 let $2_REQ=$4*10000+$5*100+$6
426 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
427 if test ${$2_VER} -lt ${$2_REQ}; then
438 [AST_CHECK_PWLIB_BUILD], [
439 if test "${HAS_$2:-unset}" != "unset"; then
440 AC_MSG_CHECKING($1 installation validity)
442 saved_cppflags="${CPPFLAGS}"
444 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
445 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
450 [AC_LANG_PROGRAM([$4],[$5])],
462 CPPFLAGS="${saved_cppflags}"
464 if test "${ac_cv_lib_$2}" = "yes"; then
465 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
466 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
468 $2_LIB="-l${PLATFORM_$2}"
470 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
471 $2_INCLUDE="-I${$2_INCDIR}"
474 AC_DEFINE([HAVE_$2], 1, [$3])
480 [AST_CHECK_OPENH323_BUILD], [
481 if test "${HAS_OPENH323:-unset}" != "unset"; then
482 AC_MSG_CHECKING(OpenH323 build option)
484 files=`ls -l ${OPENH323_LIBDIR}/libh323_${PWLIB_PLATFORM}_*.so*`
486 if test -n "$files"; then
488 if test -f $f -a ! -L $f; then
489 libfile=`basename $f`
494 if test "${libfile:-unset}" != "unset"; then
495 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/libh323_${PWLIB_PLATFORM}_\(@<:@^.@:>@*\)\..*/\1/'"`
497 case "${OPENH323_SUFFIX}" in
499 OPENH323_BUILD="notrace";;
501 OPENH323_BUILD="opt";;
503 OPENH323_BUILD="debug";;
505 OPENH323_BUILD="notrace";;
507 AC_MSG_RESULT(${OPENH323_BUILD})
509 AC_SUBST([OPENH323_SUFFIX])
510 AC_SUBST([OPENH323_BUILD])
517 AN_FUNCTION([fork], [AST_FUNC_FORK])
518 AN_FUNCTION([vfork], [AST_FUNC_FORK])
519 AC_DEFUN([AST_FUNC_FORK],
520 [AC_REQUIRE([AC_TYPE_PID_T])dnl
521 AC_CHECK_HEADERS(vfork.h)
522 AC_CHECK_FUNCS(fork vfork)
523 if test "x$ac_cv_func_fork" = xyes; then
526 ac_cv_func_fork_works=$ac_cv_func_fork
528 if test "x$ac_cv_func_fork_works" = xcross; then
530 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* )
531 # Override, as these systems have only a dummy fork() stub
532 ac_cv_func_fork_works=no
535 ac_cv_func_fork_works=yes
538 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
540 ac_cv_func_vfork_works=$ac_cv_func_vfork
541 if test "x$ac_cv_func_vfork" = xyes; then
544 if test "x$ac_cv_func_fork_works" = xcross; then
545 ac_cv_func_vfork_works=$ac_cv_func_vfork
546 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
549 if test "x$ac_cv_func_vfork_works" = xyes; then
550 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
552 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
554 if test "x$ac_cv_func_fork_works" = xyes; then
555 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
562 AC_DEFUN([_AST_FUNC_FORK],
563 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
565 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
567 /* By Ruediger Kuhlmann. */
570 [ac_cv_func_fork_works=yes],
571 [ac_cv_func_fork_works=no],
572 [ac_cv_func_fork_works=cross])])]
577 # find the pathname to the GNU or non-GNU linker
578 AC_DEFUN([AST_PROG_LD],
579 [AC_ARG_WITH([gnu-ld],
580 [AC_HELP_STRING([--with-gnu-ld],
581 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
582 [test "$withval" = no || with_gnu_ld=yes],
584 AC_REQUIRE([AST_PROG_SED])dnl
585 AC_REQUIRE([AC_PROG_CC])dnl
586 AC_REQUIRE([AC_CANONICAL_HOST])dnl
587 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
589 if test "$GCC" = yes; then
590 # Check if gcc -print-prog-name=ld gives a path.
591 AC_MSG_CHECKING([for ld used by $CC])
594 # gcc leaves a trailing carriage return which upsets mingw
595 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
597 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
600 # Accept absolute paths.
601 [[\\/]]* | ?:[[\\/]]*)
602 re_direlt='/[[^/]][[^/]]*/\.\./'
603 # Canonicalize the pathname of ld
604 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
605 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
606 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
608 test -z "$LD" && LD="$ac_prog"
611 # If it fails, then pretend we aren't using GCC.
615 # If it is relative, then search for the first ld in PATH.
619 elif test "$with_gnu_ld" = yes; then
620 AC_MSG_CHECKING([for GNU ld])
622 AC_MSG_CHECKING([for non-GNU ld])
624 AC_CACHE_VAL(lt_cv_path_LD,
625 [if test -z "$LD"; then
626 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
627 for ac_dir in $PATH; do
629 test -z "$ac_dir" && ac_dir=.
630 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
631 lt_cv_path_LD="$ac_dir/$ac_prog"
632 # Check to see if the program is GNU ld. I'd rather use --version,
633 # but apparently some variants of GNU ld only accept -v.
634 # Break only if it was the GNU/non-GNU ld that we prefer.
635 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
636 *GNU* | *'with BFD'*)
637 test "$with_gnu_ld" != no && break
640 test "$with_gnu_ld" != yes && break
647 lt_cv_path_LD="$LD" # Let the user override the test with a path.
650 if test -n "$LD"; then
655 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
662 AC_DEFUN([AST_PROG_LD_GNU],
663 [AC_REQUIRE([AST_PROG_EGREP])dnl
664 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
665 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
666 case `$LD -v 2>&1 </dev/null` in
667 *GNU* | *'with BFD'*)
668 lt_cv_prog_gnu_ld=yes
674 with_gnu_ld=$lt_cv_prog_gnu_ld
679 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
680 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
681 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
682 then ac_cv_prog_egrep='grep -E'
683 else ac_cv_prog_egrep='egrep'
685 EGREP=$ac_cv_prog_egrep
687 ])]) # AST_PROG_EGREP
691 # Check for a fully functional sed program that truncates
692 # as few characters as possible. Prefer GNU sed if found.
693 AC_DEFUN([AST_PROG_SED],
694 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
695 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
696 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
697 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
698 for ac_i in 1 2 3 4 5 6 7; do
699 ac_script="$ac_script$as_nl$ac_script"
701 echo "$ac_script" | sed 99q >conftest.sed
702 $as_unset ac_script || ac_script=
703 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
704 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
705 ["$ac_path_SED" -f conftest.sed])])])
706 SED="$ac_cv_path_SED"
711 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
713 dnl @summary figure out how to build C programs using POSIX threads
715 dnl This macro figures out how to build C programs using POSIX threads.
716 dnl It sets the PTHREAD_LIBS output variable to the threads library and
717 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
718 dnl C compiler flags that are needed. (The user can also force certain
719 dnl compiler flags/libs to be tested by setting these environment
722 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
723 dnl multi-threaded programs (defaults to the value of CC otherwise).
724 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
726 dnl NOTE: You are assumed to not only compile your program with these
727 dnl flags, but also link it with them as well. e.g. you should link
728 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
731 dnl If you are only building threads programs, you may wish to use
732 dnl these variables in your default LIBS, CFLAGS, and CC:
734 dnl LIBS="$PTHREAD_LIBS $LIBS"
735 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
738 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
739 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
740 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
742 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
743 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
744 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
745 dnl default action will define HAVE_PTHREAD.
747 dnl Please let the authors know if this macro fails on any platform, or
748 dnl if you have any other suggestions or comments. This macro was based
749 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
750 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
751 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
752 dnl We are also grateful for the helpful feedback of numerous users.
754 dnl @category InstalledPackages
755 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
756 dnl @version 2006-05-29
757 dnl @license GPLWithACException
759 AC_DEFUN([ACX_PTHREAD], [
760 AC_REQUIRE([AC_CANONICAL_HOST])
765 # We used to check for pthread.h first, but this fails if pthread.h
766 # requires special compiler flags (e.g. on True64 or Sequent).
767 # It gets checked for in the link test anyway.
769 # First of all, check if the user has set any of the PTHREAD_LIBS,
770 # etcetera environment variables, and if threads linking works using
772 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
773 save_CFLAGS="$CFLAGS"
774 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
776 LIBS="$PTHREAD_LIBS $LIBS"
777 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
778 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
779 AC_MSG_RESULT($acx_pthread_ok)
780 if test x"$acx_pthread_ok" = xno; then
785 CFLAGS="$save_CFLAGS"
788 # We must check for the threads library under a number of different
789 # names; the ordering is very important because some systems
790 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
791 # libraries is broken (non-POSIX).
793 # Create a list of thread flags to try. Items starting with a "-" are
794 # C compiler flags, and other items are library names, except for "none"
795 # which indicates that we try without any flags at all, and "pthread-config"
796 # which is a program returning the flags for the Pth emulation library.
798 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
800 # The ordering *is* (sometimes) important. Some notes on the
801 # individual items follow:
803 # pthreads: AIX (must check this before -lpthread)
804 # none: in case threads are in libc; should be tried before -Kthread and
805 # other compiler flags to prevent continual compiler warnings
806 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
807 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
808 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
809 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
810 # -pthreads: Solaris/gcc
811 # -mthreads: Mingw32/gcc, Lynx/gcc
812 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
813 # doesn't hurt to check since this sometimes defines pthreads too;
814 # also defines -D_REENTRANT)
815 # ... -mt is also the pthreads flag for HP/aCC
816 # pthread: Linux, etcetera
817 # --thread-safe: KAI C++
818 # pthread-config: use pthread-config program (for GNU Pth library)
820 case "${host_cpu}-${host_os}" in
823 # On Solaris (at least, for some versions), libc contains stubbed
824 # (non-functional) versions of the pthreads routines, so link-based
825 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
826 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
827 # a function called by this macro, so we could check for that, but
828 # who knows whether they'll stub that too in a future libc.) So,
829 # we'll just look for -pthreads and -lpthread first:
831 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
835 if test x"$acx_pthread_ok" = xno; then
836 for flag in $acx_pthread_flags; do
840 AC_MSG_CHECKING([whether pthreads work without any flags])
844 AC_MSG_CHECKING([whether pthreads work with $flag])
845 PTHREAD_CFLAGS="$flag"
849 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
850 if test x"$acx_pthread_config" = xno; then continue; fi
851 PTHREAD_CFLAGS="`pthread-config --cflags`"
852 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
856 AC_MSG_CHECKING([for the pthreads library -l$flag])
857 PTHREAD_LIBS="-l$flag"
862 save_CFLAGS="$CFLAGS"
863 LIBS="$PTHREAD_LIBS $LIBS"
864 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
866 # Check for various functions. We must include pthread.h,
867 # since some functions may be macros. (On the Sequent, we
868 # need a special flag -Kthread to make this header compile.)
869 # We check for pthread_join because it is in -lpthread on IRIX
870 # while pthread_create is in libc. We check for pthread_attr_init
871 # due to DEC craziness with -lpthreads. We check for
872 # pthread_cleanup_push because it is one of the few pthread
873 # functions on Solaris that doesn't have a non-functional libc stub.
874 # We try pthread_create on general principles.
875 AC_TRY_LINK([#include <pthread.h>],
876 [pthread_t th; pthread_join(th, 0);
877 pthread_attr_init(0); pthread_cleanup_push(0, 0);
878 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
879 [acx_pthread_ok=yes])
882 CFLAGS="$save_CFLAGS"
884 AC_MSG_RESULT($acx_pthread_ok)
885 if test "x$acx_pthread_ok" = xyes; then
894 # Various other checks:
895 if test "x$acx_pthread_ok" = xyes; then
897 LIBS="$PTHREAD_LIBS $LIBS"
898 save_CFLAGS="$CFLAGS"
899 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
901 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
902 AC_MSG_CHECKING([for joinable pthread attribute])
904 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
905 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
906 [attr_name=$attr; break])
908 AC_MSG_RESULT($attr_name)
909 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
910 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
911 [Define to necessary symbol if this constant
912 uses a non-standard name on your system.])
915 AC_MSG_CHECKING([if more special flags are required for pthreads])
917 case "${host_cpu}-${host_os}" in
918 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
919 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
921 AC_MSG_RESULT(${flag})
922 if test "x$flag" != xno; then
923 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
927 CFLAGS="$save_CFLAGS"
929 # More AIX lossage: must compile with xlc_r or cc_r
930 if test x"$GCC" != xyes; then
931 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
939 AC_SUBST(PTHREAD_LIBS)
940 AC_SUBST(PTHREAD_CFLAGS)
943 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
944 if test x"$acx_pthread_ok" = xyes; then
945 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])