1 # AST_GCC_ATTRIBUTE([attribute name])
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
5 AC_MSG_CHECKING(for compiler 'attribute $1' support)
7 CFLAGS="$CFLAGS -Werror"
9 AC_LANG_PROGRAM([static void __attribute__(($1)) *test(void *muffin, ...) {}],
12 AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
15 CFLAGS="$saved_CFLAGS"
18 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
20 AC_DEFUN([AST_EXT_LIB_SETUP],
24 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),[
40 AC_SUBST([$1_INCLUDE])
45 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data], [additional INCLUDE data])
47 AC_DEFUN([AST_EXT_LIB_CHECK],
49 if test "${USE_$1}" != "no"; then
51 if test "x${$1_DIR}" != "x"; then
52 if test -d ${$1_DIR}/lib; then
53 pbxlibdir="-L${$1_DIR}/lib"
55 pbxlibdir="-L${$1_DIR}"
58 AC_CHECK_LIB([$2], [$3], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
60 if test "${AST_$1_FOUND}" = "yes"; then
63 if test "x${$1_DIR}" != "x"; then
64 $1_LIB="${pbxlibdir} ${$1_LIB}"
65 $1_INCLUDE="-I${$1_DIR}/include"
67 $1_INCLUDE="${$1_INCLUDE} $6"
68 saved_cppflags="${CPPFLAGS}"
69 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
70 if test "x$4" != "x" ; then
71 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
73 CPPFLAGS="${saved_cppflags}"
74 if test "x${$1_HEADER_FOUND}" = "x0" ; then
75 if test -n "${$1_MANDATORY}" ;
78 AC_MSG_NOTICE([*** It appears that you do not have the $2 development package installed.])
79 AC_MSG_NOTICE([*** Please install it to include ${$1_DESCRIP} support, or re-run configure])
80 AC_MSG_NOTICE([*** without explicitly specifying --with-${$1_OPTION}])
88 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define to indicate the ${$1_DESCRIP} library])
90 elif test -n "${$1_MANDATORY}";
93 AC_MSG_NOTICE([*** The ${$1_DESCRIP} installation on this system appears to be broken.])
94 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
95 AC_MSG_NOTICE([*** without explicitly specifying --with-${$1_OPTION}])
101 # The next three functions check for the availability of a given package.
102 # AST_C_DEFINE_CHECK looks for the presence of a #define in a header file,
103 # AST_C_COMPILE_CHECK can be used for testing for various items in header files,
104 # AST_EXT_LIB_CHECK looks for a symbol in a given library, or at least
105 # for the presence of a header file.
106 # AST_EXT_TOOL_CHECK looks for a symbol in using $1-config to determine CFLAGS and LIBS
108 # They are only run if PBX_$1 != 1 (where $1 is the package),
109 # so you can call them multiple times and stop at the first matching one.
110 # On success, they both set PBX_$1 = 1, set $1_INCLUDE and $1_LIB as applicable,
111 # and also #define HAVE_$1 1 and #define HAVE_$1_VERSION ${last_argument}
112 # in autoconfig.h so you can tell which test succeeded.
113 # They should be called after AST_EXT_LIB_SETUP($1, ...)
115 # Check if a given macro is defined in a certain header.
117 # AST_C_DEFINE_CHECK([package], [macro name], [header file], [version])
118 AC_DEFUN([AST_C_DEFINE_CHECK],
120 if test "x${PBX_$1}" != "x1"; then
121 AC_MSG_CHECKING([for $2 in $3])
122 saved_cppflags="${CPPFLAGS}"
123 if test "x${$1_DIR}" != "x"; then
124 $1_INCLUDE="-I${$1_DIR}/include"
126 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
129 [ AC_LANG_PROGRAM( [#include <$3>],
139 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
140 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
142 [ AC_MSG_RESULT(no) ]
144 CPPFLAGS="${saved_cppflags}"
149 # AST_C_COMPILE_CHECK can be used for testing for various items in header files
151 # AST_C_COMPILE_CHECK([package], [expression], [header file], [version], [description])
152 AC_DEFUN([AST_C_COMPILE_CHECK],
154 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
155 if test "x$5" != "x"; then
156 AC_MSG_CHECKING([for $5])
158 AC_MSG_CHECKING([if "$2" compiles using $3])
160 saved_cppflags="${CPPFLAGS}"
161 if test "x${$1_DIR}" != "x"; then
162 $1_INCLUDE="-I${$1_DIR}/include"
164 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
167 [ AC_LANG_PROGRAM( [#include <$3>],
172 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
173 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
175 [ AC_MSG_RESULT(no) ]
177 CPPFLAGS="${saved_cppflags}"
182 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
183 GNU_MAKE='Not Found' ;
184 GNU_MAKE_VERSION_MAJOR=0 ;
185 GNU_MAKE_VERSION_MINOR=0 ;
186 for a in make gmake gnumake ; do
187 if test -z "$a" ; then continue ; fi ;
188 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
190 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
191 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
196 if test "x$GNU_MAKE" = "xNot Found" ; then
197 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
209 if test "${PWLIBDIR:-unset}" != "unset" ; then
210 AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
212 if test "${HAS_PWLIB:-unset}" = "unset" ; then
213 if test "${OPENH323DIR:-unset}" != "unset"; then
214 AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
216 if test "${HAS_PWLIB:-unset}" != "unset" ; then
217 PWLIBDIR="${OPENH323DIR}/../pwlib"
219 AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
220 if test "${HAS_PWLIB:-unset}" != "unset" ; then
221 PWLIBDIR="${HOME}/pwlib"
223 AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
224 if test "${HAS_PWLIB:-unset}" != "unset" ; then
225 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
226 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
227 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
229 PWLIB_INCDIR="/usr/local/include"
230 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
231 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
232 if test "x$LIB64" != "x"; then
233 PWLIB_LIBDIR="/usr/local/lib64"
235 PWLIB_LIBDIR="/usr/local/lib"
238 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
239 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
241 AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
242 if test "${HAS_PWLIB:-unset}" != "unset" ; then
243 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
244 PWLIB_INCDIR="/usr/include"
245 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
246 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
247 if test "x$LIB64" != "x"; then
248 PWLIB_LIBDIR="/usr/lib64"
250 PWLIB_LIBDIR="/usr/lib"
253 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
254 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
261 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
262 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
266 if test "${HAS_PWLIB:-unset}" != "unset" ; then
267 if test "${PWLIBDIR:-unset}" = "unset" ; then
268 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
269 PWLIBDIR=`$PTLIB_CONFIG --prefix`
271 echo "Cannot find ptlib-config - please install and try again"
276 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
277 PWLIBDIR="/usr/share/pwlib"
278 PWLIB_INCDIR="/usr/include"
279 if test "x$LIB64" != "x"; then
280 PWLIB_LIBDIR="/usr/lib64"
282 PWLIB_LIBDIR="/usr/lib"
285 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
286 PWLIBDIR="/usr/local/share/pwlib"
287 PWLIB_INCDIR="/usr/local/include"
288 if test "x$LIB64" != "x"; then
289 PWLIB_LIBDIR="/usr/local/lib64"
291 PWLIB_LIBDIR="/usr/local/lib"
295 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
296 PWLIB_INCDIR="${PWLIBDIR}/include"
298 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
299 PWLIB_LIBDIR="${PWLIBDIR}/lib"
303 AC_SUBST([PWLIB_INCDIR])
304 AC_SUBST([PWLIB_LIBDIR])
311 [AST_CHECK_OPENH323_PLATFORM], [
314 linux*) PWLIB_OSTYPE=linux ;
316 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
318 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
319 ENDLDLIBS="-lossaudio" ;
321 netbsd* ) PWLIB_OSTYPE=NetBSD ;
322 ENDLDLIBS="-lossaudio" ;
324 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
326 darwin* ) PWLIB_OSTYPE=Darwin ;
328 beos*) PWLIB_OSTYPE=beos ;
329 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
331 cygwin*) PWLIB_OSTYPE=cygwin ;
333 mingw*) PWLIB_OSTYPE=mingw ;
334 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
335 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
337 * ) PWLIB_OSTYPE="$host_os" ;
338 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
344 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
347 x86_64) PWLIB_MACHTYPE=x86_64 ;
352 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
356 sparc ) PWLIB_MACHTYPE=sparc ;
359 powerpc ) PWLIB_MACHTYPE=ppc ;
362 ppc ) PWLIB_MACHTYPE=ppc ;
365 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
370 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
375 ia64) PWLIB_MACHTYPE=ia64 ;
379 s390x) PWLIB_MACHTYPE=s390x ;
384 s390) PWLIB_MACHTYPE=s390 ;
387 * ) PWLIB_MACHTYPE="$host_cpu";
388 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
391 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
393 AC_SUBST([PWLIB_PLATFORM])
398 [AST_CHECK_OPENH323], [
402 if test "${OPENH323DIR:-unset}" != "unset" ; then
403 AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
405 if test "${HAS_OPENH323:-unset}" = "unset" ; then
406 AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
407 if test "${HAS_OPENH323:-unset}" != "unset" ; then
408 OPENH323DIR="${PWLIBDIR}/../openh323"
409 saved_cppflags="${CPPFLAGS}"
410 CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
411 AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
412 CPPFLAGS="${saved_cppflags}"
414 saved_cppflags="${CPPFLAGS}"
415 CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
416 AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
417 CPPFLAGS="${saved_cppflags}"
418 if test "${HAS_OPENH323:-unset}" != "unset" ; then
419 OPENH323DIR="${HOME}/openh323"
421 saved_cppflags="${CPPFLAGS}"
422 CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
423 AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
424 CPPFLAGS="${saved_cppflags}"
425 if test "${HAS_OPENH323:-unset}" != "unset" ; then
426 OPENH323DIR="/usr/local/share/openh323"
427 OPENH323_INCDIR="/usr/local/include/openh323"
428 if test "x$LIB64" != "x"; then
429 OPENH323_LIBDIR="/usr/local/lib64"
431 OPENH323_LIBDIR="/usr/local/lib"
434 saved_cppflags="${CPPFLAGS}"
435 CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
436 AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
437 CPPFLAGS="${saved_cppflags}"
438 if test "${HAS_OPENH323:-unset}" != "unset" ; then
439 OPENH323DIR="/usr/share/openh323"
440 OPENH323_INCDIR="/usr/include/openh323"
441 if test "x$LIB64" != "x"; then
442 OPENH323_LIBDIR="/usr/lib64"
444 OPENH323_LIBDIR="/usr/lib"
452 if test "${HAS_OPENH323:-unset}" != "unset" ; then
453 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
454 OPENH323_INCDIR="${OPENH323DIR}/include"
456 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
457 OPENH323_LIBDIR="${OPENH323DIR}/lib"
460 OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
461 OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
462 OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
464 AC_SUBST([OPENH323DIR])
465 AC_SUBST([OPENH323_INCDIR])
466 AC_SUBST([OPENH323_LIBDIR])
473 [AST_CHECK_PWLIB_VERSION], [
474 if test "${HAS_$2:-unset}" != "unset"; then
475 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
476 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
477 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
478 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
479 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
480 let $2_REQ=$4*10000+$5*100+$6
482 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
483 if test ${$2_VER} -lt ${$2_REQ}; then
494 [AST_CHECK_PWLIB_BUILD], [
495 if test "${HAS_$2:-unset}" != "unset"; then
496 AC_MSG_CHECKING($1 installation validity)
498 saved_cppflags="${CPPFLAGS}"
500 if test "${$2_LIB:-unset}" != "unset"; then
501 LIBS="${LIBS} ${$2_LIB} $7"
503 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
505 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
510 [AC_LANG_PROGRAM([$4],[$5])],
522 CPPFLAGS="${saved_cppflags}"
524 if test "${ac_cv_lib_$2}" = "yes"; then
525 if test "${$2_LIB:-undef}" = "undef"; then
526 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
527 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
529 $2_LIB="-l${PLATFORM_$2}"
532 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
533 $2_INCLUDE="-I${$2_INCDIR}"
536 AC_DEFINE([HAVE_$2], 1, [$3])
542 [AST_CHECK_OPENH323_BUILD], [
543 if test "${HAS_OPENH323:-unset}" != "unset"; then
544 AC_MSG_CHECKING(OpenH323 build option)
546 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
547 for pfx in $prefixes; do
548 files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
550 if test -n "$files"; then
552 if test -f $f -a ! -L $f; then
553 libfile=`basename $f`
558 if test -n "$libfile"; then
563 if test "${libfile:-unset}" != "unset"; then
564 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
566 case "${OPENH323_SUFFIX}" in
568 OPENH323_BUILD="notrace";;
570 OPENH323_BUILD="opt";;
572 OPENH323_BUILD="debug";;
574 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
575 notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@ @:>@*=@<:@ @:>@*//'"`
576 if test "x$notrace" = "x"; then
579 if test "$notrace" -ne 0; then
580 OPENH323_BUILD="notrace"
584 OPENH323_LIB="-l${OPENH323_PREFIX}"
586 OPENH323_BUILD="notrace"
590 AC_MSG_RESULT(${OPENH323_BUILD})
592 AC_SUBST([OPENH323_SUFFIX])
593 AC_SUBST([OPENH323_BUILD])
600 AN_FUNCTION([fork], [AST_FUNC_FORK])
601 AN_FUNCTION([vfork], [AST_FUNC_FORK])
602 AC_DEFUN([AST_FUNC_FORK],
603 [AC_REQUIRE([AC_TYPE_PID_T])dnl
604 AC_CHECK_HEADERS(vfork.h)
605 AC_CHECK_FUNCS(fork vfork)
606 if test "x$ac_cv_func_fork" = xyes; then
609 ac_cv_func_fork_works=$ac_cv_func_fork
611 if test "x$ac_cv_func_fork_works" = xcross; then
613 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
614 # Override, as these systems have only a dummy fork() stub
615 ac_cv_func_fork_works=no
618 ac_cv_func_fork_works=yes
621 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
623 ac_cv_func_vfork_works=$ac_cv_func_vfork
624 if test "x$ac_cv_func_vfork" = xyes; then
627 if test "x$ac_cv_func_fork_works" = xcross; then
628 ac_cv_func_vfork_works=$ac_cv_func_vfork
629 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
632 if test "x$ac_cv_func_vfork_works" = xyes; then
633 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
635 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
637 if test "x$ac_cv_func_fork_works" = xyes; then
638 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
645 AC_DEFUN([_AST_FUNC_FORK],
646 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
648 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
650 /* By Ruediger Kuhlmann. */
653 [ac_cv_func_fork_works=yes],
654 [ac_cv_func_fork_works=no],
655 [ac_cv_func_fork_works=cross])])]
660 # find the pathname to the GNU or non-GNU linker
661 AC_DEFUN([AST_PROG_LD],
662 [AC_ARG_WITH([gnu-ld],
663 [AC_HELP_STRING([--with-gnu-ld],
664 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
665 [test "$withval" = no || with_gnu_ld=yes],
667 AC_REQUIRE([AST_PROG_SED])dnl
668 AC_REQUIRE([AC_PROG_CC])dnl
669 AC_REQUIRE([AC_CANONICAL_HOST])dnl
670 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
672 if test "$GCC" = yes; then
673 # Check if gcc -print-prog-name=ld gives a path.
674 AC_MSG_CHECKING([for ld used by $CC])
677 # gcc leaves a trailing carriage return which upsets mingw
678 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
680 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
683 # Accept absolute paths.
684 [[\\/]]* | ?:[[\\/]]*)
685 re_direlt='/[[^/]][[^/]]*/\.\./'
686 # Canonicalize the pathname of ld
687 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
688 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
689 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
691 test -z "$LD" && LD="$ac_prog"
694 # If it fails, then pretend we aren't using GCC.
698 # If it is relative, then search for the first ld in PATH.
702 elif test "$with_gnu_ld" = yes; then
703 AC_MSG_CHECKING([for GNU ld])
705 AC_MSG_CHECKING([for non-GNU ld])
707 AC_CACHE_VAL(lt_cv_path_LD,
708 [if test -z "$LD"; then
709 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
710 for ac_dir in $PATH; do
712 test -z "$ac_dir" && ac_dir=.
713 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
714 lt_cv_path_LD="$ac_dir/$ac_prog"
715 # Check to see if the program is GNU ld. I'd rather use --version,
716 # but apparently some variants of GNU ld only accept -v.
717 # Break only if it was the GNU/non-GNU ld that we prefer.
718 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
719 *GNU* | *'with BFD'*)
720 test "$with_gnu_ld" != no && break
723 test "$with_gnu_ld" != yes && break
730 lt_cv_path_LD="$LD" # Let the user override the test with a path.
733 if test -n "$LD"; then
738 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
745 AC_DEFUN([AST_PROG_LD_GNU],
746 [AC_REQUIRE([AST_PROG_EGREP])dnl
747 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
748 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
749 case `$LD -v 2>&1 </dev/null` in
750 *GNU* | *'with BFD'*)
751 lt_cv_prog_gnu_ld=yes
757 with_gnu_ld=$lt_cv_prog_gnu_ld
762 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
763 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
764 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
765 then ac_cv_prog_egrep='grep -E'
766 else ac_cv_prog_egrep='egrep'
768 EGREP=$ac_cv_prog_egrep
770 ])]) # AST_PROG_EGREP
774 # Check for a fully functional sed program that truncates
775 # as few characters as possible. Prefer GNU sed if found.
776 AC_DEFUN([AST_PROG_SED],
777 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
778 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
779 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
780 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
781 for ac_i in 1 2 3 4 5 6 7; do
782 ac_script="$ac_script$as_nl$ac_script"
784 echo "$ac_script" | sed 99q >conftest.sed
785 $as_unset ac_script || ac_script=
786 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
787 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
788 ["$ac_path_SED" -f conftest.sed])])])
789 SED="$ac_cv_path_SED"
794 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
796 dnl @summary figure out how to build C programs using POSIX threads
798 dnl This macro figures out how to build C programs using POSIX threads.
799 dnl It sets the PTHREAD_LIBS output variable to the threads library and
800 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
801 dnl C compiler flags that are needed. (The user can also force certain
802 dnl compiler flags/libs to be tested by setting these environment
805 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
806 dnl multi-threaded programs (defaults to the value of CC otherwise).
807 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
809 dnl NOTE: You are assumed to not only compile your program with these
810 dnl flags, but also link it with them as well. e.g. you should link
811 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
814 dnl If you are only building threads programs, you may wish to use
815 dnl these variables in your default LIBS, CFLAGS, and CC:
817 dnl LIBS="$PTHREAD_LIBS $LIBS"
818 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
821 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
822 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
823 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
825 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
826 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
827 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
828 dnl default action will define HAVE_PTHREAD.
830 dnl Please let the authors know if this macro fails on any platform, or
831 dnl if you have any other suggestions or comments. This macro was based
832 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
833 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
834 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
835 dnl We are also grateful for the helpful feedback of numerous users.
837 dnl @category InstalledPackages
838 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
839 dnl @version 2006-05-29
840 dnl @license GPLWithACException
842 AC_DEFUN([ACX_PTHREAD], [
843 AC_REQUIRE([AC_CANONICAL_HOST])
848 # We used to check for pthread.h first, but this fails if pthread.h
849 # requires special compiler flags (e.g. on True64 or Sequent).
850 # It gets checked for in the link test anyway.
852 # First of all, check if the user has set any of the PTHREAD_LIBS,
853 # etcetera environment variables, and if threads linking works using
855 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
856 save_CFLAGS="$CFLAGS"
857 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
859 LIBS="$PTHREAD_LIBS $LIBS"
860 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
861 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
862 AC_MSG_RESULT($acx_pthread_ok)
863 if test x"$acx_pthread_ok" = xno; then
868 CFLAGS="$save_CFLAGS"
871 # We must check for the threads library under a number of different
872 # names; the ordering is very important because some systems
873 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
874 # libraries is broken (non-POSIX).
876 # Create a list of thread flags to try. Items starting with a "-" are
877 # C compiler flags, and other items are library names, except for "none"
878 # which indicates that we try without any flags at all, and "pthread-config"
879 # which is a program returning the flags for the Pth emulation library.
881 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
883 # The ordering *is* (sometimes) important. Some notes on the
884 # individual items follow:
886 # pthreads: AIX (must check this before -lpthread)
887 # none: in case threads are in libc; should be tried before -Kthread and
888 # other compiler flags to prevent continual compiler warnings
889 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
890 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
891 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
892 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
893 # -pthreads: Solaris/gcc
894 # -mthreads: Mingw32/gcc, Lynx/gcc
895 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
896 # doesn't hurt to check since this sometimes defines pthreads too;
897 # also defines -D_REENTRANT)
898 # ... -mt is also the pthreads flag for HP/aCC
899 # pthread: Linux, etcetera
900 # --thread-safe: KAI C++
901 # pthread-config: use pthread-config program (for GNU Pth library)
903 case "${host_cpu}-${host_os}" in
906 # On Solaris (at least, for some versions), libc contains stubbed
907 # (non-functional) versions of the pthreads routines, so link-based
908 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
909 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
910 # a function called by this macro, so we could check for that, but
911 # who knows whether they'll stub that too in a future libc.) So,
912 # we'll just look for -pthreads and -lpthread first:
914 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
918 if test x"$acx_pthread_ok" = xno; then
919 for flag in $acx_pthread_flags; do
923 AC_MSG_CHECKING([whether pthreads work without any flags])
927 AC_MSG_CHECKING([whether pthreads work with $flag])
928 PTHREAD_CFLAGS="$flag"
932 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
933 if test x"$acx_pthread_config" = xno; then continue; fi
934 PTHREAD_CFLAGS="`pthread-config --cflags`"
935 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
939 AC_MSG_CHECKING([for the pthreads library -l$flag])
940 PTHREAD_LIBS="-l$flag"
945 save_CFLAGS="$CFLAGS"
946 LIBS="$PTHREAD_LIBS $LIBS"
947 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
949 # Check for various functions. We must include pthread.h,
950 # since some functions may be macros. (On the Sequent, we
951 # need a special flag -Kthread to make this header compile.)
952 # We check for pthread_join because it is in -lpthread on IRIX
953 # while pthread_create is in libc. We check for pthread_attr_init
954 # due to DEC craziness with -lpthreads. We check for
955 # pthread_cleanup_push because it is one of the few pthread
956 # functions on Solaris that doesn't have a non-functional libc stub.
957 # We try pthread_create on general principles.
958 AC_TRY_LINK([#include <pthread.h>],
959 [pthread_t th; pthread_join(th, 0);
960 pthread_attr_init(0); pthread_cleanup_push(0, 0);
961 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
962 [acx_pthread_ok=yes])
965 CFLAGS="$save_CFLAGS"
967 AC_MSG_RESULT($acx_pthread_ok)
968 if test "x$acx_pthread_ok" = xyes; then
977 # Various other checks:
978 if test "x$acx_pthread_ok" = xyes; then
980 LIBS="$PTHREAD_LIBS $LIBS"
981 save_CFLAGS="$CFLAGS"
982 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
984 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
985 AC_MSG_CHECKING([for joinable pthread attribute])
987 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
988 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
989 [attr_name=$attr; break])
991 AC_MSG_RESULT($attr_name)
992 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
993 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
994 [Define to necessary symbol if this constant
995 uses a non-standard name on your system.])
998 AC_MSG_CHECKING([if more special flags are required for pthreads])
1000 case "${host_cpu}-${host_os}" in
1001 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1002 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1004 AC_MSG_RESULT(${flag})
1005 if test "x$flag" != xno; then
1006 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1010 CFLAGS="$save_CFLAGS"
1012 # More AIX lossage: must compile with xlc_r or cc_r
1013 if test x"$GCC" != xyes; then
1014 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1022 AC_SUBST(PTHREAD_LIBS)
1023 AC_SUBST(PTHREAD_CFLAGS)
1024 AC_SUBST(PTHREAD_CC)
1026 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1027 if test x"$acx_pthread_ok" = xyes; then
1028 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])