re-doxygen some comments
[asterisk-bristuff.git] / acinclude.m4
blob2e969341fd5fa7ca38024c45edd5111782829801
1 # AST_GCC_ATTRIBUTE([attribute name])
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
5 AC_MSG_CHECKING(for compiler 'attribute $1' support)
6 AC_COMPILE_IFELSE(
7         AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
8                         []),
9         AC_MSG_RESULT(yes)
10         AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
11         AC_MSG_RESULT(no))
14 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
16 AC_DEFUN([AST_EXT_LIB_SETUP],
18 $1_DESCRIP="$2"
19 $1_OPTION="$3"
20 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),[
21 case ${withval} in
22      n|no)
23      USE_$1=no
24      ;;
25      y|ye|yes)
26      $1_MANDATORY="yes"
27      ;;
28      *)
29      $1_DIR="${withval}"
30      $1_MANDATORY="yes"
31      ;;
32 esac
34 PBX_$1=0
35 AC_SUBST([$1_LIB])
36 AC_SUBST([$1_INCLUDE])
37 AC_SUBST([$1_DIR])
38 AC_SUBST([PBX_$1])
41 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data])
43 AC_DEFUN([AST_EXT_LIB_CHECK],
45 if test "${USE_$1}" != "no"; then
46    pbxlibdir=""
47    if test "x${$1_DIR}" != "x"; then
48       if test -d ${$1_DIR}/lib; then
49          pbxlibdir="-L${$1_DIR}/lib"
50       else
51          pbxlibdir="-L${$1_DIR}"
52       fi
53    fi
54    AC_CHECK_LIB([$2], [$3], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
56    if test "${AST_$1_FOUND}" = "yes"; then
57       $1_LIB="-l$2 $5"
58       $1_HEADER_FOUND="1"
59       if test "x${$1_DIR}" != "x"; then
60          $1_LIB="${pbxlibdir} ${$1_LIB}"
61          $1_INCLUDE="-I${$1_DIR}/include"
62          saved_cppflags="${CPPFLAGS}"
63          CPPFLAGS="${CPPFLAGS} -I${$1_DIR}/include"
64          if test "x$4" != "x" ; then
65             AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
66          fi
67          CPPFLAGS="${saved_cppflags}"
68       else
69          if test "x$4" != "x" ; then
70             AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
71          fi
72       fi
73       if test "x${$1_HEADER_FOUND}" = "x0" ; then
74          if test -n "${$1_MANDATORY}" ;
75          then
76             AC_MSG_NOTICE([***])
77             AC_MSG_NOTICE([*** It appears that you do not have the $2 development package installed.])
78             AC_MSG_NOTICE([*** Please install it to include ${$1_DESCRIP} support, or re-run configure])
79             AC_MSG_NOTICE([*** without explicitly specifying --with-${$1_OPTION}])
80             exit 1
81          fi
82          $1_LIB=""
83          $1_INCLUDE=""
84          PBX_$1=0
85       else
86          PBX_$1=1
87          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define to indicate the ${$1_DESCRIP} library])
88       fi
89    elif test -n "${$1_MANDATORY}";
90    then
91       AC_MSG_NOTICE([***])
92       AC_MSG_NOTICE([*** The ${$1_DESCRIP} installation on this system appears to be broken.])
93       AC_MSG_NOTICE([*** Either correct the installation, or run configure])
94       AC_MSG_NOTICE([*** without explicitly specifying --with-${$1_OPTION}])
95       exit 1
96    fi
101 AC_DEFUN(
102 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
103    GNU_MAKE='Not Found' ;
104    GNU_MAKE_VERSION_MAJOR=0 ;
105    GNU_MAKE_VERSION_MINOR=0 ;
106    for a in make gmake gnumake ; do
107       if test -z "$a" ; then continue ; fi ;
108       if ( sh -c "$a --version" 2> /dev/null | grep GNU  2>&1 > /dev/null ) ;  then
109          GNU_MAKE=$a ;
110          GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
111          GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
112          break;
113       fi
114    done ;
115 ) ;
116 if test  "x$GNU_MAKE" = "xNot Found"  ; then
117    AC_MSG_ERROR( *** Please install GNU make.  It is required to build Asterisk!)
118    exit 1
120 AC_SUBST([GNU_MAKE])
124 AC_DEFUN(
125 [AST_CHECK_PWLIB], [
126 PWLIB_INCDIR=
127 PWLIB_LIBDIR=
128 AC_LANG_PUSH([C++])
129 if test "${PWLIBDIR:-unset}" != "unset" ; then
130   AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
132 if test "${HAS_PWLIB:-unset}" = "unset" ; then
133   if test "${OPENH323DIR:-unset}" != "unset"; then
134     AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
135   fi
136   if test "${HAS_PWLIB:-unset}" != "unset" ; then
137     PWLIBDIR="${OPENH323DIR}/../pwlib"
138   else
139     AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
140     if test "${HAS_PWLIB:-unset}" != "unset" ; then
141       PWLIBDIR="${HOME}/pwlib"
142     else
143       AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
144       if test "${HAS_PWLIB:-unset}" != "unset" ; then
145         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
146         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
147           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
148         fi
149         PWLIB_INCDIR="/usr/local/include"
150         PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
151         if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
152           if test "x$LIB64" != "x"; then
153             PWLIB_LIBDIR="/usr/local/lib64"
154           else
155             PWLIB_LIBDIR="/usr/local/lib"
156           fi
157         fi
158         PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
159         PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
160       else
161         AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
162         if test "${HAS_PWLIB:-unset}" != "unset" ; then
163           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
164           PWLIB_INCDIR="/usr/include"
165           PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
166           if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
167             if test "x$LIB64" != "x"; then
168               PWLIB_LIBDIR="/usr/lib64"
169             else
170               PWLIB_LIBDIR="/usr/lib"
171             fi
172           fi
173           PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
174           PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
175         fi
176       fi
177     fi
178   fi
181 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
182 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
183 #  exit
186 if test "${HAS_PWLIB:-unset}" != "unset" ; then
187   if test "${PWLIBDIR:-unset}" = "unset" ; then
188     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
189       PWLIBDIR=`$PTLIB_CONFIG --prefix`
190     else
191       echo "Cannot find ptlib-config - please install and try again"
192       exit
193     fi
194   fi
196   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
197     PWLIBDIR="/usr/share/pwlib"
198     PWLIB_INCDIR="/usr/include"
199     if test "x$LIB64" != "x"; then
200       PWLIB_LIBDIR="/usr/lib64"
201     else
202       PWLIB_LIBDIR="/usr/lib"
203     fi
204   fi
205   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
206     PWLIBDIR="/usr/local/share/pwlib"
207     PWLIB_INCDIR="/usr/local/include"
208     if test "x$LIB64" != "x"; then
209       PWLIB_LIBDIR="/usr/local/lib64"
210     else
211       PWLIB_LIBDIR="/usr/local/lib"
212     fi
213   fi
215   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
216     PWLIB_INCDIR="${PWLIBDIR}/include"
217   fi
218   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
219     PWLIB_LIBDIR="${PWLIBDIR}/lib"
220   fi
222   AC_SUBST([PWLIBDIR])
223   AC_SUBST([PWLIB_INCDIR])
224   AC_SUBST([PWLIB_LIBDIR])
226   AC_LANG_POP([C++])
230 AC_DEFUN(
231 [AST_CHECK_OPENH323_PLATFORM], [
232 PWLIB_OSTYPE=
233 case "$host_os" in
234   linux*)          PWLIB_OSTYPE=linux ;
235                 ;;
236   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
237                 ;;
238   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
239                                    ENDLDLIBS="-lossaudio" ;
240                 ;;
241   netbsd* )        PWLIB_OSTYPE=NetBSD ;
242                                    ENDLDLIBS="-lossaudio" ;
243                 ;;
244   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
245                 ;;
246   darwin* )            PWLIB_OSTYPE=Darwin ;
247                 ;;
248   beos*)           PWLIB_OSTYPE=beos ;
249                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
250                 ;;
251   cygwin*)         PWLIB_OSTYPE=cygwin ;
252                 ;;
253   mingw*)              PWLIB_OSTYPE=mingw ;
254                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
255                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
256                 ;;
257   * )                  PWLIB_OSTYPE="$host_os" ;
258                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
259                 ;;
260 esac
262 PWLIB_MACHTYPE=
263 case "$host_cpu" in
264    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
265                    ;;
267    x86_64)         PWLIB_MACHTYPE=x86_64 ;
268                    P_64BIT=1 ;
269                    LIB64=1 ;
270                    ;;
272    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
273                    P_64BIT=1 ;
274                    ;;
276    sparc )         PWLIB_MACHTYPE=sparc ;
277                    ;;
279    powerpc )       PWLIB_MACHTYPE=ppc ;
280                    ;;
282    ppc )           PWLIB_MACHTYPE=ppc ;
283                    ;;
285    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
286                    P_64BIT=1 ;
287                    LIB64=1 ;
288                    ;;
290    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
291                    P_64BIT=1 ;
292                    LIB64=1 ;
293                    ;;
295    ia64)           PWLIB_MACHTYPE=ia64 ;
296                    P_64BIT=1 ;
297                    ;;
299    s390x)          PWLIB_MACHTYPE=s390x ;
300                    P_64BIT=1 ;
301                    LIB64=1 ;
302                    ;;
304    s390)           PWLIB_MACHTYPE=s390 ;
305                    ;;
307    * )             PWLIB_MACHTYPE="$host_cpu";
308                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
309 esac
311 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
313 AC_SUBST([PWLIB_PLATFORM])
317 AC_DEFUN(
318 [AST_CHECK_OPENH323], [
319 OPENH323_INCDIR=
320 OPENH323_LIBDIR=
321 AC_LANG_PUSH([C++])
322 if test "${OPENH323DIR:-unset}" != "unset" ; then
323   AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
325 if test "${HAS_OPENH323:-unset}" = "unset" ; then
326   AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
327   if test "${HAS_OPENH323:-unset}" != "unset" ; then
328     OPENH323DIR="${PWLIBDIR}/../openh323"
329     saved_cppflags="${CPPFLAGS}"
330     CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
331     AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
332     CPPFLAGS="${saved_cppflags}"
333   else
334     saved_cppflags="${CPPFLAGS}"
335     CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
336     AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
337     CPPFLAGS="${saved_cppflags}"
338     if test "${HAS_OPENH323:-unset}" != "unset" ; then
339       OPENH323DIR="${HOME}/openh323"
340     else
341       saved_cppflags="${CPPFLAGS}"
342       CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
343       AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
344       CPPFLAGS="${saved_cppflags}"
345       if test "${HAS_OPENH323:-unset}" != "unset" ; then
346         OPENH323DIR="/usr/local/share/openh323"
347         OPENH323_INCDIR="/usr/local/include/openh323"
348         if test "x$LIB64" != "x"; then
349           OPENH323_LIBDIR="/usr/local/lib64"
350         else
351           OPENH323_LIBDIR="/usr/local/lib"
352         fi
353       else
354         saved_cppflags="${CPPFLAGS}"
355         CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
356         AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
357         CPPFLAGS="${saved_cppflags}"
358         if test "${HAS_OPENH323:-unset}" != "unset" ; then
359           OPENH323DIR="/usr/share/openh323"
360           OPENH323_INCDIR="/usr/include/openh323"
361           if test "x$LIB64" != "x"; then
362             OPENH323_LIBDIR="/usr/lib64"
363           else
364             OPENH323_LIBDIR="/usr/lib"
365           fi
366         fi
367       fi
368     fi
369   fi
372 if test "${HAS_OPENH323:-unset}" != "unset" ; then
373   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
374     OPENH323_INCDIR="${OPENH323DIR}/include"
375   fi
376   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
377     OPENH323_LIBDIR="${OPENH323DIR}/lib"
378   fi
380   OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
381   OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
382   OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
384   AC_SUBST([OPENH323DIR])
385   AC_SUBST([OPENH323_INCDIR])
386   AC_SUBST([OPENH323_LIBDIR])
388   AC_LANG_POP([C++])
392 AC_DEFUN(
393 [AST_CHECK_PWLIB_VERSION], [
394         if test "${HAS_$2:-unset}" != "unset"; then
395                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
396                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
397                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
398                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
399                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
400                 let $2_REQ=$4*10000+$5*100+$6
402                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
403                 if test ${$2_VER} -lt ${$2_REQ}; then
404                         AC_MSG_RESULT(no)
405                         unset HAS_$2
406                 else
407                         AC_MSG_RESULT(yes)
408                 fi
409         fi
413 AC_DEFUN(
414 [AST_CHECK_PWLIB_BUILD], [
415         if test "${HAS_$2:-unset}" != "unset"; then
416            AC_MSG_CHECKING($1 installation validity)
418            saved_cppflags="${CPPFLAGS}"
419            saved_libs="${LIBS}"
420            if test "${$2_LIB:-unset}" != "unset"; then
421               LIBS="${LIBS} ${$2_LIB} $7"
422            else
423               LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
424            fi
425            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
427            AC_LANG_PUSH([C++])
429            AC_LINK_IFELSE(
430                 [AC_LANG_PROGRAM([$4],[$5])],
431                 [       AC_MSG_RESULT(yes) 
432                         ac_cv_lib_$2="yes" 
433                 ],
434                 [       AC_MSG_RESULT(no) 
435                         ac_cv_lib_$2="no" 
436                 ]
437                 )
439            AC_LANG_POP([C++])
441            LIBS="${saved_libs}"
442            CPPFLAGS="${saved_cppflags}"
444            if test "${ac_cv_lib_$2}" = "yes"; then
445               if test "${$2_LIB:-undef}" = "undef"; then
446                  if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
447                     $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
448                  else
449                     $2_LIB="-l${PLATFORM_$2}"
450                  fi
451               fi
452               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
453                  $2_INCLUDE="-I${$2_INCDIR}"
454               fi
455                   PBX_$2=1
456                   AC_DEFINE([HAVE_$2], 1, [$3])
457            fi
458         fi
461 AC_DEFUN(
462 [AST_CHECK_OPENH323_BUILD], [
463         if test "${HAS_OPENH323:-unset}" != "unset"; then
464                 AC_MSG_CHECKING(OpenH323 build option)
465                 OPENH323_SUFFIX=
466                 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
467                 for pfx in $prefixes; do
468                         files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
469                         libfile=
470                         if test -n "$files"; then
471                                 for f in $files; do
472                                         if test -f $f -a ! -L $f; then
473                                                 libfile=`basename $f`
474                                                 break;
475                                         fi
476                                 done
477                         fi
478                         if test -n "$libfile"; then
479                                 OPENH323_PREFIX=$pfx
480                                 break;
481                         fi
482                 done
483                 if test "${libfile:-unset}" != "unset"; then
484                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
485                 fi
486                 case "${OPENH323_SUFFIX}" in
487                         n)
488                                 OPENH323_BUILD="notrace";;
489                         r)
490                                 OPENH323_BUILD="opt";;
491                         d)
492                                 OPENH323_BUILD="debug";;
493                         *)
494                                 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
495                                         notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@      @:>@*=@<:@      @:>@*//'"`
496                                         if test "x$notrace" = "x"; then
497                                                 notrace="0"
498                                         fi
499                                         if test "$notrace" -ne 0; then
500                                                 OPENH323_BUILD="notrace"
501                                         else
502                                                 OPENH323_BUILD="opt"
503                                         fi
504                                         OPENH323_LIB="-l${OPENH323_PREFIX}"
505                                 else
506                                         OPENH323_BUILD="notrace"
507                                 fi
508                                 ;;
509                 esac
510                 AC_MSG_RESULT(${OPENH323_BUILD})
512                 AC_SUBST([OPENH323_SUFFIX])
513                 AC_SUBST([OPENH323_BUILD])
514         fi
518 # AST_FUNC_FORK
519 # -------------
520 AN_FUNCTION([fork],  [AST_FUNC_FORK])
521 AN_FUNCTION([vfork], [AST_FUNC_FORK])
522 AC_DEFUN([AST_FUNC_FORK],
523 [AC_REQUIRE([AC_TYPE_PID_T])dnl
524 AC_CHECK_HEADERS(vfork.h)
525 AC_CHECK_FUNCS(fork vfork)
526 if test "x$ac_cv_func_fork" = xyes; then
527   _AST_FUNC_FORK
528 else
529   ac_cv_func_fork_works=$ac_cv_func_fork
531 if test "x$ac_cv_func_fork_works" = xcross; then
532   case $host in
533     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
534       # Override, as these systems have only a dummy fork() stub
535       ac_cv_func_fork_works=no
536       ;;
537     *)
538       ac_cv_func_fork_works=yes
539       ;;
540   esac
541   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
543 ac_cv_func_vfork_works=$ac_cv_func_vfork
544 if test "x$ac_cv_func_vfork" = xyes; then
545   _AC_FUNC_VFORK
547 if test "x$ac_cv_func_fork_works" = xcross; then
548   ac_cv_func_vfork_works=$ac_cv_func_vfork
549   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
552 if test "x$ac_cv_func_vfork_works" = xyes; then
553   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
554 else
555   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
557 if test "x$ac_cv_func_fork_works" = xyes; then
558   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
560 ])# AST_FUNC_FORK
563 # _AST_FUNC_FORK
564 # -------------
565 AC_DEFUN([_AST_FUNC_FORK],
566   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
567     [AC_RUN_IFELSE(
568       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
569         [
570           /* By Ruediger Kuhlmann. */
571           return fork () < 0;
572         ])],
573       [ac_cv_func_fork_works=yes],
574       [ac_cv_func_fork_works=no],
575       [ac_cv_func_fork_works=cross])])]
576 )# _AST_FUNC_FORK
578 # AST_PROG_LD
579 # ----------
580 # find the pathname to the GNU or non-GNU linker
581 AC_DEFUN([AST_PROG_LD],
582 [AC_ARG_WITH([gnu-ld],
583     [AC_HELP_STRING([--with-gnu-ld],
584         [assume the C compiler uses GNU ld @<:@default=no@:>@])],
585     [test "$withval" = no || with_gnu_ld=yes],
586     [with_gnu_ld=no])
587 AC_REQUIRE([AST_PROG_SED])dnl
588 AC_REQUIRE([AC_PROG_CC])dnl
589 AC_REQUIRE([AC_CANONICAL_HOST])dnl
590 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
591 ac_prog=ld
592 if test "$GCC" = yes; then
593   # Check if gcc -print-prog-name=ld gives a path.
594   AC_MSG_CHECKING([for ld used by $CC])
595   case $host in
596   *-*-mingw*)
597     # gcc leaves a trailing carriage return which upsets mingw
598     ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
599   *)
600     ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
601   esac
602   case $ac_prog in
603     # Accept absolute paths.
604     [[\\/]]* | ?:[[\\/]]*)
605       re_direlt='/[[^/]][[^/]]*/\.\./'
606       # Canonicalize the pathname of ld
607       ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
608       while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
609         ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
610       done
611       test -z "$LD" && LD="$ac_prog"
612       ;;
613   "")
614     # If it fails, then pretend we aren't using GCC.
615     ac_prog=ld
616     ;;
617   *)
618     # If it is relative, then search for the first ld in PATH.
619     with_gnu_ld=unknown
620     ;;
621   esac
622 elif test "$with_gnu_ld" = yes; then
623   AC_MSG_CHECKING([for GNU ld])
624 else
625   AC_MSG_CHECKING([for non-GNU ld])
627 AC_CACHE_VAL(lt_cv_path_LD,
628 [if test -z "$LD"; then
629   lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
630   for ac_dir in $PATH; do
631     IFS="$lt_save_ifs"
632     test -z "$ac_dir" && ac_dir=.
633     if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
634       lt_cv_path_LD="$ac_dir/$ac_prog"
635       # Check to see if the program is GNU ld.  I'd rather use --version,
636       # but apparently some variants of GNU ld only accept -v.
637       # Break only if it was the GNU/non-GNU ld that we prefer.
638       case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
639       *GNU* | *'with BFD'*)
640         test "$with_gnu_ld" != no && break
641         ;;
642       *)
643         test "$with_gnu_ld" != yes && break
644         ;;
645       esac
646     fi
647   done
648   IFS="$lt_save_ifs"
649 else
650   lt_cv_path_LD="$LD" # Let the user override the test with a path.
651 fi])
652 LD="$lt_cv_path_LD"
653 if test -n "$LD"; then
654   AC_MSG_RESULT($LD)
655 else
656   AC_MSG_RESULT(no)
658 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
659 AST_PROG_LD_GNU
660 ])# AST_PROG_LD
663 # AST_PROG_LD_GNU
664 # --------------
665 AC_DEFUN([AST_PROG_LD_GNU],
666 [AC_REQUIRE([AST_PROG_EGREP])dnl
667 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
668 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
669 case `$LD -v 2>&1 </dev/null` in
670 *GNU* | *'with BFD'*)
671   lt_cv_prog_gnu_ld=yes
672   ;;
674   lt_cv_prog_gnu_ld=no
675   ;;
676 esac])
677 with_gnu_ld=$lt_cv_prog_gnu_ld
678 ])# AST_PROG_LD_GNU
680 # AST_PROG_EGREP
681 # -------------
682 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
683 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
684    [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
685     then ac_cv_prog_egrep='grep -E'
686     else ac_cv_prog_egrep='egrep'
687     fi])
688  EGREP=$ac_cv_prog_egrep
689  AC_SUBST([EGREP])
690 ])]) # AST_PROG_EGREP
692 # AST_PROG_SED
693 # -----------
694 # Check for a fully functional sed program that truncates
695 # as few characters as possible.  Prefer GNU sed if found.
696 AC_DEFUN([AST_PROG_SED],
697 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
698     [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
699      dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
700      ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
701      for ac_i in 1 2 3 4 5 6 7; do
702        ac_script="$ac_script$as_nl$ac_script"
703      done
704      echo "$ac_script" | sed 99q >conftest.sed
705      $as_unset ac_script || ac_script=
706      _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
707         [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
708                 ["$ac_path_SED" -f conftest.sed])])])
709  SED="$ac_cv_path_SED"
710  AC_SUBST([SED])dnl
711  rm -f conftest.sed
712 ])# AST_PROG_SED
714 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
716 dnl @summary figure out how to build C programs using POSIX threads
718 dnl This macro figures out how to build C programs using POSIX threads.
719 dnl It sets the PTHREAD_LIBS output variable to the threads library and
720 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
721 dnl C compiler flags that are needed. (The user can also force certain
722 dnl compiler flags/libs to be tested by setting these environment
723 dnl variables.)
725 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
726 dnl multi-threaded programs (defaults to the value of CC otherwise).
727 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
729 dnl NOTE: You are assumed to not only compile your program with these
730 dnl flags, but also link it with them as well. e.g. you should link
731 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
732 dnl $LIBS
734 dnl If you are only building threads programs, you may wish to use
735 dnl these variables in your default LIBS, CFLAGS, and CC:
737 dnl        LIBS="$PTHREAD_LIBS $LIBS"
738 dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
739 dnl        CC="$PTHREAD_CC"
741 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
742 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
743 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
745 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
746 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
747 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
748 dnl default action will define HAVE_PTHREAD.
750 dnl Please let the authors know if this macro fails on any platform, or
751 dnl if you have any other suggestions or comments. This macro was based
752 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
753 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
754 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
755 dnl We are also grateful for the helpful feedback of numerous users.
757 dnl @category InstalledPackages
758 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
759 dnl @version 2006-05-29
760 dnl @license GPLWithACException
762 AC_DEFUN([ACX_PTHREAD], [
763 AC_REQUIRE([AC_CANONICAL_HOST])
764 AC_LANG_SAVE
765 AC_LANG_C
766 acx_pthread_ok=no
768 # We used to check for pthread.h first, but this fails if pthread.h
769 # requires special compiler flags (e.g. on True64 or Sequent).
770 # It gets checked for in the link test anyway.
772 # First of all, check if the user has set any of the PTHREAD_LIBS,
773 # etcetera environment variables, and if threads linking works using
774 # them:
775 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
776         save_CFLAGS="$CFLAGS"
777         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
778         save_LIBS="$LIBS"
779         LIBS="$PTHREAD_LIBS $LIBS"
780         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
781         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
782         AC_MSG_RESULT($acx_pthread_ok)
783         if test x"$acx_pthread_ok" = xno; then
784                 PTHREAD_LIBS=""
785                 PTHREAD_CFLAGS=""
786         fi
787         LIBS="$save_LIBS"
788         CFLAGS="$save_CFLAGS"
791 # We must check for the threads library under a number of different
792 # names; the ordering is very important because some systems
793 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
794 # libraries is broken (non-POSIX).
796 # Create a list of thread flags to try.  Items starting with a "-" are
797 # C compiler flags, and other items are library names, except for "none"
798 # which indicates that we try without any flags at all, and "pthread-config"
799 # which is a program returning the flags for the Pth emulation library.
801 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
803 # The ordering *is* (sometimes) important.  Some notes on the
804 # individual items follow:
806 # pthreads: AIX (must check this before -lpthread)
807 # none: in case threads are in libc; should be tried before -Kthread and
808 #       other compiler flags to prevent continual compiler warnings
809 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
810 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
811 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
812 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
813 # -pthreads: Solaris/gcc
814 # -mthreads: Mingw32/gcc, Lynx/gcc
815 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
816 #      doesn't hurt to check since this sometimes defines pthreads too;
817 #      also defines -D_REENTRANT)
818 #      ... -mt is also the pthreads flag for HP/aCC
819 # pthread: Linux, etcetera
820 # --thread-safe: KAI C++
821 # pthread-config: use pthread-config program (for GNU Pth library)
823 case "${host_cpu}-${host_os}" in
824         *solaris*)
826         # On Solaris (at least, for some versions), libc contains stubbed
827         # (non-functional) versions of the pthreads routines, so link-based
828         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
829         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
830         # a function called by this macro, so we could check for that, but
831         # who knows whether they'll stub that too in a future libc.)  So,
832         # we'll just look for -pthreads and -lpthread first:
834         acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
835         ;;
836 esac
838 if test x"$acx_pthread_ok" = xno; then
839 for flag in $acx_pthread_flags; do
841         case $flag in
842                 none)
843                 AC_MSG_CHECKING([whether pthreads work without any flags])
844                 ;;
846                 -*)
847                 AC_MSG_CHECKING([whether pthreads work with $flag])
848                 PTHREAD_CFLAGS="$flag"
849                 ;;
851                 pthread-config)
852                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
853                 if test x"$acx_pthread_config" = xno; then continue; fi
854                 PTHREAD_CFLAGS="`pthread-config --cflags`"
855                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
856                 ;;
858                 *)
859                 AC_MSG_CHECKING([for the pthreads library -l$flag])
860                 PTHREAD_LIBS="-l$flag"
861                 ;;
862         esac
864         save_LIBS="$LIBS"
865         save_CFLAGS="$CFLAGS"
866         LIBS="$PTHREAD_LIBS $LIBS"
867         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
869         # Check for various functions.  We must include pthread.h,
870         # since some functions may be macros.  (On the Sequent, we
871         # need a special flag -Kthread to make this header compile.)
872         # We check for pthread_join because it is in -lpthread on IRIX
873         # while pthread_create is in libc.  We check for pthread_attr_init
874         # due to DEC craziness with -lpthreads.  We check for
875         # pthread_cleanup_push because it is one of the few pthread
876         # functions on Solaris that doesn't have a non-functional libc stub.
877         # We try pthread_create on general principles.
878         AC_TRY_LINK([#include <pthread.h>],
879                     [pthread_t th; pthread_join(th, 0);
880                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
881                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
882                     [acx_pthread_ok=yes])
884         LIBS="$save_LIBS"
885         CFLAGS="$save_CFLAGS"
887         AC_MSG_RESULT($acx_pthread_ok)
888         if test "x$acx_pthread_ok" = xyes; then
889                 break;
890         fi
892         PTHREAD_LIBS=""
893         PTHREAD_CFLAGS=""
894 done
897 # Various other checks:
898 if test "x$acx_pthread_ok" = xyes; then
899         save_LIBS="$LIBS"
900         LIBS="$PTHREAD_LIBS $LIBS"
901         save_CFLAGS="$CFLAGS"
902         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
904         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
905         AC_MSG_CHECKING([for joinable pthread attribute])
906         attr_name=unknown
907         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
908             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
909                         [attr_name=$attr; break])
910         done
911         AC_MSG_RESULT($attr_name)
912         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
913             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
914                                [Define to necessary symbol if this constant
915                                 uses a non-standard name on your system.])
916         fi
918         AC_MSG_CHECKING([if more special flags are required for pthreads])
919         flag=no
920         case "${host_cpu}-${host_os}" in
921             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
922             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
923         esac
924         AC_MSG_RESULT(${flag})
925         if test "x$flag" != xno; then
926             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
927         fi
929         LIBS="$save_LIBS"
930         CFLAGS="$save_CFLAGS"
932         # More AIX lossage: must compile with xlc_r or cc_r
933         if test x"$GCC" != xyes; then
934           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
935         else
936           PTHREAD_CC=$CC
937         fi
938 else
939         PTHREAD_CC="$CC"
942 AC_SUBST(PTHREAD_LIBS)
943 AC_SUBST(PTHREAD_CFLAGS)
944 AC_SUBST(PTHREAD_CC)
946 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
947 if test x"$acx_pthread_ok" = xyes; then
948         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
949         :
950 else
951         acx_pthread_ok=no
952         $2
954 AC_LANG_RESTORE
955 ])dnl ACX_PTHREAD