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!)
183 if test "${PWLIBDIR:-unset}" != "unset" ; then
184 AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
186 if test "${HAS_PWLIB:-unset}" = "unset" ; then
187 if test "${OPENH323DIR:-unset}" != "unset"; then
188 AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
190 if test "${HAS_PWLIB:-unset}" != "unset" ; then
191 PWLIBDIR="${OPENH323DIR}/../pwlib"
193 AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
194 if test "${HAS_PWLIB:-unset}" != "unset" ; then
195 PWLIBDIR="${HOME}/pwlib"
197 AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
198 if test "${HAS_PWLIB:-unset}" != "unset" ; then
199 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
200 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
201 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
203 PWLIB_INCDIR="/usr/local/include"
204 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
205 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
206 if test "x$LIB64" != "x"; then
207 PWLIB_LIBDIR="/usr/local/lib64"
209 PWLIB_LIBDIR="/usr/local/lib"
212 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
213 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
215 AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
216 if test "${HAS_PWLIB:-unset}" != "unset" ; then
217 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
218 PWLIB_INCDIR="/usr/include"
219 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
220 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
221 if test "x$LIB64" != "x"; then
222 PWLIB_LIBDIR="/usr/lib64"
224 PWLIB_LIBDIR="/usr/lib"
227 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
228 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
235 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
236 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
240 if test "${HAS_PWLIB:-unset}" != "unset" ; then
241 if test "${PWLIBDIR:-unset}" = "unset" ; then
242 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
243 PWLIBDIR=`$PTLIB_CONFIG --prefix`
245 echo "Cannot find ptlib-config - please install and try again"
250 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
251 PWLIBDIR="/usr/share/pwlib"
252 PWLIB_INCDIR="/usr/include"
253 if test "x$LIB64" != "x"; then
254 PWLIB_LIBDIR="/usr/lib64"
256 PWLIB_LIBDIR="/usr/lib"
259 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
260 PWLIBDIR="/usr/local/share/pwlib"
261 PWLIB_INCDIR="/usr/local/include"
262 if test "x$LIB64" != "x"; then
263 PWLIB_LIBDIR="/usr/local/lib64"
265 PWLIB_LIBDIR="/usr/local/lib"
269 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
270 PWLIB_INCDIR="${PWLIBDIR}/include"
272 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
273 PWLIB_LIBDIR="${PWLIBDIR}/lib"
277 AC_SUBST([PWLIB_INCDIR])
278 AC_SUBST([PWLIB_LIBDIR])
285 [AST_CHECK_OPENH323_PLATFORM], [
288 linux*) PWLIB_OSTYPE=linux ;
290 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
292 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
293 ENDLDLIBS="-lossaudio" ;
295 netbsd* ) PWLIB_OSTYPE=NetBSD ;
296 ENDLDLIBS="-lossaudio" ;
298 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
300 darwin* ) PWLIB_OSTYPE=Darwin ;
302 beos*) PWLIB_OSTYPE=beos ;
303 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
305 cygwin*) PWLIB_OSTYPE=cygwin ;
307 mingw*) PWLIB_OSTYPE=mingw ;
308 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
309 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
311 * ) PWLIB_OSTYPE="$host_os" ;
312 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
318 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
321 x86_64) PWLIB_MACHTYPE=x86_64 ;
326 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
330 sparc ) PWLIB_MACHTYPE=sparc ;
333 powerpc ) PWLIB_MACHTYPE=ppc ;
336 ppc ) PWLIB_MACHTYPE=ppc ;
339 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
344 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
349 ia64) PWLIB_MACHTYPE=ia64 ;
353 s390x) PWLIB_MACHTYPE=s390x ;
358 s390) PWLIB_MACHTYPE=s390 ;
361 * ) PWLIB_MACHTYPE="$host_cpu";
362 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
365 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
367 AC_SUBST([PWLIB_PLATFORM])
372 [AST_CHECK_OPENH323], [
376 if test "${OPENH323DIR:-unset}" != "unset" ; then
377 AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
379 if test "${HAS_OPENH323:-unset}" = "unset" ; then
380 AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
381 if test "${HAS_OPENH323:-unset}" != "unset" ; then
382 OPENH323DIR="${PWLIBDIR}/../openh323"
383 saved_cppflags="${CPPFLAGS}"
384 CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
385 AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
386 CPPFLAGS="${saved_cppflags}"
388 saved_cppflags="${CPPFLAGS}"
389 CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
390 AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
391 CPPFLAGS="${saved_cppflags}"
392 if test "${HAS_OPENH323:-unset}" != "unset" ; then
393 OPENH323DIR="${HOME}/openh323"
395 saved_cppflags="${CPPFLAGS}"
396 CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
397 AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
398 CPPFLAGS="${saved_cppflags}"
399 if test "${HAS_OPENH323:-unset}" != "unset" ; then
400 OPENH323DIR="/usr/local/share/openh323"
401 OPENH323_INCDIR="/usr/local/include/openh323"
402 if test "x$LIB64" != "x"; then
403 OPENH323_LIBDIR="/usr/local/lib64"
405 OPENH323_LIBDIR="/usr/local/lib"
408 saved_cppflags="${CPPFLAGS}"
409 CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
410 AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
411 CPPFLAGS="${saved_cppflags}"
412 if test "${HAS_OPENH323:-unset}" != "unset" ; then
413 OPENH323DIR="/usr/share/openh323"
414 OPENH323_INCDIR="/usr/include/openh323"
415 if test "x$LIB64" != "x"; then
416 OPENH323_LIBDIR="/usr/lib64"
418 OPENH323_LIBDIR="/usr/lib"
426 if test "${HAS_OPENH323:-unset}" != "unset" ; then
427 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
428 OPENH323_INCDIR="${OPENH323DIR}/include"
430 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
431 OPENH323_LIBDIR="${OPENH323DIR}/lib"
434 OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
435 OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
436 OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
438 AC_SUBST([OPENH323DIR])
439 AC_SUBST([OPENH323_INCDIR])
440 AC_SUBST([OPENH323_LIBDIR])
447 [AST_CHECK_PWLIB_VERSION], [
448 if test "${HAS_$2:-unset}" != "unset"; then
449 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
450 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
451 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
452 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
453 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
454 let $2_REQ=$4*10000+$5*100+$6
456 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
457 if test ${$2_VER} -lt ${$2_REQ}; then
468 [AST_CHECK_PWLIB_BUILD], [
469 if test "${HAS_$2:-unset}" != "unset"; then
470 AC_MSG_CHECKING($1 installation validity)
472 saved_cppflags="${CPPFLAGS}"
474 if test "${$2_LIB:-unset}" != "unset"; then
475 LIBS="${LIBS} ${$2_LIB} $7"
477 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
479 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
484 [AC_LANG_PROGRAM([$4],[$5])],
496 CPPFLAGS="${saved_cppflags}"
498 if test "${ac_cv_lib_$2}" = "yes"; then
499 if test "${$2_LIB:-undef}" = "undef"; then
500 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
501 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
503 $2_LIB="-l${PLATFORM_$2}"
506 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
507 $2_INCLUDE="-I${$2_INCDIR}"
510 AC_DEFINE([HAVE_$2], 1, [$3])
516 [AST_CHECK_OPENH323_BUILD], [
517 if test "${HAS_OPENH323:-unset}" != "unset"; then
518 AC_MSG_CHECKING(OpenH323 build option)
520 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
521 for pfx in $prefixes; do
522 files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
524 if test -n "$files"; then
526 if test -f $f -a ! -L $f; then
527 libfile=`basename $f`
532 if test -n "$libfile"; then
537 if test "${libfile:-unset}" != "unset"; then
538 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
540 case "${OPENH323_SUFFIX}" in
542 OPENH323_BUILD="notrace";;
544 OPENH323_BUILD="opt";;
546 OPENH323_BUILD="debug";;
548 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
549 notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@ @:>@*=@<:@ @:>@*//'"`
550 if test "x$notrace" = "x"; then
553 if test "$notrace" -ne 0; then
554 OPENH323_BUILD="notrace"
558 OPENH323_LIB="-l${OPENH323_PREFIX}"
560 OPENH323_BUILD="notrace"
564 AC_MSG_RESULT(${OPENH323_BUILD})
566 AC_SUBST([OPENH323_SUFFIX])
567 AC_SUBST([OPENH323_BUILD])
574 AN_FUNCTION([fork], [AST_FUNC_FORK])
575 AN_FUNCTION([vfork], [AST_FUNC_FORK])
576 AC_DEFUN([AST_FUNC_FORK],
577 [AC_REQUIRE([AC_TYPE_PID_T])dnl
578 AC_CHECK_HEADERS(vfork.h)
579 AC_CHECK_FUNCS(fork vfork)
580 if test "x$ac_cv_func_fork" = xyes; then
583 ac_cv_func_fork_works=$ac_cv_func_fork
585 if test "x$ac_cv_func_fork_works" = xcross; then
587 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
588 # Override, as these systems have only a dummy fork() stub
589 ac_cv_func_fork_works=no
592 ac_cv_func_fork_works=yes
595 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
597 ac_cv_func_vfork_works=$ac_cv_func_vfork
598 if test "x$ac_cv_func_vfork" = xyes; then
601 if test "x$ac_cv_func_fork_works" = xcross; then
602 ac_cv_func_vfork_works=$ac_cv_func_vfork
603 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
606 if test "x$ac_cv_func_vfork_works" = xyes; then
607 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
609 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
611 if test "x$ac_cv_func_fork_works" = xyes; then
612 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
619 AC_DEFUN([_AST_FUNC_FORK],
620 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
622 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
624 /* By Ruediger Kuhlmann. */
627 [ac_cv_func_fork_works=yes],
628 [ac_cv_func_fork_works=no],
629 [ac_cv_func_fork_works=cross])])]
634 # find the pathname to the GNU or non-GNU linker
635 AC_DEFUN([AST_PROG_LD],
636 [AC_ARG_WITH([gnu-ld],
637 [AC_HELP_STRING([--with-gnu-ld],
638 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
639 [test "$withval" = no || with_gnu_ld=yes],
641 AC_REQUIRE([AST_PROG_SED])dnl
642 AC_REQUIRE([AC_PROG_CC])dnl
643 AC_REQUIRE([AC_CANONICAL_HOST])dnl
644 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
646 if test "$GCC" = yes; then
647 # Check if gcc -print-prog-name=ld gives a path.
648 AC_MSG_CHECKING([for ld used by $CC])
651 # gcc leaves a trailing carriage return which upsets mingw
652 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
654 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
657 # Accept absolute paths.
658 [[\\/]]* | ?:[[\\/]]*)
659 re_direlt='/[[^/]][[^/]]*/\.\./'
660 # Canonicalize the pathname of ld
661 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
662 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
663 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
665 test -z "$LD" && LD="$ac_prog"
668 # If it fails, then pretend we aren't using GCC.
672 # If it is relative, then search for the first ld in PATH.
676 elif test "$with_gnu_ld" = yes; then
677 AC_MSG_CHECKING([for GNU ld])
679 AC_MSG_CHECKING([for non-GNU ld])
681 AC_CACHE_VAL(lt_cv_path_LD,
682 [if test -z "$LD"; then
683 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
684 for ac_dir in $PATH; do
686 test -z "$ac_dir" && ac_dir=.
687 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
688 lt_cv_path_LD="$ac_dir/$ac_prog"
689 # Check to see if the program is GNU ld. I'd rather use --version,
690 # but apparently some variants of GNU ld only accept -v.
691 # Break only if it was the GNU/non-GNU ld that we prefer.
692 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
693 *GNU* | *'with BFD'*)
694 test "$with_gnu_ld" != no && break
697 test "$with_gnu_ld" != yes && break
704 lt_cv_path_LD="$LD" # Let the user override the test with a path.
707 if test -n "$LD"; then
712 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
719 AC_DEFUN([AST_PROG_LD_GNU],
720 [AC_REQUIRE([AST_PROG_EGREP])dnl
721 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
722 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
723 case `$LD -v 2>&1 </dev/null` in
724 *GNU* | *'with BFD'*)
725 lt_cv_prog_gnu_ld=yes
731 with_gnu_ld=$lt_cv_prog_gnu_ld
736 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
737 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
738 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
739 then ac_cv_prog_egrep='grep -E'
740 else ac_cv_prog_egrep='egrep'
742 EGREP=$ac_cv_prog_egrep
744 ])]) # AST_PROG_EGREP
748 # Check for a fully functional sed program that truncates
749 # as few characters as possible. Prefer GNU sed if found.
750 AC_DEFUN([AST_PROG_SED],
751 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
752 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
753 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
754 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
755 for ac_i in 1 2 3 4 5 6 7; do
756 ac_script="$ac_script$as_nl$ac_script"
758 echo "$ac_script" | sed 99q >conftest.sed
759 $as_unset ac_script || ac_script=
760 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
761 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
762 ["$ac_path_SED" -f conftest.sed])])])
763 SED="$ac_cv_path_SED"
768 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
770 dnl @summary figure out how to build C programs using POSIX threads
772 dnl This macro figures out how to build C programs using POSIX threads.
773 dnl It sets the PTHREAD_LIBS output variable to the threads library and
774 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
775 dnl C compiler flags that are needed. (The user can also force certain
776 dnl compiler flags/libs to be tested by setting these environment
779 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
780 dnl multi-threaded programs (defaults to the value of CC otherwise).
781 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
783 dnl NOTE: You are assumed to not only compile your program with these
784 dnl flags, but also link it with them as well. e.g. you should link
785 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
788 dnl If you are only building threads programs, you may wish to use
789 dnl these variables in your default LIBS, CFLAGS, and CC:
791 dnl LIBS="$PTHREAD_LIBS $LIBS"
792 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
795 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
796 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
797 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
799 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
800 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
801 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
802 dnl default action will define HAVE_PTHREAD.
804 dnl Please let the authors know if this macro fails on any platform, or
805 dnl if you have any other suggestions or comments. This macro was based
806 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
807 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
808 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
809 dnl We are also grateful for the helpful feedback of numerous users.
811 dnl @category InstalledPackages
812 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
813 dnl @version 2006-05-29
814 dnl @license GPLWithACException
816 AC_DEFUN([ACX_PTHREAD], [
817 AC_REQUIRE([AC_CANONICAL_HOST])
822 # We used to check for pthread.h first, but this fails if pthread.h
823 # requires special compiler flags (e.g. on True64 or Sequent).
824 # It gets checked for in the link test anyway.
826 # First of all, check if the user has set any of the PTHREAD_LIBS,
827 # etcetera environment variables, and if threads linking works using
829 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
830 save_CFLAGS="$CFLAGS"
831 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
833 LIBS="$PTHREAD_LIBS $LIBS"
834 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
835 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
836 AC_MSG_RESULT($acx_pthread_ok)
837 if test x"$acx_pthread_ok" = xno; then
842 CFLAGS="$save_CFLAGS"
845 # We must check for the threads library under a number of different
846 # names; the ordering is very important because some systems
847 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
848 # libraries is broken (non-POSIX).
850 # Create a list of thread flags to try. Items starting with a "-" are
851 # C compiler flags, and other items are library names, except for "none"
852 # which indicates that we try without any flags at all, and "pthread-config"
853 # which is a program returning the flags for the Pth emulation library.
855 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
857 # The ordering *is* (sometimes) important. Some notes on the
858 # individual items follow:
860 # pthreads: AIX (must check this before -lpthread)
861 # none: in case threads are in libc; should be tried before -Kthread and
862 # other compiler flags to prevent continual compiler warnings
863 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
864 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
865 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
866 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
867 # -pthreads: Solaris/gcc
868 # -mthreads: Mingw32/gcc, Lynx/gcc
869 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
870 # doesn't hurt to check since this sometimes defines pthreads too;
871 # also defines -D_REENTRANT)
872 # ... -mt is also the pthreads flag for HP/aCC
873 # pthread: Linux, etcetera
874 # --thread-safe: KAI C++
875 # pthread-config: use pthread-config program (for GNU Pth library)
877 case "${host_cpu}-${host_os}" in
880 # On Solaris (at least, for some versions), libc contains stubbed
881 # (non-functional) versions of the pthreads routines, so link-based
882 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
883 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
884 # a function called by this macro, so we could check for that, but
885 # who knows whether they'll stub that too in a future libc.) So,
886 # we'll just look for -pthreads and -lpthread first:
888 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
892 if test x"$acx_pthread_ok" = xno; then
893 for flag in $acx_pthread_flags; do
897 AC_MSG_CHECKING([whether pthreads work without any flags])
901 AC_MSG_CHECKING([whether pthreads work with $flag])
902 PTHREAD_CFLAGS="$flag"
906 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
907 if test x"$acx_pthread_config" = xno; then continue; fi
908 PTHREAD_CFLAGS="`pthread-config --cflags`"
909 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
913 AC_MSG_CHECKING([for the pthreads library -l$flag])
914 PTHREAD_LIBS="-l$flag"
919 save_CFLAGS="$CFLAGS"
920 LIBS="$PTHREAD_LIBS $LIBS"
921 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
923 # Check for various functions. We must include pthread.h,
924 # since some functions may be macros. (On the Sequent, we
925 # need a special flag -Kthread to make this header compile.)
926 # We check for pthread_join because it is in -lpthread on IRIX
927 # while pthread_create is in libc. We check for pthread_attr_init
928 # due to DEC craziness with -lpthreads. We check for
929 # pthread_cleanup_push because it is one of the few pthread
930 # functions on Solaris that doesn't have a non-functional libc stub.
931 # We try pthread_create on general principles.
932 AC_TRY_LINK([#include <pthread.h>],
933 [pthread_t th; pthread_join(th, 0);
934 pthread_attr_init(0); pthread_cleanup_push(0, 0);
935 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
936 [acx_pthread_ok=yes])
939 CFLAGS="$save_CFLAGS"
941 AC_MSG_RESULT($acx_pthread_ok)
942 if test "x$acx_pthread_ok" = xyes; then
951 # Various other checks:
952 if test "x$acx_pthread_ok" = xyes; then
954 LIBS="$PTHREAD_LIBS $LIBS"
955 save_CFLAGS="$CFLAGS"
956 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
958 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
959 AC_MSG_CHECKING([for joinable pthread attribute])
961 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
962 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
963 [attr_name=$attr; break])
965 AC_MSG_RESULT($attr_name)
966 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
967 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
968 [Define to necessary symbol if this constant
969 uses a non-standard name on your system.])
972 AC_MSG_CHECKING([if more special flags are required for pthreads])
974 case "${host_cpu}-${host_os}" in
975 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
976 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
978 AC_MSG_RESULT(${flag})
979 if test "x$flag" != xno; then
980 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
984 CFLAGS="$save_CFLAGS"
986 # More AIX lossage: must compile with xlc_r or cc_r
987 if test x"$GCC" != xyes; then
988 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
996 AC_SUBST(PTHREAD_LIBS)
997 AC_SUBST(PTHREAD_CFLAGS)
1000 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1001 if test x"$acx_pthread_ok" = xyes; then
1002 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])