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], [description])
132 AC_DEFUN([AST_C_COMPILE_CHECK],
134 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
135 if test "x$5" != "x"; then
136 AC_MSG_CHECKING([for $5])
138 AC_MSG_CHECKING([if "$2" compiles using $3])
140 saved_cppflags="${CPPFLAGS}"
141 if test "x${$1_DIR}" != "x"; then
142 $1_INCLUDE="-I${$1_DIR}/include"
144 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
147 [ AC_LANG_PROGRAM( [#include <$3>],
152 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
153 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
155 [ AC_MSG_RESULT(no) ]
157 CPPFLAGS="${saved_cppflags}"
162 # Check for existence of a given package ($1), either looking up a function
163 # in a library, or, if no function is supplied, only check for the
164 # existence of the header files.
166 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
167 # [extra libs], [extra cflags], [version])
168 AC_DEFUN([AST_EXT_LIB_CHECK],
170 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
172 # if --with-$1=DIR has been specified, use it.
173 if test "x${$1_DIR}" != "x"; then
174 if test -d ${$1_DIR}/lib; then
175 pbxlibdir="-L${$1_DIR}/lib"
177 pbxlibdir="-L${$1_DIR}"
181 if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
184 AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
187 # now check for the header.
188 if test "${AST_$1_FOUND}" = "yes"; then
189 $1_LIB="${pbxlibdir} -l$2 $5"
190 # if --with-$1=DIR has been specified, use it.
191 if test "x${$1_DIR}" != "x"; then
192 $1_INCLUDE="-I${$1_DIR}/include"
194 $1_INCLUDE="${$1_INCLUDE} $6"
195 if test "x$4" = "x" ; then # no header, assume found
197 else # check for the header
198 saved_cppflags="${CPPFLAGS}"
199 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
200 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
201 CPPFLAGS="${saved_cppflags}"
203 if test "x${$1_HEADER_FOUND}" = "x0" ; then
207 if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
211 # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
212 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
213 AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the ${$1_DESCRIP} library version])
220 # Check for a package using $2-config. Similar to AST_EXT_LIB_CHECK,
221 # but use $2-config to determine cflags and libraries to use.
222 # $3 and $4 can be used to replace --cflags and --libs in the request
224 # AST_EXT_TOOL_CHECK([package], [tool name], [--cflags], [--libs], [includes], [expression])
225 AC_DEFUN([AST_EXT_TOOL_CHECK],
227 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
229 AC_CHECK_TOOL(CONFIG_$1, $2-config, No)
230 if test ! "x${CONFIG_$1}" = xNo; then
231 if test x"$3" = x ; then A=--cflags ; else A="$3" ; fi
232 $1_INCLUDE=$(${CONFIG_$1} $A)
233 if test x"$4" = x ; then A=--libs ; else A="$4" ; fi
234 $1_LIB=$(${CONFIG_$1} $A)
235 if test x"$5" != x ; then
236 saved_cppflags="${CPPFLAGS}"
237 if test "x${$1_DIR}" != "x"; then
238 $1_INCLUDE="-I${$1_DIR}/include"
240 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
242 saved_ldflags="${LDFLAGS}"
246 [ AC_LANG_PROGRAM( [ $5 ],
250 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
254 CPPFLAGS="${saved_cppflags}"
255 LDFLAGS="${saved_ldflags}"
258 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
265 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
266 GNU_MAKE='Not Found' ;
267 GNU_MAKE_VERSION_MAJOR=0 ;
268 GNU_MAKE_VERSION_MINOR=0 ;
269 for a in make gmake gnumake ; do
270 if test -z "$a" ; then continue ; fi ;
271 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
273 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
274 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
279 if test "x$GNU_MAKE" = "xNot Found" ; then
280 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
292 if test "${PWLIBDIR:-unset}" != "unset" ; then
293 AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
295 if test "${HAS_PWLIB:-unset}" = "unset" ; then
296 if test "${OPENH323DIR:-unset}" != "unset"; then
297 AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
299 if test "${HAS_PWLIB:-unset}" != "unset" ; then
300 PWLIBDIR="${OPENH323DIR}/../pwlib"
302 AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
303 if test "${HAS_PWLIB:-unset}" != "unset" ; then
304 PWLIBDIR="${HOME}/pwlib"
306 AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
307 if test "${HAS_PWLIB:-unset}" != "unset" ; then
308 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
309 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
310 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
312 PWLIB_INCDIR="/usr/local/include"
313 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
314 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
315 if test "x$LIB64" != "x"; then
316 PWLIB_LIBDIR="/usr/local/lib64"
318 PWLIB_LIBDIR="/usr/local/lib"
321 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
322 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
324 AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
325 if test "${HAS_PWLIB:-unset}" != "unset" ; then
326 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
327 PWLIB_INCDIR="/usr/include"
328 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
329 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
330 if test "x$LIB64" != "x"; then
331 PWLIB_LIBDIR="/usr/lib64"
333 PWLIB_LIBDIR="/usr/lib"
336 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
337 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
344 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
345 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
349 if test "${HAS_PWLIB:-unset}" != "unset" ; then
350 if test "${PWLIBDIR:-unset}" = "unset" ; then
351 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
352 PWLIBDIR=`$PTLIB_CONFIG --prefix`
354 echo "Cannot find ptlib-config - please install and try again"
359 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
360 PWLIBDIR="/usr/share/pwlib"
361 PWLIB_INCDIR="/usr/include"
362 if test "x$LIB64" != "x"; then
363 PWLIB_LIBDIR="/usr/lib64"
365 PWLIB_LIBDIR="/usr/lib"
368 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
369 PWLIBDIR="/usr/local/share/pwlib"
370 PWLIB_INCDIR="/usr/local/include"
371 if test "x$LIB64" != "x"; then
372 PWLIB_LIBDIR="/usr/local/lib64"
374 PWLIB_LIBDIR="/usr/local/lib"
378 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
379 PWLIB_INCDIR="${PWLIBDIR}/include"
381 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
382 PWLIB_LIBDIR="${PWLIBDIR}/lib"
386 AC_SUBST([PWLIB_INCDIR])
387 AC_SUBST([PWLIB_LIBDIR])
394 [AST_CHECK_OPENH323_PLATFORM], [
397 linux*) PWLIB_OSTYPE=linux ;
399 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
401 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
402 ENDLDLIBS="-lossaudio" ;
404 netbsd* ) PWLIB_OSTYPE=NetBSD ;
405 ENDLDLIBS="-lossaudio" ;
407 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
409 darwin* ) PWLIB_OSTYPE=Darwin ;
411 beos*) PWLIB_OSTYPE=beos ;
412 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
414 cygwin*) PWLIB_OSTYPE=cygwin ;
416 mingw*) PWLIB_OSTYPE=mingw ;
417 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
418 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
420 * ) PWLIB_OSTYPE="$host_os" ;
421 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
427 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
430 x86_64) PWLIB_MACHTYPE=x86_64 ;
435 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
439 sparc ) PWLIB_MACHTYPE=sparc ;
442 powerpc ) PWLIB_MACHTYPE=ppc ;
445 ppc ) PWLIB_MACHTYPE=ppc ;
448 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
453 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
458 ia64) PWLIB_MACHTYPE=ia64 ;
462 s390x) PWLIB_MACHTYPE=s390x ;
467 s390) PWLIB_MACHTYPE=s390 ;
470 * ) PWLIB_MACHTYPE="$host_cpu";
471 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
474 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
476 AC_SUBST([PWLIB_PLATFORM])
481 [AST_CHECK_OPENH323], [
485 if test "${OPENH323DIR:-unset}" != "unset" ; then
486 AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
488 if test "${HAS_OPENH323:-unset}" = "unset" ; then
489 AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
490 if test "${HAS_OPENH323:-unset}" != "unset" ; then
491 OPENH323DIR="${PWLIBDIR}/../openh323"
492 saved_cppflags="${CPPFLAGS}"
493 CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
494 AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
495 CPPFLAGS="${saved_cppflags}"
497 saved_cppflags="${CPPFLAGS}"
498 CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
499 AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
500 CPPFLAGS="${saved_cppflags}"
501 if test "${HAS_OPENH323:-unset}" != "unset" ; then
502 OPENH323DIR="${HOME}/openh323"
504 saved_cppflags="${CPPFLAGS}"
505 CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
506 AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
507 CPPFLAGS="${saved_cppflags}"
508 if test "${HAS_OPENH323:-unset}" != "unset" ; then
509 OPENH323DIR="/usr/local/share/openh323"
510 OPENH323_INCDIR="/usr/local/include/openh323"
511 if test "x$LIB64" != "x"; then
512 OPENH323_LIBDIR="/usr/local/lib64"
514 OPENH323_LIBDIR="/usr/local/lib"
517 saved_cppflags="${CPPFLAGS}"
518 CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
519 AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
520 CPPFLAGS="${saved_cppflags}"
521 if test "${HAS_OPENH323:-unset}" != "unset" ; then
522 OPENH323DIR="/usr/share/openh323"
523 OPENH323_INCDIR="/usr/include/openh323"
524 if test "x$LIB64" != "x"; then
525 OPENH323_LIBDIR="/usr/lib64"
527 OPENH323_LIBDIR="/usr/lib"
535 if test "${HAS_OPENH323:-unset}" != "unset" ; then
536 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
537 OPENH323_INCDIR="${OPENH323DIR}/include"
539 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
540 OPENH323_LIBDIR="${OPENH323DIR}/lib"
543 OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
544 OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
545 OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
547 AC_SUBST([OPENH323DIR])
548 AC_SUBST([OPENH323_INCDIR])
549 AC_SUBST([OPENH323_LIBDIR])
556 [AST_CHECK_PWLIB_VERSION], [
557 if test "${HAS_$2:-unset}" != "unset"; then
558 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
559 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
560 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
561 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
562 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
563 let $2_REQ=$4*10000+$5*100+$6
565 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
566 if test ${$2_VER} -lt ${$2_REQ}; then
577 [AST_CHECK_PWLIB_BUILD], [
578 if test "${HAS_$2:-unset}" != "unset"; then
579 AC_MSG_CHECKING($1 installation validity)
581 saved_cppflags="${CPPFLAGS}"
583 if test "${$2_LIB:-unset}" != "unset"; then
584 LIBS="${LIBS} ${$2_LIB} $7"
586 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
588 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
593 [AC_LANG_PROGRAM([$4],[$5])],
605 CPPFLAGS="${saved_cppflags}"
607 if test "${ac_cv_lib_$2}" = "yes"; then
608 if test "${$2_LIB:-undef}" = "undef"; then
609 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
610 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
612 $2_LIB="-l${PLATFORM_$2}"
615 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
616 $2_INCLUDE="-I${$2_INCDIR}"
619 AC_DEFINE([HAVE_$2], 1, [$3])
625 [AST_CHECK_OPENH323_BUILD], [
626 if test "${HAS_OPENH323:-unset}" != "unset"; then
627 AC_MSG_CHECKING(OpenH323 build option)
629 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
630 for pfx in $prefixes; do
631 files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
633 if test -n "$files"; then
635 if test -f $f -a ! -L $f; then
636 libfile=`basename $f`
641 if test -n "$libfile"; then
646 if test "${libfile:-unset}" != "unset"; then
647 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
649 case "${OPENH323_SUFFIX}" in
651 OPENH323_BUILD="notrace";;
653 OPENH323_BUILD="opt";;
655 OPENH323_BUILD="debug";;
657 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
658 notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@ @:>@*=@<:@ @:>@*//'"`
659 if test "x$notrace" = "x"; then
662 if test "$notrace" -ne 0; then
663 OPENH323_BUILD="notrace"
667 OPENH323_LIB="-l${OPENH323_PREFIX}"
669 OPENH323_BUILD="notrace"
673 AC_MSG_RESULT(${OPENH323_BUILD})
675 AC_SUBST([OPENH323_SUFFIX])
676 AC_SUBST([OPENH323_BUILD])
683 AN_FUNCTION([fork], [AST_FUNC_FORK])
684 AN_FUNCTION([vfork], [AST_FUNC_FORK])
685 AC_DEFUN([AST_FUNC_FORK],
686 [AC_REQUIRE([AC_TYPE_PID_T])dnl
687 AC_CHECK_HEADERS(vfork.h)
688 AC_CHECK_FUNCS(fork vfork)
689 if test "x$ac_cv_func_fork" = xyes; then
692 ac_cv_func_fork_works=$ac_cv_func_fork
694 if test "x$ac_cv_func_fork_works" = xcross; then
696 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
697 # Override, as these systems have only a dummy fork() stub
698 ac_cv_func_fork_works=no
701 ac_cv_func_fork_works=yes
704 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
706 ac_cv_func_vfork_works=$ac_cv_func_vfork
707 if test "x$ac_cv_func_vfork" = xyes; then
710 if test "x$ac_cv_func_fork_works" = xcross; then
711 ac_cv_func_vfork_works=$ac_cv_func_vfork
712 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
715 if test "x$ac_cv_func_vfork_works" = xyes; then
716 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
718 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
720 if test "x$ac_cv_func_fork_works" = xyes; then
721 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
728 AC_DEFUN([_AST_FUNC_FORK],
729 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
731 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
733 /* By Ruediger Kuhlmann. */
736 [ac_cv_func_fork_works=yes],
737 [ac_cv_func_fork_works=no],
738 [ac_cv_func_fork_works=cross])])]
743 # find the pathname to the GNU or non-GNU linker
744 AC_DEFUN([AST_PROG_LD],
745 [AC_ARG_WITH([gnu-ld],
746 [AC_HELP_STRING([--with-gnu-ld],
747 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
748 [test "$withval" = no || with_gnu_ld=yes],
750 AC_REQUIRE([AST_PROG_SED])dnl
751 AC_REQUIRE([AC_PROG_CC])dnl
752 AC_REQUIRE([AC_CANONICAL_HOST])dnl
753 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
755 if test "$GCC" = yes; then
756 # Check if gcc -print-prog-name=ld gives a path.
757 AC_MSG_CHECKING([for ld used by $CC])
760 # gcc leaves a trailing carriage return which upsets mingw
761 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
763 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
766 # Accept absolute paths.
767 [[\\/]]* | ?:[[\\/]]*)
768 re_direlt='/[[^/]][[^/]]*/\.\./'
769 # Canonicalize the pathname of ld
770 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
771 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
772 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
774 test -z "$LD" && LD="$ac_prog"
777 # If it fails, then pretend we aren't using GCC.
781 # If it is relative, then search for the first ld in PATH.
785 elif test "$with_gnu_ld" = yes; then
786 AC_MSG_CHECKING([for GNU ld])
788 AC_MSG_CHECKING([for non-GNU ld])
790 AC_CACHE_VAL(lt_cv_path_LD,
791 [if test -z "$LD"; then
792 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
793 for ac_dir in $PATH; do
795 test -z "$ac_dir" && ac_dir=.
796 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
797 lt_cv_path_LD="$ac_dir/$ac_prog"
798 # Check to see if the program is GNU ld. I'd rather use --version,
799 # but apparently some variants of GNU ld only accept -v.
800 # Break only if it was the GNU/non-GNU ld that we prefer.
801 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
802 *GNU* | *'with BFD'*)
803 test "$with_gnu_ld" != no && break
806 test "$with_gnu_ld" != yes && break
813 lt_cv_path_LD="$LD" # Let the user override the test with a path.
816 if test -n "$LD"; then
821 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
828 AC_DEFUN([AST_PROG_LD_GNU],
829 [AC_REQUIRE([AST_PROG_EGREP])dnl
830 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
831 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
832 case `$LD -v 2>&1 </dev/null` in
833 *GNU* | *'with BFD'*)
834 lt_cv_prog_gnu_ld=yes
840 with_gnu_ld=$lt_cv_prog_gnu_ld
845 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
846 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
847 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
848 then ac_cv_prog_egrep='grep -E'
849 else ac_cv_prog_egrep='egrep'
851 EGREP=$ac_cv_prog_egrep
853 ])]) # AST_PROG_EGREP
857 # Check for a fully functional sed program that truncates
858 # as few characters as possible. Prefer GNU sed if found.
859 AC_DEFUN([AST_PROG_SED],
860 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
861 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
862 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
863 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
864 for ac_i in 1 2 3 4 5 6 7; do
865 ac_script="$ac_script$as_nl$ac_script"
867 echo "$ac_script" | sed 99q >conftest.sed
868 $as_unset ac_script || ac_script=
869 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
870 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
871 ["$ac_path_SED" -f conftest.sed])])])
872 SED="$ac_cv_path_SED"
877 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
879 dnl @summary figure out how to build C programs using POSIX threads
881 dnl This macro figures out how to build C programs using POSIX threads.
882 dnl It sets the PTHREAD_LIBS output variable to the threads library and
883 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
884 dnl C compiler flags that are needed. (The user can also force certain
885 dnl compiler flags/libs to be tested by setting these environment
888 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
889 dnl multi-threaded programs (defaults to the value of CC otherwise).
890 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
892 dnl NOTE: You are assumed to not only compile your program with these
893 dnl flags, but also link it with them as well. e.g. you should link
894 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
897 dnl If you are only building threads programs, you may wish to use
898 dnl these variables in your default LIBS, CFLAGS, and CC:
900 dnl LIBS="$PTHREAD_LIBS $LIBS"
901 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
904 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
905 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
906 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
908 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
909 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
910 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
911 dnl default action will define HAVE_PTHREAD.
913 dnl Please let the authors know if this macro fails on any platform, or
914 dnl if you have any other suggestions or comments. This macro was based
915 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
916 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
917 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
918 dnl We are also grateful for the helpful feedback of numerous users.
920 dnl @category InstalledPackages
921 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
922 dnl @version 2006-05-29
923 dnl @license GPLWithACException
925 AC_DEFUN([ACX_PTHREAD],
927 AC_REQUIRE([AC_CANONICAL_HOST])
932 # We used to check for pthread.h first, but this fails if pthread.h
933 # requires special compiler flags (e.g. on True64 or Sequent).
934 # It gets checked for in the link test anyway.
936 # First of all, check if the user has set any of the PTHREAD_LIBS,
937 # etcetera environment variables, and if threads linking works using
939 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
940 save_CFLAGS="$CFLAGS"
941 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
943 LIBS="$PTHREAD_LIBS $LIBS"
944 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
945 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
946 AC_MSG_RESULT($acx_pthread_ok)
947 if test x"$acx_pthread_ok" = xno; then
952 CFLAGS="$save_CFLAGS"
955 # We must check for the threads library under a number of different
956 # names; the ordering is very important because some systems
957 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
958 # libraries is broken (non-POSIX).
960 # Create a list of thread flags to try. Items starting with a "-" are
961 # C compiler flags, and other items are library names, except for "none"
962 # which indicates that we try without any flags at all, and "pthread-config"
963 # which is a program returning the flags for the Pth emulation library.
965 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
967 # The ordering *is* (sometimes) important. Some notes on the
968 # individual items follow:
970 # pthreads: AIX (must check this before -lpthread)
971 # none: in case threads are in libc; should be tried before -Kthread and
972 # other compiler flags to prevent continual compiler warnings
973 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
974 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
975 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
976 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
977 # -pthreads: Solaris/gcc
978 # -mthreads: Mingw32/gcc, Lynx/gcc
979 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
980 # doesn't hurt to check since this sometimes defines pthreads too;
981 # also defines -D_REENTRANT)
982 # ... -mt is also the pthreads flag for HP/aCC
983 # pthread: Linux, etcetera
984 # --thread-safe: KAI C++
985 # pthread-config: use pthread-config program (for GNU Pth library)
987 case "${host_cpu}-${host_os}" in
990 # On Solaris (at least, for some versions), libc contains stubbed
991 # (non-functional) versions of the pthreads routines, so link-based
992 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
993 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
994 # a function called by this macro, so we could check for that, but
995 # who knows whether they'll stub that too in a future libc.) So,
996 # we'll just look for -pthreads and -lpthread first:
998 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
1002 if test x"$acx_pthread_ok" = xno; then
1003 for flag in $acx_pthread_flags; do
1007 AC_MSG_CHECKING([whether pthreads work without any flags])
1011 AC_MSG_CHECKING([whether pthreads work with $flag])
1012 PTHREAD_CFLAGS="$flag"
1016 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
1017 if test x"$acx_pthread_config" = xno; then continue; fi
1018 PTHREAD_CFLAGS="`pthread-config --cflags`"
1019 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
1023 AC_MSG_CHECKING([for the pthreads library -l$flag])
1024 PTHREAD_LIBS="-l$flag"
1029 save_CFLAGS="$CFLAGS"
1030 LIBS="$PTHREAD_LIBS $LIBS"
1031 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1033 # Check for various functions. We must include pthread.h,
1034 # since some functions may be macros. (On the Sequent, we
1035 # need a special flag -Kthread to make this header compile.)
1036 # We check for pthread_join because it is in -lpthread on IRIX
1037 # while pthread_create is in libc. We check for pthread_attr_init
1038 # due to DEC craziness with -lpthreads. We check for
1039 # pthread_cleanup_push because it is one of the few pthread
1040 # functions on Solaris that doesn't have a non-functional libc stub.
1041 # We try pthread_create on general principles.
1042 AC_TRY_LINK([#include <pthread.h>],
1043 [pthread_t th; pthread_join(th, 0);
1044 pthread_attr_init(0); pthread_cleanup_push(0, 0);
1045 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
1046 [acx_pthread_ok=yes])
1049 CFLAGS="$save_CFLAGS"
1051 AC_MSG_RESULT($acx_pthread_ok)
1052 if test "x$acx_pthread_ok" = xyes; then
1061 # Various other checks:
1062 if test "x$acx_pthread_ok" = xyes; then
1064 LIBS="$PTHREAD_LIBS $LIBS"
1065 save_CFLAGS="$CFLAGS"
1066 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1068 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
1069 AC_MSG_CHECKING([for joinable pthread attribute])
1071 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
1072 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
1073 [attr_name=$attr; break])
1075 AC_MSG_RESULT($attr_name)
1076 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
1077 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
1078 [Define to necessary symbol if this constant
1079 uses a non-standard name on your system.])
1082 AC_MSG_CHECKING([if more special flags are required for pthreads])
1084 case "${host_cpu}-${host_os}" in
1085 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1086 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1088 AC_MSG_RESULT(${flag})
1089 if test "x$flag" != xno; then
1090 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1094 CFLAGS="$save_CFLAGS"
1096 # More AIX lossage: must compile with xlc_r or cc_r
1097 if test x"$GCC" != xyes; then
1098 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1106 AC_SUBST(PTHREAD_LIBS)
1107 AC_SUBST(PTHREAD_CFLAGS)
1108 AC_SUBST(PTHREAD_CC)
1110 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1111 if test x"$acx_pthread_ok" = xyes; then
1112 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])