use the proper type for storing group number bits so that if someone specifies 'group...
[asterisk-bristuff.git] / acinclude.m4
blobfc4311ab053de95d1f7ee4ee5b284fc63d4cec3b
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 if test "${PWLIBDIR:-unset}" != "unset" ; then
129   AC_CHECK_FILE(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
131 if test "${HAS_PWLIB:-unset}" = "unset" ; then
132   if test "${OPENH323DIR:-unset}" != "unset"; then
133     AC_CHECK_FILE(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
134   fi
135   if test "${HAS_PWLIB:-unset}" != "unset" ; then
136     PWLIBDIR="${OPENH323DIR}/../pwlib"
137   else
138     AC_CHECK_FILE(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
139     if test "${HAS_PWLIB:-unset}" != "unset" ; then
140       PWLIBDIR="${HOME}/pwlib"
141     else
142       AC_CHECK_FILE(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
143       if test "${HAS_PWLIB:-unset}" != "unset" ; then
144         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
145         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
146           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
147         fi
148         PWLIB_INCDIR="/usr/local/include"
149         PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
150         if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
151           if test "x$LIB64" != "x"; then
152             PWLIB_LIBDIR="/usr/local/lib64"
153           else
154             PWLIB_LIBDIR="/usr/local/lib"
155           fi
156         fi
157         PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
158         PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
159       else
160         AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
161         if test "${HAS_PWLIB:-unset}" != "unset" ; then
162           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
163           PWLIB_INCDIR="/usr/include"
164           PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
165           if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
166             if test "x$LIB64" != "x"; then
167               PWLIB_LIBDIR="/usr/lib64"
168             else
169               PWLIB_LIBDIR="/usr/lib"
170             fi
171           fi
172           PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
173           PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
174         fi
175       fi
176     fi
177   fi
180 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
181 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
182 #  exit
185 if test "${HAS_PWLIB:-unset}" != "unset" ; then
186   if test "${PWLIBDIR:-unset}" = "unset" ; then
187     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
188       PWLIBDIR=`$PTLIB_CONFIG --prefix`
189     else
190       echo "Cannot find ptlib-config - please install and try again"
191       exit
192     fi
193   fi
195   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
196     PWLIBDIR="/usr/share/pwlib"
197     PWLIB_INCDIR="/usr/include"
198     if test "x$LIB64" != "x"; then
199       PWLIB_LIBDIR="/usr/lib64"
200     else
201       PWLIB_LIBDIR="/usr/lib"
202     fi
203   fi
204   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
205     PWLIBDIR="/usr/local/share/pwlib"
206     PWLIB_INCDIR="/usr/local/include"
207     if test "x$LIB64" != "x"; then
208       PWLIB_LIBDIR="/usr/local/lib64"
209     else
210       PWLIB_LIBDIR="/usr/local/lib"
211     fi
212   fi
214   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
215     PWLIB_INCDIR="${PWLIBDIR}/include"
216   fi
217   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
218     PWLIB_LIBDIR="${PWLIBDIR}/lib"
219   fi
221   AC_SUBST([PWLIBDIR])
222   AC_SUBST([PWLIB_INCDIR])
223   AC_SUBST([PWLIB_LIBDIR])
228 AC_DEFUN(
229 [AST_CHECK_OPENH323_PLATFORM], [
230 PWLIB_OSTYPE=
231 case "$host_os" in
232   linux*)          PWLIB_OSTYPE=linux ;
233                 ;;
234   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
235                 ;;
236   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
237                                    ENDLDLIBS="-lossaudio" ;
238                 ;;
239   netbsd* )        PWLIB_OSTYPE=NetBSD ;
240                                    ENDLDLIBS="-lossaudio" ;
241                 ;;
242   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
243                 ;;
244   darwin* )            PWLIB_OSTYPE=Darwin ;
245                 ;;
246   beos*)           PWLIB_OSTYPE=beos ;
247                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
248                 ;;
249   cygwin*)         PWLIB_OSTYPE=cygwin ;
250                 ;;
251   mingw*)              PWLIB_OSTYPE=mingw ;
252                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
253                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
254                 ;;
255   * )                  PWLIB_OSTYPE="$host_os" ;
256                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
257                 ;;
258 esac
260 PWLIB_MACHTYPE=
261 case "$host_cpu" in
262    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
263                    ;;
265    x86_64)         PWLIB_MACHTYPE=x86_64 ;
266                    P_64BIT=1 ;
267                    LIB64=1 ;
268                    ;;
270    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
271                    P_64BIT=1 ;
272                    ;;
274    sparc )         PWLIB_MACHTYPE=sparc ;
275                    ;;
277    powerpc )       PWLIB_MACHTYPE=ppc ;
278                    ;;
280    ppc )           PWLIB_MACHTYPE=ppc ;
281                    ;;
283    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
284                    P_64BIT=1 ;
285                    LIB64=1 ;
286                    ;;
288    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
289                    P_64BIT=1 ;
290                    LIB64=1 ;
291                    ;;
293    ia64)           PWLIB_MACHTYPE=ia64 ;
294                    P_64BIT=1 ;
295                    ;;
297    s390x)          PWLIB_MACHTYPE=s390x ;
298                    P_64BIT=1 ;
299                    LIB64=1 ;
300                    ;;
302    s390)           PWLIB_MACHTYPE=s390 ;
303                    ;;
305    * )             PWLIB_MACHTYPE="$host_cpu";
306                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
307 esac
309 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
311 AC_SUBST([PWLIB_PLATFORM])
315 AC_DEFUN(
316 [AST_CHECK_OPENH323], [
317 OPENH323_INCDIR=
318 OPENH323_LIBDIR=
319 if test "${OPENH323DIR:-unset}" != "unset" ; then
320   AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
322 if test "${HAS_OPENH323:-unset}" = "unset" ; then
323   AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
324   if test "${HAS_OPENH323:-unset}" != "unset" ; then
325     OPENH323DIR="${PWLIBDIR}/../openh323"
326     AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
327   else
328     AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
329     if test "${HAS_OPENH323:-unset}" != "unset" ; then
330       OPENH323DIR="${HOME}/openh323"
331     else
332       AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
333       if test "${HAS_OPENH323:-unset}" != "unset" ; then
334         OPENH323DIR="/usr/local/share/openh323"
335         OPENH323_INCDIR="/usr/local/include/openh323"
336         if test "x$LIB64" != "x"; then
337           OPENH323_LIBDIR="/usr/local/lib64"
338         else
339           OPENH323_LIBDIR="/usr/local/lib"
340         fi
341       else
342         AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
343         if test "${HAS_OPENH323:-unset}" != "unset" ; then
344           OPENH323DIR="/usr/share/openh323"
345           OPENH323_INCDIR="/usr/include/openh323"
346           if test "x$LIB64" != "x"; then
347             OPENH323_LIBDIR="/usr/lib64"
348           else
349             OPENH323_LIBDIR="/usr/lib"
350           fi
351         fi
352       fi
353     fi
354   fi
357 if test "${HAS_OPENH323:-unset}" != "unset" ; then
358   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
359     OPENH323_INCDIR="${OPENH323DIR}/include"
360   fi
361   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
362     OPENH323_LIBDIR="${OPENH323DIR}/lib"
363   fi
365   OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
366   OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
367   OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
369   AC_SUBST([OPENH323DIR])
370   AC_SUBST([OPENH323_INCDIR])
371   AC_SUBST([OPENH323_LIBDIR])
376 AC_DEFUN(
377 [AST_CHECK_PWLIB_VERSION], [
378         if test "${HAS_$2:-unset}" != "unset"; then
379                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
380                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
381                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
382                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
383                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
384                 let $2_REQ=$4*10000+$5*100+$6
386                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
387                 if test ${$2_VER} -lt ${$2_REQ}; then
388                         AC_MSG_RESULT(no)
389                         unset HAS_$2
390                 else
391                         AC_MSG_RESULT(yes)
392                 fi
393         fi
397 AC_DEFUN(
398 [AST_CHECK_PWLIB_BUILD], [
399         if test "${HAS_$2:-unset}" != "unset"; then
400            AC_MSG_CHECKING($1 installation validity)
402            saved_cppflags="${CPPFLAGS}"
403            saved_libs="${LIBS}"
404            if test "${$2_LIB:-unset}" != "unset"; then
405               LIBS="${LIBS} ${$2_LIB} $7"
406            else
407               LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
408            fi
409            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
411            AC_LANG_PUSH([C++])
413            AC_LINK_IFELSE(
414                 [AC_LANG_PROGRAM([$4],[$5])],
415                 [       AC_MSG_RESULT(yes) 
416                         ac_cv_lib_$2="yes" 
417                 ],
418                 [       AC_MSG_RESULT(no) 
419                         ac_cv_lib_$2="no" 
420                 ]
421                 )
423            AC_LANG_POP([C++])
425            LIBS="${saved_libs}"
426            CPPFLAGS="${saved_cppflags}"
428            if test "${ac_cv_lib_$2}" = "yes"; then
429               if test "${$2_LIB:-undef}" = "undef"; then
430                  if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
431                     $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
432                  else
433                     $2_LIB="-l${PLATFORM_$2}"
434                  fi
435               fi
436               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
437                  $2_INCLUDE="-I${$2_INCDIR}"
438               fi
439                   PBX_$2=1
440                   AC_DEFINE([HAVE_$2], 1, [$3])
441            fi
442         fi
445 AC_DEFUN(
446 [AST_CHECK_OPENH323_BUILD], [
447         if test "${HAS_OPENH323:-unset}" != "unset"; then
448                 AC_MSG_CHECKING(OpenH323 build option)
449                 OPENH323_SUFFIX=
450                 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
451                 for pfx in $prefixes; do
452                         files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
453                         libfile=
454                         if test -n "$files"; then
455                                 for f in $files; do
456                                         if test -f $f -a ! -L $f; then
457                                                 libfile=`basename $f`
458                                                 break;
459                                         fi
460                                 done
461                         fi
462                         if test -n "$libfile"; then
463                                 OPENH323_PREFIX=$pfx
464                                 break;
465                         fi
466                 done
467                 if test "${libfile:-unset}" != "unset"; then
468                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
469                 fi
470                 case "${OPENH323_SUFFIX}" in
471                         n)
472                                 OPENH323_BUILD="notrace";;
473                         r)
474                                 OPENH323_BUILD="opt";;
475                         d)
476                                 OPENH323_BUILD="debug";;
477                         *)
478                                 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
479                                         notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@      @:>@*=@<:@      @:>@*//'"`
480                                         if test "x$notrace" = "x"; then
481                                                 notrace="0"
482                                         fi
483                                         if test "$notrace" -ne 0; then
484                                                 OPENH323_BUILD="notrace"
485                                         else
486                                                 OPENH323_BUILD="opt"
487                                         fi
488                                         OPENH323_LIB="-l${OPENH323_PREFIX}"
489                                 else
490                                         OPENH323_BUILD="notrace"
491                                 fi
492                                 ;;
493                 esac
494                 AC_MSG_RESULT(${OPENH323_BUILD})
496                 AC_SUBST([OPENH323_SUFFIX])
497                 AC_SUBST([OPENH323_BUILD])
498         fi
502 # AST_FUNC_FORK
503 # -------------
504 AN_FUNCTION([fork],  [AST_FUNC_FORK])
505 AN_FUNCTION([vfork], [AST_FUNC_FORK])
506 AC_DEFUN([AST_FUNC_FORK],
507 [AC_REQUIRE([AC_TYPE_PID_T])dnl
508 AC_CHECK_HEADERS(vfork.h)
509 AC_CHECK_FUNCS(fork vfork)
510 if test "x$ac_cv_func_fork" = xyes; then
511   _AST_FUNC_FORK
512 else
513   ac_cv_func_fork_works=$ac_cv_func_fork
515 if test "x$ac_cv_func_fork_works" = xcross; then
516   case $host in
517     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
518       # Override, as these systems have only a dummy fork() stub
519       ac_cv_func_fork_works=no
520       ;;
521     *)
522       ac_cv_func_fork_works=yes
523       ;;
524   esac
525   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
527 ac_cv_func_vfork_works=$ac_cv_func_vfork
528 if test "x$ac_cv_func_vfork" = xyes; then
529   _AC_FUNC_VFORK
531 if test "x$ac_cv_func_fork_works" = xcross; then
532   ac_cv_func_vfork_works=$ac_cv_func_vfork
533   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
536 if test "x$ac_cv_func_vfork_works" = xyes; then
537   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
538 else
539   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
541 if test "x$ac_cv_func_fork_works" = xyes; then
542   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
544 ])# AST_FUNC_FORK
547 # _AST_FUNC_FORK
548 # -------------
549 AC_DEFUN([_AST_FUNC_FORK],
550   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
551     [AC_RUN_IFELSE(
552       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
553         [
554           /* By Ruediger Kuhlmann. */
555           return fork () < 0;
556         ])],
557       [ac_cv_func_fork_works=yes],
558       [ac_cv_func_fork_works=no],
559       [ac_cv_func_fork_works=cross])])]
560 )# _AST_FUNC_FORK
562 # AST_PROG_LD
563 # ----------
564 # find the pathname to the GNU or non-GNU linker
565 AC_DEFUN([AST_PROG_LD],
566 [AC_ARG_WITH([gnu-ld],
567     [AC_HELP_STRING([--with-gnu-ld],
568         [assume the C compiler uses GNU ld @<:@default=no@:>@])],
569     [test "$withval" = no || with_gnu_ld=yes],
570     [with_gnu_ld=no])
571 AC_REQUIRE([AST_PROG_SED])dnl
572 AC_REQUIRE([AC_PROG_CC])dnl
573 AC_REQUIRE([AC_CANONICAL_HOST])dnl
574 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
575 ac_prog=ld
576 if test "$GCC" = yes; then
577   # Check if gcc -print-prog-name=ld gives a path.
578   AC_MSG_CHECKING([for ld used by $CC])
579   case $host in
580   *-*-mingw*)
581     # gcc leaves a trailing carriage return which upsets mingw
582     ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
583   *)
584     ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
585   esac
586   case $ac_prog in
587     # Accept absolute paths.
588     [[\\/]]* | ?:[[\\/]]*)
589       re_direlt='/[[^/]][[^/]]*/\.\./'
590       # Canonicalize the pathname of ld
591       ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
592       while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
593         ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
594       done
595       test -z "$LD" && LD="$ac_prog"
596       ;;
597   "")
598     # If it fails, then pretend we aren't using GCC.
599     ac_prog=ld
600     ;;
601   *)
602     # If it is relative, then search for the first ld in PATH.
603     with_gnu_ld=unknown
604     ;;
605   esac
606 elif test "$with_gnu_ld" = yes; then
607   AC_MSG_CHECKING([for GNU ld])
608 else
609   AC_MSG_CHECKING([for non-GNU ld])
611 AC_CACHE_VAL(lt_cv_path_LD,
612 [if test -z "$LD"; then
613   lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
614   for ac_dir in $PATH; do
615     IFS="$lt_save_ifs"
616     test -z "$ac_dir" && ac_dir=.
617     if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
618       lt_cv_path_LD="$ac_dir/$ac_prog"
619       # Check to see if the program is GNU ld.  I'd rather use --version,
620       # but apparently some variants of GNU ld only accept -v.
621       # Break only if it was the GNU/non-GNU ld that we prefer.
622       case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
623       *GNU* | *'with BFD'*)
624         test "$with_gnu_ld" != no && break
625         ;;
626       *)
627         test "$with_gnu_ld" != yes && break
628         ;;
629       esac
630     fi
631   done
632   IFS="$lt_save_ifs"
633 else
634   lt_cv_path_LD="$LD" # Let the user override the test with a path.
635 fi])
636 LD="$lt_cv_path_LD"
637 if test -n "$LD"; then
638   AC_MSG_RESULT($LD)
639 else
640   AC_MSG_RESULT(no)
642 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
643 AST_PROG_LD_GNU
644 ])# AST_PROG_LD
647 # AST_PROG_LD_GNU
648 # --------------
649 AC_DEFUN([AST_PROG_LD_GNU],
650 [AC_REQUIRE([AST_PROG_EGREP])dnl
651 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
652 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
653 case `$LD -v 2>&1 </dev/null` in
654 *GNU* | *'with BFD'*)
655   lt_cv_prog_gnu_ld=yes
656   ;;
658   lt_cv_prog_gnu_ld=no
659   ;;
660 esac])
661 with_gnu_ld=$lt_cv_prog_gnu_ld
662 ])# AST_PROG_LD_GNU
664 # AST_PROG_EGREP
665 # -------------
666 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
667 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
668    [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
669     then ac_cv_prog_egrep='grep -E'
670     else ac_cv_prog_egrep='egrep'
671     fi])
672  EGREP=$ac_cv_prog_egrep
673  AC_SUBST([EGREP])
674 ])]) # AST_PROG_EGREP
676 # AST_PROG_SED
677 # -----------
678 # Check for a fully functional sed program that truncates
679 # as few characters as possible.  Prefer GNU sed if found.
680 AC_DEFUN([AST_PROG_SED],
681 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
682     [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
683      dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
684      ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
685      for ac_i in 1 2 3 4 5 6 7; do
686        ac_script="$ac_script$as_nl$ac_script"
687      done
688      echo "$ac_script" | sed 99q >conftest.sed
689      $as_unset ac_script || ac_script=
690      _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
691         [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
692                 ["$ac_path_SED" -f conftest.sed])])])
693  SED="$ac_cv_path_SED"
694  AC_SUBST([SED])dnl
695  rm -f conftest.sed
696 ])# AST_PROG_SED
698 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
700 dnl @summary figure out how to build C programs using POSIX threads
702 dnl This macro figures out how to build C programs using POSIX threads.
703 dnl It sets the PTHREAD_LIBS output variable to the threads library and
704 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
705 dnl C compiler flags that are needed. (The user can also force certain
706 dnl compiler flags/libs to be tested by setting these environment
707 dnl variables.)
709 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
710 dnl multi-threaded programs (defaults to the value of CC otherwise).
711 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
713 dnl NOTE: You are assumed to not only compile your program with these
714 dnl flags, but also link it with them as well. e.g. you should link
715 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
716 dnl $LIBS
718 dnl If you are only building threads programs, you may wish to use
719 dnl these variables in your default LIBS, CFLAGS, and CC:
721 dnl        LIBS="$PTHREAD_LIBS $LIBS"
722 dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
723 dnl        CC="$PTHREAD_CC"
725 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
726 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
727 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
729 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
730 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
731 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
732 dnl default action will define HAVE_PTHREAD.
734 dnl Please let the authors know if this macro fails on any platform, or
735 dnl if you have any other suggestions or comments. This macro was based
736 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
737 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
738 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
739 dnl We are also grateful for the helpful feedback of numerous users.
741 dnl @category InstalledPackages
742 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
743 dnl @version 2006-05-29
744 dnl @license GPLWithACException
746 AC_DEFUN([ACX_PTHREAD], [
747 AC_REQUIRE([AC_CANONICAL_HOST])
748 AC_LANG_SAVE
749 AC_LANG_C
750 acx_pthread_ok=no
752 # We used to check for pthread.h first, but this fails if pthread.h
753 # requires special compiler flags (e.g. on True64 or Sequent).
754 # It gets checked for in the link test anyway.
756 # First of all, check if the user has set any of the PTHREAD_LIBS,
757 # etcetera environment variables, and if threads linking works using
758 # them:
759 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
760         save_CFLAGS="$CFLAGS"
761         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
762         save_LIBS="$LIBS"
763         LIBS="$PTHREAD_LIBS $LIBS"
764         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
765         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
766         AC_MSG_RESULT($acx_pthread_ok)
767         if test x"$acx_pthread_ok" = xno; then
768                 PTHREAD_LIBS=""
769                 PTHREAD_CFLAGS=""
770         fi
771         LIBS="$save_LIBS"
772         CFLAGS="$save_CFLAGS"
775 # We must check for the threads library under a number of different
776 # names; the ordering is very important because some systems
777 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
778 # libraries is broken (non-POSIX).
780 # Create a list of thread flags to try.  Items starting with a "-" are
781 # C compiler flags, and other items are library names, except for "none"
782 # which indicates that we try without any flags at all, and "pthread-config"
783 # which is a program returning the flags for the Pth emulation library.
785 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
787 # The ordering *is* (sometimes) important.  Some notes on the
788 # individual items follow:
790 # pthreads: AIX (must check this before -lpthread)
791 # none: in case threads are in libc; should be tried before -Kthread and
792 #       other compiler flags to prevent continual compiler warnings
793 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
794 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
795 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
796 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
797 # -pthreads: Solaris/gcc
798 # -mthreads: Mingw32/gcc, Lynx/gcc
799 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
800 #      doesn't hurt to check since this sometimes defines pthreads too;
801 #      also defines -D_REENTRANT)
802 #      ... -mt is also the pthreads flag for HP/aCC
803 # pthread: Linux, etcetera
804 # --thread-safe: KAI C++
805 # pthread-config: use pthread-config program (for GNU Pth library)
807 case "${host_cpu}-${host_os}" in
808         *solaris*)
810         # On Solaris (at least, for some versions), libc contains stubbed
811         # (non-functional) versions of the pthreads routines, so link-based
812         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
813         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
814         # a function called by this macro, so we could check for that, but
815         # who knows whether they'll stub that too in a future libc.)  So,
816         # we'll just look for -pthreads and -lpthread first:
818         acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
819         ;;
820 esac
822 if test x"$acx_pthread_ok" = xno; then
823 for flag in $acx_pthread_flags; do
825         case $flag in
826                 none)
827                 AC_MSG_CHECKING([whether pthreads work without any flags])
828                 ;;
830                 -*)
831                 AC_MSG_CHECKING([whether pthreads work with $flag])
832                 PTHREAD_CFLAGS="$flag"
833                 ;;
835                 pthread-config)
836                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
837                 if test x"$acx_pthread_config" = xno; then continue; fi
838                 PTHREAD_CFLAGS="`pthread-config --cflags`"
839                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
840                 ;;
842                 *)
843                 AC_MSG_CHECKING([for the pthreads library -l$flag])
844                 PTHREAD_LIBS="-l$flag"
845                 ;;
846         esac
848         save_LIBS="$LIBS"
849         save_CFLAGS="$CFLAGS"
850         LIBS="$PTHREAD_LIBS $LIBS"
851         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
853         # Check for various functions.  We must include pthread.h,
854         # since some functions may be macros.  (On the Sequent, we
855         # need a special flag -Kthread to make this header compile.)
856         # We check for pthread_join because it is in -lpthread on IRIX
857         # while pthread_create is in libc.  We check for pthread_attr_init
858         # due to DEC craziness with -lpthreads.  We check for
859         # pthread_cleanup_push because it is one of the few pthread
860         # functions on Solaris that doesn't have a non-functional libc stub.
861         # We try pthread_create on general principles.
862         AC_TRY_LINK([#include <pthread.h>],
863                     [pthread_t th; pthread_join(th, 0);
864                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
865                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
866                     [acx_pthread_ok=yes])
868         LIBS="$save_LIBS"
869         CFLAGS="$save_CFLAGS"
871         AC_MSG_RESULT($acx_pthread_ok)
872         if test "x$acx_pthread_ok" = xyes; then
873                 break;
874         fi
876         PTHREAD_LIBS=""
877         PTHREAD_CFLAGS=""
878 done
881 # Various other checks:
882 if test "x$acx_pthread_ok" = xyes; then
883         save_LIBS="$LIBS"
884         LIBS="$PTHREAD_LIBS $LIBS"
885         save_CFLAGS="$CFLAGS"
886         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
888         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
889         AC_MSG_CHECKING([for joinable pthread attribute])
890         attr_name=unknown
891         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
892             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
893                         [attr_name=$attr; break])
894         done
895         AC_MSG_RESULT($attr_name)
896         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
897             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
898                                [Define to necessary symbol if this constant
899                                 uses a non-standard name on your system.])
900         fi
902         AC_MSG_CHECKING([if more special flags are required for pthreads])
903         flag=no
904         case "${host_cpu}-${host_os}" in
905             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
906             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
907         esac
908         AC_MSG_RESULT(${flag})
909         if test "x$flag" != xno; then
910             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
911         fi
913         LIBS="$save_LIBS"
914         CFLAGS="$save_CFLAGS"
916         # More AIX lossage: must compile with xlc_r or cc_r
917         if test x"$GCC" != xyes; then
918           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
919         else
920           PTHREAD_CC=$CC
921         fi
922 else
923         PTHREAD_CC="$CC"
926 AC_SUBST(PTHREAD_LIBS)
927 AC_SUBST(PTHREAD_CFLAGS)
928 AC_SUBST(PTHREAD_CC)
930 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
931 if test x"$acx_pthread_ok" = xyes; then
932         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
933         :
934 else
935         acx_pthread_ok=no
936         $2
938 AC_LANG_RESTORE
939 ])dnl ACX_PTHREAD