1 # Various support functions for configure.ac in asterisk
4 # Helper function to check for gcc attributes.
5 # AST_GCC_ATTRIBUTE([attribute name])
7 AC_DEFUN([AST_GCC_ATTRIBUTE],
9 AC_MSG_CHECKING(for compiler 'attribute $1' support)
10 saved_CFLAGS="$CFLAGS"
11 CFLAGS="$CFLAGS -Werror"
13 AC_LANG_PROGRAM([static void __attribute__(($1)) *test(void *muffin, ...) {}],
16 AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
19 CFLAGS="$saved_CFLAGS"
22 # Helper function to setup variables for a package.
23 # $1 -> the package name. Used in configure.ac and also as a prefix
24 # for the variables ($1_DIR, $1_INCLUDE, $1_LIB) in makeopts
25 # $3 -> option name, used in --with-$3 or --without-$3 when calling configure.
26 # $2 and $4 are just text describing the package (short and long form)
28 # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
30 AC_DEFUN([AST_EXT_LIB_SETUP],
34 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),
41 ac_mandatory_list="${ac_mandatory_list} $1"
45 ac_mandatory_list="${ac_mandatory_list} $1"
51 AC_SUBST([$1_INCLUDE])
56 # Check whether any of the mandatory modules are not present, and
57 # print error messages in case. The mandatory list is built using
58 # --with-* arguments when invoking configure.
60 AC_DEFUN([AST_CHECK_MANDATORY],
62 AC_MSG_CHECKING([for mandatory modules: ${ac_mandatory_list}])
64 for i in ${ac_mandatory_list}; do
66 if test "x${a}" = "x1" ; then continue; fi
67 if test ${err} = "0" ; then AC_MSG_RESULT(fail) ; fi
69 eval "a=\${${i}_OPTION}"
71 AC_MSG_NOTICE([*** The $i installation appears to be missing or broken.])
72 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
73 AC_MSG_NOTICE([*** including --without-${a}.])
76 if test $err = 1 ; then exit 1; fi
80 # The next three functions check for the availability of a given package.
81 # AST_C_DEFINE_CHECK looks for the presence of a #define in a header file,
82 # AST_C_COMPILE_CHECK can be used for testing for various items in header files,
83 # AST_EXT_LIB_CHECK looks for a symbol in a given library, or at least
84 # for the presence of a header file.
85 # AST_EXT_TOOL_CHECK looks for a symbol in using $1-config to determine CFLAGS and LIBS
87 # They are only run if PBX_$1 != 1 (where $1 is the package),
88 # so you can call them multiple times and stop at the first matching one.
89 # On success, they both set PBX_$1 = 1, set $1_INCLUDE and $1_LIB as applicable,
90 # and also #define HAVE_$1 1 and #define HAVE_$1_VERSION ${last_argument}
91 # in autoconfig.h so you can tell which test succeeded.
92 # They should be called after AST_EXT_LIB_SETUP($1, ...)
94 # Check if a given macro is defined in a certain header.
96 # AST_C_DEFINE_CHECK([package], [macro name], [header file], [version])
97 AC_DEFUN([AST_C_DEFINE_CHECK],
99 if test "x${PBX_$1}" != "x1"; then
100 AC_MSG_CHECKING([for $2 in $3])
101 saved_cppflags="${CPPFLAGS}"
102 if test "x${$1_DIR}" != "x"; then
103 $1_INCLUDE="-I${$1_DIR}/include"
105 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
108 [ AC_LANG_PROGRAM( [#include <$3>],
118 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
119 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
121 [ AC_MSG_RESULT(no) ]
123 CPPFLAGS="${saved_cppflags}"
129 # Check if a given expression will compile using a certain header.
131 # AST_C_COMPILE_CHECK([package], [expression], [header file], [version])
132 AC_DEFUN([AST_C_COMPILE_CHECK],
134 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
135 AC_MSG_CHECKING([if "$2" compiles using $3])
136 saved_cppflags="${CPPFLAGS}"
137 if test "x${$1_DIR}" != "x"; then
138 $1_INCLUDE="-I${$1_DIR}/include"
140 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
143 [ AC_LANG_PROGRAM( [#include <$3>],
148 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
149 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
151 [ AC_MSG_RESULT(no) ]
153 CPPFLAGS="${saved_cppflags}"
158 # Check for existence of a given package ($1), either looking up a function
159 # in a library, or, if no function is supplied, only check for the
160 # existence of the header files.
162 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
163 # [extra libs], [extra cflags], [version])
164 AC_DEFUN([AST_EXT_LIB_CHECK],
166 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
168 # if --with-$1=DIR has been specified, use it.
169 if test "x${$1_DIR}" != "x"; then
170 if test -d ${$1_DIR}/lib; then
171 pbxlibdir="-L${$1_DIR}/lib"
173 pbxlibdir="-L${$1_DIR}"
177 if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
180 AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
183 # now check for the header.
184 if test "${AST_$1_FOUND}" = "yes"; then
185 $1_LIB="${pbxlibdir} -l$2 $5"
186 # if --with-$1=DIR has been specified, use it.
187 if test "x${$1_DIR}" != "x"; then
188 $1_INCLUDE="-I${$1_DIR}/include"
190 $1_INCLUDE="${$1_INCLUDE} $6"
191 if test "x$4" = "x" ; then # no header, assume found
193 else # check for the header
194 saved_cppflags="${CPPFLAGS}"
195 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
196 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
197 CPPFLAGS="${saved_cppflags}"
199 if test "x${$1_HEADER_FOUND}" = "x0" ; then
203 if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
207 # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
208 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
209 AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the ${$1_DESCRIP} library version])
216 # Check for a package using $2-config. Similar to AST_EXT_LIB_CHECK,
217 # but use $2-config to determine cflags and libraries to use.
218 # $3 and $4 can be used to replace --cflags and --libs in the request
220 # AST_EXT_TOOL_CHECK([package], [tool name], [--cflags], [--libs], [includes], [expression])
221 AC_DEFUN([AST_EXT_TOOL_CHECK],
223 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
225 AC_CHECK_TOOL(CONFIG_$1, $2-config, No)
226 if test ! "x${CONFIG_$1}" = xNo; then
227 if test x"$3" = x ; then A=--cflags ; else A="$3" ; fi
228 $1_INCLUDE=$(${CONFIG_$1} $A)
229 if test x"$4" = x ; then A=--libs ; else A="$4" ; fi
230 $1_LIB=$(${CONFIG_$1} $A)
231 if test x"$5" != x ; then
232 saved_cppflags="${CPPFLAGS}"
233 if test "x${$1_DIR}" != "x"; then
234 $1_INCLUDE="-I${$1_DIR}/include"
236 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
238 saved_ldflags="${LDFLAGS}"
242 [ AC_LANG_PROGRAM( [ $5 ],
246 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
250 CPPFLAGS="${saved_cppflags}"
251 LDFLAGS="${saved_ldflags}"
254 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
261 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
262 GNU_MAKE='Not Found' ;
263 GNU_MAKE_VERSION_MAJOR=0 ;
264 GNU_MAKE_VERSION_MINOR=0 ;
265 for a in make gmake gnumake ; do
266 if test -z "$a" ; then continue ; fi ;
267 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
269 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
270 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
275 if test "x$GNU_MAKE" = "xNot Found" ; then
276 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
288 if test "${PWLIBDIR:-unset}" != "unset" ; then
289 AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
291 if test "${HAS_PWLIB:-unset}" = "unset" ; then
292 if test "${OPENH323DIR:-unset}" != "unset"; then
293 AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
295 if test "${HAS_PWLIB:-unset}" != "unset" ; then
296 PWLIBDIR="${OPENH323DIR}/../pwlib"
298 AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
299 if test "${HAS_PWLIB:-unset}" != "unset" ; then
300 PWLIBDIR="${HOME}/pwlib"
302 AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
303 if test "${HAS_PWLIB:-unset}" != "unset" ; then
304 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
305 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
306 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
308 PWLIB_INCDIR="/usr/local/include"
309 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
310 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
311 if test "x$LIB64" != "x"; then
312 PWLIB_LIBDIR="/usr/local/lib64"
314 PWLIB_LIBDIR="/usr/local/lib"
317 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
318 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
320 AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
321 if test "${HAS_PWLIB:-unset}" != "unset" ; then
322 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
323 PWLIB_INCDIR="/usr/include"
324 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
325 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
326 if test "x$LIB64" != "x"; then
327 PWLIB_LIBDIR="/usr/lib64"
329 PWLIB_LIBDIR="/usr/lib"
332 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
333 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
340 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
341 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
345 if test "${HAS_PWLIB:-unset}" != "unset" ; then
346 if test "${PWLIBDIR:-unset}" = "unset" ; then
347 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
348 PWLIBDIR=`$PTLIB_CONFIG --prefix`
350 echo "Cannot find ptlib-config - please install and try again"
355 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
356 PWLIBDIR="/usr/share/pwlib"
357 PWLIB_INCDIR="/usr/include"
358 if test "x$LIB64" != "x"; then
359 PWLIB_LIBDIR="/usr/lib64"
361 PWLIB_LIBDIR="/usr/lib"
364 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
365 PWLIBDIR="/usr/local/share/pwlib"
366 PWLIB_INCDIR="/usr/local/include"
367 if test "x$LIB64" != "x"; then
368 PWLIB_LIBDIR="/usr/local/lib64"
370 PWLIB_LIBDIR="/usr/local/lib"
374 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
375 PWLIB_INCDIR="${PWLIBDIR}/include"
377 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
378 PWLIB_LIBDIR="${PWLIBDIR}/lib"
382 AC_SUBST([PWLIB_INCDIR])
383 AC_SUBST([PWLIB_LIBDIR])
390 [AST_CHECK_OPENH323_PLATFORM], [
393 linux*) PWLIB_OSTYPE=linux ;
395 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
397 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
398 ENDLDLIBS="-lossaudio" ;
400 netbsd* ) PWLIB_OSTYPE=NetBSD ;
401 ENDLDLIBS="-lossaudio" ;
403 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
405 darwin* ) PWLIB_OSTYPE=Darwin ;
407 beos*) PWLIB_OSTYPE=beos ;
408 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
410 cygwin*) PWLIB_OSTYPE=cygwin ;
412 mingw*) PWLIB_OSTYPE=mingw ;
413 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
414 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
416 * ) PWLIB_OSTYPE="$host_os" ;
417 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
423 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
426 x86_64) PWLIB_MACHTYPE=x86_64 ;
431 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
435 sparc ) PWLIB_MACHTYPE=sparc ;
438 powerpc ) PWLIB_MACHTYPE=ppc ;
441 ppc ) PWLIB_MACHTYPE=ppc ;
444 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
449 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
454 ia64) PWLIB_MACHTYPE=ia64 ;
458 s390x) PWLIB_MACHTYPE=s390x ;
463 s390) PWLIB_MACHTYPE=s390 ;
466 * ) PWLIB_MACHTYPE="$host_cpu";
467 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
470 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
472 AC_SUBST([PWLIB_PLATFORM])
477 [AST_CHECK_OPENH323], [
481 if test "${OPENH323DIR:-unset}" != "unset" ; then
482 AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
484 if test "${HAS_OPENH323:-unset}" = "unset" ; then
485 AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
486 if test "${HAS_OPENH323:-unset}" != "unset" ; then
487 OPENH323DIR="${PWLIBDIR}/../openh323"
488 saved_cppflags="${CPPFLAGS}"
489 CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
490 AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
491 CPPFLAGS="${saved_cppflags}"
493 saved_cppflags="${CPPFLAGS}"
494 CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
495 AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
496 CPPFLAGS="${saved_cppflags}"
497 if test "${HAS_OPENH323:-unset}" != "unset" ; then
498 OPENH323DIR="${HOME}/openh323"
500 saved_cppflags="${CPPFLAGS}"
501 CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
502 AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
503 CPPFLAGS="${saved_cppflags}"
504 if test "${HAS_OPENH323:-unset}" != "unset" ; then
505 OPENH323DIR="/usr/local/share/openh323"
506 OPENH323_INCDIR="/usr/local/include/openh323"
507 if test "x$LIB64" != "x"; then
508 OPENH323_LIBDIR="/usr/local/lib64"
510 OPENH323_LIBDIR="/usr/local/lib"
513 saved_cppflags="${CPPFLAGS}"
514 CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
515 AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
516 CPPFLAGS="${saved_cppflags}"
517 if test "${HAS_OPENH323:-unset}" != "unset" ; then
518 OPENH323DIR="/usr/share/openh323"
519 OPENH323_INCDIR="/usr/include/openh323"
520 if test "x$LIB64" != "x"; then
521 OPENH323_LIBDIR="/usr/lib64"
523 OPENH323_LIBDIR="/usr/lib"
531 if test "${HAS_OPENH323:-unset}" != "unset" ; then
532 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
533 OPENH323_INCDIR="${OPENH323DIR}/include"
535 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
536 OPENH323_LIBDIR="${OPENH323DIR}/lib"
539 OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
540 OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
541 OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
543 AC_SUBST([OPENH323DIR])
544 AC_SUBST([OPENH323_INCDIR])
545 AC_SUBST([OPENH323_LIBDIR])
552 [AST_CHECK_PWLIB_VERSION], [
553 if test "${HAS_$2:-unset}" != "unset"; then
554 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
555 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
556 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
557 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
558 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
559 let $2_REQ=$4*10000+$5*100+$6
561 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
562 if test ${$2_VER} -lt ${$2_REQ}; then
573 [AST_CHECK_PWLIB_BUILD], [
574 if test "${HAS_$2:-unset}" != "unset"; then
575 AC_MSG_CHECKING($1 installation validity)
577 saved_cppflags="${CPPFLAGS}"
579 if test "${$2_LIB:-unset}" != "unset"; then
580 LIBS="${LIBS} ${$2_LIB} $7"
582 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
584 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
589 [AC_LANG_PROGRAM([$4],[$5])],
601 CPPFLAGS="${saved_cppflags}"
603 if test "${ac_cv_lib_$2}" = "yes"; then
604 if test "${$2_LIB:-undef}" = "undef"; then
605 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
606 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
608 $2_LIB="-l${PLATFORM_$2}"
611 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
612 $2_INCLUDE="-I${$2_INCDIR}"
615 AC_DEFINE([HAVE_$2], 1, [$3])
621 [AST_CHECK_OPENH323_BUILD], [
622 if test "${HAS_OPENH323:-unset}" != "unset"; then
623 AC_MSG_CHECKING(OpenH323 build option)
625 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
626 for pfx in $prefixes; do
627 files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
629 if test -n "$files"; then
631 if test -f $f -a ! -L $f; then
632 libfile=`basename $f`
637 if test -n "$libfile"; then
642 if test "${libfile:-unset}" != "unset"; then
643 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
645 case "${OPENH323_SUFFIX}" in
647 OPENH323_BUILD="notrace";;
649 OPENH323_BUILD="opt";;
651 OPENH323_BUILD="debug";;
653 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
654 notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@ @:>@*=@<:@ @:>@*//'"`
655 if test "x$notrace" = "x"; then
658 if test "$notrace" -ne 0; then
659 OPENH323_BUILD="notrace"
663 OPENH323_LIB="-l${OPENH323_PREFIX}"
665 OPENH323_BUILD="notrace"
669 AC_MSG_RESULT(${OPENH323_BUILD})
671 AC_SUBST([OPENH323_SUFFIX])
672 AC_SUBST([OPENH323_BUILD])
679 AN_FUNCTION([fork], [AST_FUNC_FORK])
680 AN_FUNCTION([vfork], [AST_FUNC_FORK])
681 AC_DEFUN([AST_FUNC_FORK],
682 [AC_REQUIRE([AC_TYPE_PID_T])dnl
683 AC_CHECK_HEADERS(vfork.h)
684 AC_CHECK_FUNCS(fork vfork)
685 if test "x$ac_cv_func_fork" = xyes; then
688 ac_cv_func_fork_works=$ac_cv_func_fork
690 if test "x$ac_cv_func_fork_works" = xcross; then
692 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
693 # Override, as these systems have only a dummy fork() stub
694 ac_cv_func_fork_works=no
697 ac_cv_func_fork_works=yes
700 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
702 ac_cv_func_vfork_works=$ac_cv_func_vfork
703 if test "x$ac_cv_func_vfork" = xyes; then
706 if test "x$ac_cv_func_fork_works" = xcross; then
707 ac_cv_func_vfork_works=$ac_cv_func_vfork
708 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
711 if test "x$ac_cv_func_vfork_works" = xyes; then
712 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
714 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
716 if test "x$ac_cv_func_fork_works" = xyes; then
717 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
724 AC_DEFUN([_AST_FUNC_FORK],
725 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
727 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
729 /* By Ruediger Kuhlmann. */
732 [ac_cv_func_fork_works=yes],
733 [ac_cv_func_fork_works=no],
734 [ac_cv_func_fork_works=cross])])]
739 # find the pathname to the GNU or non-GNU linker
740 AC_DEFUN([AST_PROG_LD],
741 [AC_ARG_WITH([gnu-ld],
742 [AC_HELP_STRING([--with-gnu-ld],
743 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
744 [test "$withval" = no || with_gnu_ld=yes],
746 AC_REQUIRE([AST_PROG_SED])dnl
747 AC_REQUIRE([AC_PROG_CC])dnl
748 AC_REQUIRE([AC_CANONICAL_HOST])dnl
749 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
751 if test "$GCC" = yes; then
752 # Check if gcc -print-prog-name=ld gives a path.
753 AC_MSG_CHECKING([for ld used by $CC])
756 # gcc leaves a trailing carriage return which upsets mingw
757 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
759 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
762 # Accept absolute paths.
763 [[\\/]]* | ?:[[\\/]]*)
764 re_direlt='/[[^/]][[^/]]*/\.\./'
765 # Canonicalize the pathname of ld
766 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
767 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
768 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
770 test -z "$LD" && LD="$ac_prog"
773 # If it fails, then pretend we aren't using GCC.
777 # If it is relative, then search for the first ld in PATH.
781 elif test "$with_gnu_ld" = yes; then
782 AC_MSG_CHECKING([for GNU ld])
784 AC_MSG_CHECKING([for non-GNU ld])
786 AC_CACHE_VAL(lt_cv_path_LD,
787 [if test -z "$LD"; then
788 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
789 for ac_dir in $PATH; do
791 test -z "$ac_dir" && ac_dir=.
792 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
793 lt_cv_path_LD="$ac_dir/$ac_prog"
794 # Check to see if the program is GNU ld. I'd rather use --version,
795 # but apparently some variants of GNU ld only accept -v.
796 # Break only if it was the GNU/non-GNU ld that we prefer.
797 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
798 *GNU* | *'with BFD'*)
799 test "$with_gnu_ld" != no && break
802 test "$with_gnu_ld" != yes && break
809 lt_cv_path_LD="$LD" # Let the user override the test with a path.
812 if test -n "$LD"; then
817 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
824 AC_DEFUN([AST_PROG_LD_GNU],
825 [AC_REQUIRE([AST_PROG_EGREP])dnl
826 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
827 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
828 case `$LD -v 2>&1 </dev/null` in
829 *GNU* | *'with BFD'*)
830 lt_cv_prog_gnu_ld=yes
836 with_gnu_ld=$lt_cv_prog_gnu_ld
841 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
842 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
843 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
844 then ac_cv_prog_egrep='grep -E'
845 else ac_cv_prog_egrep='egrep'
847 EGREP=$ac_cv_prog_egrep
849 ])]) # AST_PROG_EGREP
853 # Check for a fully functional sed program that truncates
854 # as few characters as possible. Prefer GNU sed if found.
855 AC_DEFUN([AST_PROG_SED],
856 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
857 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
858 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
859 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
860 for ac_i in 1 2 3 4 5 6 7; do
861 ac_script="$ac_script$as_nl$ac_script"
863 echo "$ac_script" | sed 99q >conftest.sed
864 $as_unset ac_script || ac_script=
865 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
866 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
867 ["$ac_path_SED" -f conftest.sed])])])
868 SED="$ac_cv_path_SED"
873 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
875 dnl @summary figure out how to build C programs using POSIX threads
877 dnl This macro figures out how to build C programs using POSIX threads.
878 dnl It sets the PTHREAD_LIBS output variable to the threads library and
879 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
880 dnl C compiler flags that are needed. (The user can also force certain
881 dnl compiler flags/libs to be tested by setting these environment
884 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
885 dnl multi-threaded programs (defaults to the value of CC otherwise).
886 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
888 dnl NOTE: You are assumed to not only compile your program with these
889 dnl flags, but also link it with them as well. e.g. you should link
890 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
893 dnl If you are only building threads programs, you may wish to use
894 dnl these variables in your default LIBS, CFLAGS, and CC:
896 dnl LIBS="$PTHREAD_LIBS $LIBS"
897 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
900 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
901 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
902 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
904 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
905 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
906 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
907 dnl default action will define HAVE_PTHREAD.
909 dnl Please let the authors know if this macro fails on any platform, or
910 dnl if you have any other suggestions or comments. This macro was based
911 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
912 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
913 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
914 dnl We are also grateful for the helpful feedback of numerous users.
916 dnl @category InstalledPackages
917 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
918 dnl @version 2006-05-29
919 dnl @license GPLWithACException
921 AC_DEFUN([ACX_PTHREAD],
923 AC_REQUIRE([AC_CANONICAL_HOST])
928 # We used to check for pthread.h first, but this fails if pthread.h
929 # requires special compiler flags (e.g. on True64 or Sequent).
930 # It gets checked for in the link test anyway.
932 # First of all, check if the user has set any of the PTHREAD_LIBS,
933 # etcetera environment variables, and if threads linking works using
935 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
936 save_CFLAGS="$CFLAGS"
937 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
939 LIBS="$PTHREAD_LIBS $LIBS"
940 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
941 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
942 AC_MSG_RESULT($acx_pthread_ok)
943 if test x"$acx_pthread_ok" = xno; then
948 CFLAGS="$save_CFLAGS"
951 # We must check for the threads library under a number of different
952 # names; the ordering is very important because some systems
953 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
954 # libraries is broken (non-POSIX).
956 # Create a list of thread flags to try. Items starting with a "-" are
957 # C compiler flags, and other items are library names, except for "none"
958 # which indicates that we try without any flags at all, and "pthread-config"
959 # which is a program returning the flags for the Pth emulation library.
961 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
963 # The ordering *is* (sometimes) important. Some notes on the
964 # individual items follow:
966 # pthreads: AIX (must check this before -lpthread)
967 # none: in case threads are in libc; should be tried before -Kthread and
968 # other compiler flags to prevent continual compiler warnings
969 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
970 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
971 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
972 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
973 # -pthreads: Solaris/gcc
974 # -mthreads: Mingw32/gcc, Lynx/gcc
975 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
976 # doesn't hurt to check since this sometimes defines pthreads too;
977 # also defines -D_REENTRANT)
978 # ... -mt is also the pthreads flag for HP/aCC
979 # pthread: Linux, etcetera
980 # --thread-safe: KAI C++
981 # pthread-config: use pthread-config program (for GNU Pth library)
983 case "${host_cpu}-${host_os}" in
986 # On Solaris (at least, for some versions), libc contains stubbed
987 # (non-functional) versions of the pthreads routines, so link-based
988 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
989 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
990 # a function called by this macro, so we could check for that, but
991 # who knows whether they'll stub that too in a future libc.) So,
992 # we'll just look for -pthreads and -lpthread first:
994 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
998 if test x"$acx_pthread_ok" = xno; then
999 for flag in $acx_pthread_flags; do
1003 AC_MSG_CHECKING([whether pthreads work without any flags])
1007 AC_MSG_CHECKING([whether pthreads work with $flag])
1008 PTHREAD_CFLAGS="$flag"
1012 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
1013 if test x"$acx_pthread_config" = xno; then continue; fi
1014 PTHREAD_CFLAGS="`pthread-config --cflags`"
1015 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
1019 AC_MSG_CHECKING([for the pthreads library -l$flag])
1020 PTHREAD_LIBS="-l$flag"
1025 save_CFLAGS="$CFLAGS"
1026 LIBS="$PTHREAD_LIBS $LIBS"
1027 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1029 # Check for various functions. We must include pthread.h,
1030 # since some functions may be macros. (On the Sequent, we
1031 # need a special flag -Kthread to make this header compile.)
1032 # We check for pthread_join because it is in -lpthread on IRIX
1033 # while pthread_create is in libc. We check for pthread_attr_init
1034 # due to DEC craziness with -lpthreads. We check for
1035 # pthread_cleanup_push because it is one of the few pthread
1036 # functions on Solaris that doesn't have a non-functional libc stub.
1037 # We try pthread_create on general principles.
1038 AC_TRY_LINK([#include <pthread.h>],
1039 [pthread_t th; pthread_join(th, 0);
1040 pthread_attr_init(0); pthread_cleanup_push(0, 0);
1041 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
1042 [acx_pthread_ok=yes])
1045 CFLAGS="$save_CFLAGS"
1047 AC_MSG_RESULT($acx_pthread_ok)
1048 if test "x$acx_pthread_ok" = xyes; then
1057 # Various other checks:
1058 if test "x$acx_pthread_ok" = xyes; then
1060 LIBS="$PTHREAD_LIBS $LIBS"
1061 save_CFLAGS="$CFLAGS"
1062 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1064 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
1065 AC_MSG_CHECKING([for joinable pthread attribute])
1067 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
1068 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
1069 [attr_name=$attr; break])
1071 AC_MSG_RESULT($attr_name)
1072 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
1073 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
1074 [Define to necessary symbol if this constant
1075 uses a non-standard name on your system.])
1078 AC_MSG_CHECKING([if more special flags are required for pthreads])
1080 case "${host_cpu}-${host_os}" in
1081 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1082 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1084 AC_MSG_RESULT(${flag})
1085 if test "x$flag" != xno; then
1086 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1090 CFLAGS="$save_CFLAGS"
1092 # More AIX lossage: must compile with xlc_r or cc_r
1093 if test x"$GCC" != xyes; then
1094 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1102 AC_SUBST(PTHREAD_LIBS)
1103 AC_SUBST(PTHREAD_CFLAGS)
1104 AC_SUBST(PTHREAD_CC)
1106 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1107 if test x"$acx_pthread_ok" = xyes; then
1108 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])