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)
11 AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
14 AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
18 # Helper function to setup variables for a package.
19 # $1 -> the package name. Used in configure.ac and also as a prefix
20 # for the variables ($1_DIR, $1_INCLUDE, $1_LIB) in makeopts
21 # $3 -> option name, used in --with-$3 or --without-$3 when calling configure.
22 # $2 and $4 are just text describing the package (short and long form)
24 # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
26 AC_DEFUN([AST_EXT_LIB_SETUP],
30 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),
37 ac_mandatory_list="${ac_mandatory_list} $1"
41 ac_mandatory_list="${ac_mandatory_list} $1"
47 AC_SUBST([$1_INCLUDE])
52 # Check whether any of the mandatory modules are not present, and
53 # print error messages in case. The mandatory list is built using
54 # --with-* arguments when invoking configure.
56 AC_DEFUN([AST_CHECK_MANDATORY],
58 AC_MSG_CHECKING([for mandatory modules: ${ac_mandatory_list}])
60 for i in ${ac_mandatory_list}; do
62 if test "x${a}" = "x1" ; then continue; fi
63 if test ${err} = "0" ; then AC_MSG_RESULT(fail) ; fi
65 eval "a=\${${i}_OPTION}"
67 AC_MSG_NOTICE([*** The $i installation appears to be missing or broken.])
68 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
69 AC_MSG_NOTICE([*** including --without-${a}.])
72 if test $err = 1 ; then exit 1; fi
76 # The next three functions check for the availability of a given package.
77 # AST_C_DEFINE_CHECK looks for the presence of a #define in a header file,
78 # AST_EXT_LIB_CHECK looks for a symbol in a given library, or at least
79 # for the presence of a header file.
80 # AST_EXT_TOOL_CHECK looks for a symbol in using $1-config to determine CFLAGS and LIBS
82 # They are only run if PBX_$1 != 1 (where $1 is the package),
83 # so you can call them multiple times and stop at the first matching one.
84 # On success, they both set PBX_$1 = 1, set $1_INCLUDE and $1_LIB as applicable,
85 # and also #define HAVE_$1 1 and #define HAVE_$1_VERSION ${last_argument}
86 # in autoconfig.h so you can tell which test succeeded.
87 # They should be called after AST_EXT_LIB_SETUP($1, ...)
89 # Check if a given macro is defined in a certain header.
91 # AST_C_DEFINE_CHECK([package], [macro name], [header file], [version])
92 AC_DEFUN([AST_C_DEFINE_CHECK],
94 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
95 AC_MSG_CHECKING([for $2 in $3])
96 saved_cppflags="${CPPFLAGS}"
97 if test "x${$1_DIR}" != "x"; then
98 $1_INCLUDE="-I${$1_DIR}/include"
100 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
103 [ AC_LANG_PROGRAM( [#include <$3>], [int foo = $2;]) ],
106 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
107 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
109 [ AC_MSG_RESULT(no) ]
111 CPPFLAGS="${saved_cppflags}"
116 # Check for existence of a given package ($1), either looking up a function
117 # in a library, or, if no function is supplied, only check for the
118 # existence of the header files.
120 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
121 # [extra libs], [extra cflags], [version])
122 AC_DEFUN([AST_EXT_LIB_CHECK],
124 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
126 # if --with-$1=DIR has been specified, use it.
127 if test "x${$1_DIR}" != "x"; then
128 if test -d ${$1_DIR}/lib; then
129 pbxlibdir="-L${$1_DIR}/lib"
131 pbxlibdir="-L${$1_DIR}"
135 if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
138 AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
141 # now check for the header.
142 if test "${AST_$1_FOUND}" = "yes"; then
143 $1_LIB="${pbxlibdir} -l$2 $5"
144 # if --with-$1=DIR has been specified, use it.
145 if test "x${$1_DIR}" != "x"; then
146 $1_INCLUDE="-I${$1_DIR}/include"
148 $1_INCLUDE="${$1_INCLUDE} $6"
149 if test "x$4" = "x" ; then # no header, assume found
151 else # check for the header
152 saved_cppflags="${CPPFLAGS}"
153 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE} $6"
154 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
155 CPPFLAGS="${saved_cppflags}"
157 if test "x${$1_HEADER_FOUND}" = "x0" ; then
161 if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
165 # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
166 AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
167 AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the ${$1_DESCRIP} library version])
174 # Check for a package using $2-config. Similar to AST_EXT_LIB_CHECK,
175 # but use $2-config to determine cflags and libraries to use.
176 # $3 and $4 can be used to replace --cflags and --libs in the request
178 # AST_EXT_TOOL_CHECK([package], [tool name], [--cflags], [--libs])
179 AC_DEFUN([AST_EXT_TOOL_CHECK],
181 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
183 AC_CHECK_TOOL(CONFIG_$1, $2-config, No)
184 if test ! "x${CONFIG_$1}" = xNo; then
185 if test x"$3" = x ; then A=--cflags ; else A="$3" ; fi
186 $1_INCLUDE=$(${CONFIG_$1} $A)
187 if test x"$4" = x ; then A=--libs ; else A="$4" ; fi
188 $1_LIB=$(${CONFIG_$1} $A)
190 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
196 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
197 GNU_MAKE='Not Found' ;
198 GNU_MAKE_VERSION_MAJOR=0 ;
199 GNU_MAKE_VERSION_MINOR=0 ;
200 for a in make gmake gnumake ; do
201 if test -z "$a" ; then continue ; fi ;
202 if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
204 GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
205 GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
210 if test "x$GNU_MAKE" = "xNot Found" ; then
211 AC_MSG_ERROR( *** Please install GNU make. It is required to build Asterisk!)
223 if test "${PWLIBDIR:-unset}" != "unset" ; then
224 AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
226 if test "${HAS_PWLIB:-unset}" = "unset" ; then
227 if test "${OPENH323DIR:-unset}" != "unset"; then
228 AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
230 if test "${HAS_PWLIB:-unset}" != "unset" ; then
231 PWLIBDIR="${OPENH323DIR}/../pwlib"
233 AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
234 if test "${HAS_PWLIB:-unset}" != "unset" ; then
235 PWLIBDIR="${HOME}/pwlib"
237 AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
238 if test "${HAS_PWLIB:-unset}" != "unset" ; then
239 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
240 if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
241 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
243 PWLIB_INCDIR="/usr/local/include"
244 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
245 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
246 if test "x$LIB64" != "x"; then
247 PWLIB_LIBDIR="/usr/local/lib64"
249 PWLIB_LIBDIR="/usr/local/lib"
252 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
253 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
255 AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
256 if test "${HAS_PWLIB:-unset}" != "unset" ; then
257 AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
258 PWLIB_INCDIR="/usr/include"
259 PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
260 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
261 if test "x$LIB64" != "x"; then
262 PWLIB_LIBDIR="/usr/lib64"
264 PWLIB_LIBDIR="/usr/lib"
267 PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
268 PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
275 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
276 # echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
280 if test "${HAS_PWLIB:-unset}" != "unset" ; then
281 if test "${PWLIBDIR:-unset}" = "unset" ; then
282 if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
283 PWLIBDIR=`$PTLIB_CONFIG --prefix`
285 echo "Cannot find ptlib-config - please install and try again"
290 if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
291 PWLIBDIR="/usr/share/pwlib"
292 PWLIB_INCDIR="/usr/include"
293 if test "x$LIB64" != "x"; then
294 PWLIB_LIBDIR="/usr/lib64"
296 PWLIB_LIBDIR="/usr/lib"
299 if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
300 PWLIBDIR="/usr/local/share/pwlib"
301 PWLIB_INCDIR="/usr/local/include"
302 if test "x$LIB64" != "x"; then
303 PWLIB_LIBDIR="/usr/local/lib64"
305 PWLIB_LIBDIR="/usr/local/lib"
309 if test "${PWLIB_INCDIR:-unset}" = "unset"; then
310 PWLIB_INCDIR="${PWLIBDIR}/include"
312 if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
313 PWLIB_LIBDIR="${PWLIBDIR}/lib"
317 AC_SUBST([PWLIB_INCDIR])
318 AC_SUBST([PWLIB_LIBDIR])
325 [AST_CHECK_OPENH323_PLATFORM], [
328 linux*) PWLIB_OSTYPE=linux ;
330 freebsd* ) PWLIB_OSTYPE=FreeBSD ;
332 openbsd* ) PWLIB_OSTYPE=OpenBSD ;
333 ENDLDLIBS="-lossaudio" ;
335 netbsd* ) PWLIB_OSTYPE=NetBSD ;
336 ENDLDLIBS="-lossaudio" ;
338 solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
340 darwin* ) PWLIB_OSTYPE=Darwin ;
342 beos*) PWLIB_OSTYPE=beos ;
343 STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
345 cygwin*) PWLIB_OSTYPE=cygwin ;
347 mingw*) PWLIB_OSTYPE=mingw ;
348 STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
349 ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
351 * ) PWLIB_OSTYPE="$host_os" ;
352 AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
358 x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
361 x86_64) PWLIB_MACHTYPE=x86_64 ;
366 alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
370 sparc ) PWLIB_MACHTYPE=sparc ;
373 powerpc ) PWLIB_MACHTYPE=ppc ;
376 ppc ) PWLIB_MACHTYPE=ppc ;
379 powerpc64 ) PWLIB_MACHTYPE=ppc64 ;
384 ppc64 ) PWLIB_MACHTYPE=ppc64 ;
389 ia64) PWLIB_MACHTYPE=ia64 ;
393 s390x) PWLIB_MACHTYPE=s390x ;
398 s390) PWLIB_MACHTYPE=s390 ;
401 * ) PWLIB_MACHTYPE="$host_cpu";
402 AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
405 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
407 AC_SUBST([PWLIB_PLATFORM])
412 [AST_CHECK_OPENH323], [
416 if test "${OPENH323DIR:-unset}" != "unset" ; then
417 AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
419 if test "${HAS_OPENH323:-unset}" = "unset" ; then
420 AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
421 if test "${HAS_OPENH323:-unset}" != "unset" ; then
422 OPENH323DIR="${PWLIBDIR}/../openh323"
423 saved_cppflags="${CPPFLAGS}"
424 CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
425 AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
426 CPPFLAGS="${saved_cppflags}"
428 saved_cppflags="${CPPFLAGS}"
429 CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
430 AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
431 CPPFLAGS="${saved_cppflags}"
432 if test "${HAS_OPENH323:-unset}" != "unset" ; then
433 OPENH323DIR="${HOME}/openh323"
435 saved_cppflags="${CPPFLAGS}"
436 CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
437 AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
438 CPPFLAGS="${saved_cppflags}"
439 if test "${HAS_OPENH323:-unset}" != "unset" ; then
440 OPENH323DIR="/usr/local/share/openh323"
441 OPENH323_INCDIR="/usr/local/include/openh323"
442 if test "x$LIB64" != "x"; then
443 OPENH323_LIBDIR="/usr/local/lib64"
445 OPENH323_LIBDIR="/usr/local/lib"
448 saved_cppflags="${CPPFLAGS}"
449 CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
450 AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
451 CPPFLAGS="${saved_cppflags}"
452 if test "${HAS_OPENH323:-unset}" != "unset" ; then
453 OPENH323DIR="/usr/share/openh323"
454 OPENH323_INCDIR="/usr/include/openh323"
455 if test "x$LIB64" != "x"; then
456 OPENH323_LIBDIR="/usr/lib64"
458 OPENH323_LIBDIR="/usr/lib"
466 if test "${HAS_OPENH323:-unset}" != "unset" ; then
467 if test "${OPENH323_INCDIR:-unset}" = "unset"; then
468 OPENH323_INCDIR="${OPENH323DIR}/include"
470 if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
471 OPENH323_LIBDIR="${OPENH323DIR}/lib"
474 OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
475 OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
476 OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
478 AC_SUBST([OPENH323DIR])
479 AC_SUBST([OPENH323_INCDIR])
480 AC_SUBST([OPENH323_LIBDIR])
487 [AST_CHECK_PWLIB_VERSION], [
488 if test "${HAS_$2:-unset}" != "unset"; then
489 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
490 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
491 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
492 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
493 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
494 let $2_REQ=$4*10000+$5*100+$6
496 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
497 if test ${$2_VER} -lt ${$2_REQ}; then
508 [AST_CHECK_PWLIB_BUILD], [
509 if test "${HAS_$2:-unset}" != "unset"; then
510 AC_MSG_CHECKING($1 installation validity)
512 saved_cppflags="${CPPFLAGS}"
514 if test "${$2_LIB:-unset}" != "unset"; then
515 LIBS="${LIBS} ${$2_LIB} $7"
517 LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
519 CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
524 [AC_LANG_PROGRAM([$4],[$5])],
536 CPPFLAGS="${saved_cppflags}"
538 if test "${ac_cv_lib_$2}" = "yes"; then
539 if test "${$2_LIB:-undef}" = "undef"; then
540 if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
541 $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
543 $2_LIB="-l${PLATFORM_$2}"
546 if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
547 $2_INCLUDE="-I${$2_INCDIR}"
550 AC_DEFINE([HAVE_$2], 1, [$3])
556 [AST_CHECK_OPENH323_BUILD], [
557 if test "${HAS_OPENH323:-unset}" != "unset"; then
558 AC_MSG_CHECKING(OpenH323 build option)
560 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
561 for pfx in $prefixes; do
562 files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
564 if test -n "$files"; then
566 if test -f $f -a ! -L $f; then
567 libfile=`basename $f`
572 if test -n "$libfile"; then
577 if test "${libfile:-unset}" != "unset"; then
578 OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
580 case "${OPENH323_SUFFIX}" in
582 OPENH323_BUILD="notrace";;
584 OPENH323_BUILD="opt";;
586 OPENH323_BUILD="debug";;
588 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
589 notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@ @:>@*=@<:@ @:>@*//'"`
590 if test "x$notrace" = "x"; then
593 if test "$notrace" -ne 0; then
594 OPENH323_BUILD="notrace"
598 OPENH323_LIB="-l${OPENH323_PREFIX}"
600 OPENH323_BUILD="notrace"
604 AC_MSG_RESULT(${OPENH323_BUILD})
606 AC_SUBST([OPENH323_SUFFIX])
607 AC_SUBST([OPENH323_BUILD])
614 AN_FUNCTION([fork], [AST_FUNC_FORK])
615 AN_FUNCTION([vfork], [AST_FUNC_FORK])
616 AC_DEFUN([AST_FUNC_FORK],
617 [AC_REQUIRE([AC_TYPE_PID_T])dnl
618 AC_CHECK_HEADERS(vfork.h)
619 AC_CHECK_FUNCS(fork vfork)
620 if test "x$ac_cv_func_fork" = xyes; then
623 ac_cv_func_fork_works=$ac_cv_func_fork
625 if test "x$ac_cv_func_fork_works" = xcross; then
627 *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
628 # Override, as these systems have only a dummy fork() stub
629 ac_cv_func_fork_works=no
632 ac_cv_func_fork_works=yes
635 AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
637 ac_cv_func_vfork_works=$ac_cv_func_vfork
638 if test "x$ac_cv_func_vfork" = xyes; then
641 if test "x$ac_cv_func_fork_works" = xcross; then
642 ac_cv_func_vfork_works=$ac_cv_func_vfork
643 AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
646 if test "x$ac_cv_func_vfork_works" = xyes; then
647 AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
649 AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
651 if test "x$ac_cv_func_fork_works" = xyes; then
652 AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
659 AC_DEFUN([_AST_FUNC_FORK],
660 [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
662 [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
664 /* By Ruediger Kuhlmann. */
667 [ac_cv_func_fork_works=yes],
668 [ac_cv_func_fork_works=no],
669 [ac_cv_func_fork_works=cross])])]
674 # find the pathname to the GNU or non-GNU linker
675 AC_DEFUN([AST_PROG_LD],
676 [AC_ARG_WITH([gnu-ld],
677 [AC_HELP_STRING([--with-gnu-ld],
678 [assume the C compiler uses GNU ld @<:@default=no@:>@])],
679 [test "$withval" = no || with_gnu_ld=yes],
681 AC_REQUIRE([AST_PROG_SED])dnl
682 AC_REQUIRE([AC_PROG_CC])dnl
683 AC_REQUIRE([AC_CANONICAL_HOST])dnl
684 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
686 if test "$GCC" = yes; then
687 # Check if gcc -print-prog-name=ld gives a path.
688 AC_MSG_CHECKING([for ld used by $CC])
691 # gcc leaves a trailing carriage return which upsets mingw
692 ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
694 ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
697 # Accept absolute paths.
698 [[\\/]]* | ?:[[\\/]]*)
699 re_direlt='/[[^/]][[^/]]*/\.\./'
700 # Canonicalize the pathname of ld
701 ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
702 while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
703 ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
705 test -z "$LD" && LD="$ac_prog"
708 # If it fails, then pretend we aren't using GCC.
712 # If it is relative, then search for the first ld in PATH.
716 elif test "$with_gnu_ld" = yes; then
717 AC_MSG_CHECKING([for GNU ld])
719 AC_MSG_CHECKING([for non-GNU ld])
721 AC_CACHE_VAL(lt_cv_path_LD,
722 [if test -z "$LD"; then
723 lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
724 for ac_dir in $PATH; do
726 test -z "$ac_dir" && ac_dir=.
727 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
728 lt_cv_path_LD="$ac_dir/$ac_prog"
729 # Check to see if the program is GNU ld. I'd rather use --version,
730 # but apparently some variants of GNU ld only accept -v.
731 # Break only if it was the GNU/non-GNU ld that we prefer.
732 case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
733 *GNU* | *'with BFD'*)
734 test "$with_gnu_ld" != no && break
737 test "$with_gnu_ld" != yes && break
744 lt_cv_path_LD="$LD" # Let the user override the test with a path.
747 if test -n "$LD"; then
752 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
759 AC_DEFUN([AST_PROG_LD_GNU],
760 [AC_REQUIRE([AST_PROG_EGREP])dnl
761 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
762 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
763 case `$LD -v 2>&1 </dev/null` in
764 *GNU* | *'with BFD'*)
765 lt_cv_prog_gnu_ld=yes
771 with_gnu_ld=$lt_cv_prog_gnu_ld
776 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
777 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
778 [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
779 then ac_cv_prog_egrep='grep -E'
780 else ac_cv_prog_egrep='egrep'
782 EGREP=$ac_cv_prog_egrep
784 ])]) # AST_PROG_EGREP
788 # Check for a fully functional sed program that truncates
789 # as few characters as possible. Prefer GNU sed if found.
790 AC_DEFUN([AST_PROG_SED],
791 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
792 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
793 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
794 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
795 for ac_i in 1 2 3 4 5 6 7; do
796 ac_script="$ac_script$as_nl$ac_script"
798 echo "$ac_script" | sed 99q >conftest.sed
799 $as_unset ac_script || ac_script=
800 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
801 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
802 ["$ac_path_SED" -f conftest.sed])])])
803 SED="$ac_cv_path_SED"
808 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
810 dnl @summary figure out how to build C programs using POSIX threads
812 dnl This macro figures out how to build C programs using POSIX threads.
813 dnl It sets the PTHREAD_LIBS output variable to the threads library and
814 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
815 dnl C compiler flags that are needed. (The user can also force certain
816 dnl compiler flags/libs to be tested by setting these environment
819 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
820 dnl multi-threaded programs (defaults to the value of CC otherwise).
821 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
823 dnl NOTE: You are assumed to not only compile your program with these
824 dnl flags, but also link it with them as well. e.g. you should link
825 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
828 dnl If you are only building threads programs, you may wish to use
829 dnl these variables in your default LIBS, CFLAGS, and CC:
831 dnl LIBS="$PTHREAD_LIBS $LIBS"
832 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
835 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
836 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
837 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
839 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
840 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
841 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
842 dnl default action will define HAVE_PTHREAD.
844 dnl Please let the authors know if this macro fails on any platform, or
845 dnl if you have any other suggestions or comments. This macro was based
846 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
847 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
848 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
849 dnl We are also grateful for the helpful feedback of numerous users.
851 dnl @category InstalledPackages
852 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
853 dnl @version 2006-05-29
854 dnl @license GPLWithACException
856 AC_DEFUN([ACX_PTHREAD],
858 AC_REQUIRE([AC_CANONICAL_HOST])
863 # We used to check for pthread.h first, but this fails if pthread.h
864 # requires special compiler flags (e.g. on True64 or Sequent).
865 # It gets checked for in the link test anyway.
867 # First of all, check if the user has set any of the PTHREAD_LIBS,
868 # etcetera environment variables, and if threads linking works using
870 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
871 save_CFLAGS="$CFLAGS"
872 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
874 LIBS="$PTHREAD_LIBS $LIBS"
875 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
876 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
877 AC_MSG_RESULT($acx_pthread_ok)
878 if test x"$acx_pthread_ok" = xno; then
883 CFLAGS="$save_CFLAGS"
886 # We must check for the threads library under a number of different
887 # names; the ordering is very important because some systems
888 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
889 # libraries is broken (non-POSIX).
891 # Create a list of thread flags to try. Items starting with a "-" are
892 # C compiler flags, and other items are library names, except for "none"
893 # which indicates that we try without any flags at all, and "pthread-config"
894 # which is a program returning the flags for the Pth emulation library.
896 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
898 # The ordering *is* (sometimes) important. Some notes on the
899 # individual items follow:
901 # pthreads: AIX (must check this before -lpthread)
902 # none: in case threads are in libc; should be tried before -Kthread and
903 # other compiler flags to prevent continual compiler warnings
904 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
905 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
906 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
907 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
908 # -pthreads: Solaris/gcc
909 # -mthreads: Mingw32/gcc, Lynx/gcc
910 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
911 # doesn't hurt to check since this sometimes defines pthreads too;
912 # also defines -D_REENTRANT)
913 # ... -mt is also the pthreads flag for HP/aCC
914 # pthread: Linux, etcetera
915 # --thread-safe: KAI C++
916 # pthread-config: use pthread-config program (for GNU Pth library)
918 case "${host_cpu}-${host_os}" in
921 # On Solaris (at least, for some versions), libc contains stubbed
922 # (non-functional) versions of the pthreads routines, so link-based
923 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
924 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
925 # a function called by this macro, so we could check for that, but
926 # who knows whether they'll stub that too in a future libc.) So,
927 # we'll just look for -pthreads and -lpthread first:
929 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
933 if test x"$acx_pthread_ok" = xno; then
934 for flag in $acx_pthread_flags; do
938 AC_MSG_CHECKING([whether pthreads work without any flags])
942 AC_MSG_CHECKING([whether pthreads work with $flag])
943 PTHREAD_CFLAGS="$flag"
947 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
948 if test x"$acx_pthread_config" = xno; then continue; fi
949 PTHREAD_CFLAGS="`pthread-config --cflags`"
950 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
954 AC_MSG_CHECKING([for the pthreads library -l$flag])
955 PTHREAD_LIBS="-l$flag"
960 save_CFLAGS="$CFLAGS"
961 LIBS="$PTHREAD_LIBS $LIBS"
962 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
964 # Check for various functions. We must include pthread.h,
965 # since some functions may be macros. (On the Sequent, we
966 # need a special flag -Kthread to make this header compile.)
967 # We check for pthread_join because it is in -lpthread on IRIX
968 # while pthread_create is in libc. We check for pthread_attr_init
969 # due to DEC craziness with -lpthreads. We check for
970 # pthread_cleanup_push because it is one of the few pthread
971 # functions on Solaris that doesn't have a non-functional libc stub.
972 # We try pthread_create on general principles.
973 AC_TRY_LINK([#include <pthread.h>],
974 [pthread_t th; pthread_join(th, 0);
975 pthread_attr_init(0); pthread_cleanup_push(0, 0);
976 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
977 [acx_pthread_ok=yes])
980 CFLAGS="$save_CFLAGS"
982 AC_MSG_RESULT($acx_pthread_ok)
983 if test "x$acx_pthread_ok" = xyes; then
992 # Various other checks:
993 if test "x$acx_pthread_ok" = xyes; then
995 LIBS="$PTHREAD_LIBS $LIBS"
996 save_CFLAGS="$CFLAGS"
997 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
999 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
1000 AC_MSG_CHECKING([for joinable pthread attribute])
1002 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
1003 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
1004 [attr_name=$attr; break])
1006 AC_MSG_RESULT($attr_name)
1007 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
1008 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
1009 [Define to necessary symbol if this constant
1010 uses a non-standard name on your system.])
1013 AC_MSG_CHECKING([if more special flags are required for pthreads])
1015 case "${host_cpu}-${host_os}" in
1016 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1017 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1019 AC_MSG_RESULT(${flag})
1020 if test "x$flag" != xno; then
1021 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1025 CFLAGS="$save_CFLAGS"
1027 # More AIX lossage: must compile with xlc_r or cc_r
1028 if test x"$GCC" != xyes; then
1029 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1037 AC_SUBST(PTHREAD_LIBS)
1038 AC_SUBST(PTHREAD_CFLAGS)
1039 AC_SUBST(PTHREAD_CC)
1041 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1042 if test x"$acx_pthread_ok" = xyes; then
1043 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])