dd31440412bc671b9bb37ca90c4b1a6619dd003b
[asterisk/asterisk.git] / acinclude.m4
1 # AST_GCC_ATTRIBUTE([attribute name])
2
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
4 [
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))
12 ])
13
14 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
15
16 AC_DEFUN([AST_EXT_LIB_SETUP],
17 [
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
33 ])
34 PBX_$1=0
35 AC_SUBST([$1_LIB])
36 AC_SUBST([$1_INCLUDE])
37 AC_SUBST([PBX_$1])
38 ])
39
40 # Check for existence of a given package ($1), looking up a function
41 # in a library, or, if no function is supplied, only check for the
42 # existence of the header files.
43 # Only check if PBX_$1 != 1, and set PBX_$1=1 and HAVE_$1 if found.
44 # Should be called after AST_EXT_LIB_SETUP($1, ...)
45
46 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data])
47
48 AC_DEFUN([AST_EXT_LIB_CHECK],
49 [
50 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
51    pbxlibdir=""
52    if test "x${$1_DIR}" != "x"; then
53       if test -d ${$1_DIR}/lib; then
54          pbxlibdir="-L${$1_DIR}/lib"
55       else
56          pbxlibdir="-L${$1_DIR}"
57       fi
58    fi
59    pbxfuncname="$3"
60    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
61       AST_$1_FOUND=yes
62    else
63       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
64    fi
65
66    if test "${AST_$1_FOUND}" = "yes"; then
67       $1_LIB="-l$2 $5"
68       $1_HEADER_FOUND="1"
69       if test "x${$1_DIR}" != "x"; then
70          $1_LIB="${pbxlibdir} ${$1_LIB}"
71          $1_INCLUDE="-I${$1_DIR}/include"
72          if test "x$4" != "x" ; then
73             AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0] )
74          fi
75       else
76          if test "x$4" != "x" ; then
77             AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0] )
78          fi
79       fi
80       if test "x${$1_HEADER_FOUND}" = "x0" ; then
81          if test ! -z "${$1_MANDATORY}" ; then
82             AC_MSG_NOTICE( ***)
83             AC_MSG_NOTICE( *** It appears that you do not have the $2 development package installed.)
84             AC_MSG_NOTICE( *** Please install it to include ${$1_DESCRIP} support, or re-run configure)
85             AC_MSG_NOTICE( *** without explicitly specifying --with-${$1_OPTION})
86             exit 1
87          fi
88          $1_LIB=""
89          $1_INCLUDE=""
90       else
91          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
92             $1_LIB=""
93          fi
94          PBX_$1=1
95          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define to indicate the ${$1_DESCRIP} library])
96       fi
97    elif test ! -z "${$1_MANDATORY}"; then
98       AC_MSG_NOTICE(***)
99       AC_MSG_NOTICE(*** The ${$1_DESCRIP} installation on this system appears to be broken.)
100       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
101       AC_MSG_NOTICE(*** without explicitly specifying --with-${$1_OPTION})
102       exit 1
103    fi
104 fi
105 ])
106
107
108 AC_DEFUN(
109 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
110    GNU_MAKE='Not Found' ;
111    GNU_MAKE_VERSION_MAJOR=0 ;
112    GNU_MAKE_VERSION_MINOR=0 ;
113    for a in make gmake gnumake ; do
114       if test -z "$a" ; then continue ; fi ;
115       if ( sh -c "$a --version" 2> /dev/null | grep GNU  2>&1 > /dev/null ) ;  then
116          GNU_MAKE=$a ;
117          GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
118          GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
119          break;
120       fi
121    done ;
122 ) ;
123 if test  "x$GNU_MAKE" = "xNot Found"  ; then
124    AC_MSG_ERROR( *** Please install GNU make.  It is required to build Asterisk!)
125    exit 1
126 fi
127 AC_SUBST([GNU_MAKE])
128 ])
129
130
131 AC_DEFUN(
132 [AST_CHECK_PWLIB], [
133 PWLIB_INCDIR=
134 PWLIB_LIBDIR=
135 if test "${PWLIBDIR:-unset}" != "unset" ; then
136   AC_CHECK_FILE(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
137 fi
138 if test "${HAS_PWLIB:-unset}" = "unset" ; then
139   if test "${OPENH323DIR:-unset}" != "unset"; then
140     AC_CHECK_FILE(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
141   fi
142   if test "${HAS_PWLIB:-unset}" != "unset" ; then
143     PWLIBDIR="${OPENH323DIR}/../pwlib"
144   else
145     AC_CHECK_FILE(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
146     if test "${HAS_PWLIB:-unset}" != "unset" ; then
147       PWLIBDIR="${HOME}/pwlib"
148     else
149       AC_CHECK_FILE(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
150       if test "${HAS_PWLIB:-unset}" != "unset" ; then
151         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
152         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
153           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
154         fi
155         PWLIB_INCDIR="/usr/local/include"
156         if test "x$LIB64" != "x"; then
157           PWLIB_LIBDIR="/usr/local/lib64"
158         else
159           PWLIB_LIBDIR="/usr/local/lib"
160         fi
161       else
162         AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
163         if test "${HAS_PWLIB:-unset}" != "unset" ; then
164           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
165           PWLIB_INCDIR="/usr/include"
166           if test "x$LIB64" != "x"; then
167                 PWLIB_LIBDIR="/usr/lib64"
168           else
169                 PWLIB_LIBDIR="/usr/lib"
170               fi
171         fi
172       fi
173     fi
174   fi
175 fi
176
177 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
178 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
179 #  exit
180 #fi
181
182 if test "${HAS_PWLIB:-unset}" != "unset" ; then
183   if test "${PWLIBDIR:-unset}" = "unset" ; then
184     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
185       PWLIBDIR=`$PTLIB_CONFIG --prefix`
186     else
187       echo "Cannot find ptlib-config - please install and try again"
188       exit
189     fi
190   fi
191
192   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
193     PWLIBDIR="/usr/share/pwlib"
194     PWLIB_INCDIR="/usr/include"
195     if test "x$LIB64" != "x"; then
196       PWLIB_LIBDIR="/usr/lib64"
197     else
198       PWLIB_LIBDIR="/usr/lib"
199     fi
200   fi
201   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
202     PWLIBDIR="/usr/local/share/pwlib"
203     PWLIB_INCDIR="/usr/local/include"
204     if test "x$LIB64" != "x"; then
205       PWLIB_LIBDIR="/usr/local/lib64"
206     else
207       PWLIB_LIBDIR="/usr/local/lib"
208     fi
209   fi
210
211   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
212     PWLIB_INCDIR="${PWLIBDIR}/include"
213   fi
214   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
215     PWLIB_LIBDIR="${PWLIBDIR}/lib"
216   fi
217
218   AC_SUBST([PWLIBDIR])
219   AC_SUBST([PWLIB_INCDIR])
220   AC_SUBST([PWLIB_LIBDIR])
221 fi
222 ])
223
224
225 AC_DEFUN(
226 [AST_CHECK_OPENH323_PLATFORM], [
227 PWLIB_OSTYPE=
228 case "$host_os" in
229   linux*)          PWLIB_OSTYPE=linux ;
230                 ;;
231   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
232                 ;;
233   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
234                                    ENDLDLIBS="-lossaudio" ;
235                 ;;
236   netbsd* )        PWLIB_OSTYPE=NetBSD ;
237                                    ENDLDLIBS="-lossaudio" ;
238                 ;;
239   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
240                 ;;
241   darwin* )            PWLIB_OSTYPE=Darwin ;
242                 ;;
243   beos*)           PWLIB_OSTYPE=beos ;
244                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
245                 ;;
246   cygwin*)         PWLIB_OSTYPE=cygwin ;
247                 ;;
248   mingw*)              PWLIB_OSTYPE=mingw ;
249                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
250                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
251                 ;;
252   * )                  PWLIB_OSTYPE="$host_os" ;
253                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
254                 ;;
255 esac
256
257 PWLIB_MACHTYPE=
258 case "$host_cpu" in
259    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
260                    ;;
261
262    x86_64)         PWLIB_MACHTYPE=x86_64 ;
263                    P_64BIT=1 ;
264                    LIB64=1 ;
265                    ;;
266
267    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
268                    P_64BIT=1 ;
269                    ;;
270
271    sparc )         PWLIB_MACHTYPE=sparc ;
272                    ;;
273
274    powerpc )       PWLIB_MACHTYPE=ppc ;
275                    ;;
276
277    ppc )           PWLIB_MACHTYPE=ppc ;
278                    ;;
279
280    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
281                    P_64BIT=1 ;
282                    LIB64=1 ;
283                    ;;
284
285    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
286                    P_64BIT=1 ;
287                    LIB64=1 ;
288                    ;;
289
290    ia64)           PWLIB_MACHTYPE=ia64 ;
291                    P_64BIT=1 ;
292                    ;;
293
294    s390x)          PWLIB_MACHTYPE=s390x ;
295                    P_64BIT=1 ;
296                    LIB64=1 ;
297                    ;;
298
299    s390)           PWLIB_MACHTYPE=s390 ;
300                    ;;
301
302    * )             PWLIB_MACHTYPE="$host_cpu";
303                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
304 esac
305
306 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
307
308 AC_SUBST([PWLIB_PLATFORM])
309 ])
310
311
312 AC_DEFUN(
313 [AST_CHECK_OPENH323], [
314 OPENH323_INCDIR=
315 OPENH323_LIBDIR=
316 if test "${OPENH323DIR:-unset}" != "unset" ; then
317   AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
318 fi
319 if test "${HAS_OPENH323:-unset}" = "unset" ; then
320   AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
321   if test "${HAS_OPENH323:-unset}" != "unset" ; then
322     OPENH323DIR="${PWLIBDIR}/../openh323"
323     AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
324   else
325     AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
326     if test "${HAS_OPENH323:-unset}" != "unset" ; then
327       OPENH323DIR="${HOME}/openh323"
328     else
329       AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
330       if test "${HAS_OPENH323:-unset}" != "unset" ; then
331         OPENH323DIR="/usr/local/share/openh323"
332         OPENH323_INCDIR="/usr/local/include/openh323"
333         if test "x$LIB64" != "x"; then
334           OPENH323_LIBDIR="/usr/local/lib64"
335         else
336           OPENH323_LIBDIR="/usr/local/lib"
337         fi
338       else
339         AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
340         if test "${HAS_OPENH323:-unset}" != "unset" ; then
341           OPENH323DIR="/usr/share/openh323"
342           OPENH323_INCDIR="/usr/include/openh323"
343           if test "x$LIB64" != "x"; then
344             OPENH323_LIBDIR="/usr/lib64"
345           else
346             OPENH323_LIBDIR="/usr/lib"
347           fi
348         fi
349       fi
350     fi
351   fi
352 fi
353
354 if test "${HAS_OPENH323:-unset}" != "unset" ; then
355   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
356     OPENH323_INCDIR="${OPENH323DIR}/include"
357   fi
358   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
359     OPENH323_LIBDIR="${OPENH323DIR}/lib"
360   fi
361
362   AC_SUBST([OPENH323DIR])
363   AC_SUBST([OPENH323_INCDIR])
364   AC_SUBST([OPENH323_LIBDIR])
365 fi
366 ])
367
368
369 AC_DEFUN(
370 [AST_CHECK_PWLIB_VERSION], [
371         if test "${HAS_$2:-unset}" != "unset"; then
372                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
373                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
374                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
375                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
376                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
377                 let $2_REQ=$4*10000+$5*100+$6
378
379                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
380                 if test ${$2_VER} -lt ${$2_REQ}; then
381                         AC_MSG_RESULT(no)
382                         unset HAS_$2
383                 else
384                         AC_MSG_RESULT(yes)
385                 fi
386         fi
387 ])
388
389
390 AC_DEFUN(
391 [AST_CHECK_PWLIB_BUILD], [
392         if test "${HAS_$2:-unset}" != "unset"; then
393            AC_MSG_CHECKING($1 installation validity)
394
395            saved_cppflags="${CPPFLAGS}"
396            saved_libs="${LIBS}"
397            LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
398            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
399
400            AC_LANG_PUSH([C++])
401
402            AC_LINK_IFELSE(
403                 [AC_LANG_PROGRAM([$4],[$5])],
404                 [       AC_MSG_RESULT(yes) 
405                         ac_cv_lib_$2="yes" 
406                 ],
407                 [       AC_MSG_RESULT(no) 
408                         ac_cv_lib_$2="no" 
409                 ]
410                 )
411
412            AC_LANG_POP([C++])
413
414            LIBS="${saved_libs}"
415            CPPFLAGS="${saved_cppflags}"
416
417            if test "${ac_cv_lib_$2}" = "yes"; then
418               if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
419                  $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
420               else
421                  $2_LIB="-l${PLATFORM_$2}"
422               fi
423               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
424                  $2_INCLUDE="-I${$2_INCDIR}"
425               fi
426                   PBX_$2=1
427                   AC_DEFINE([HAVE_$2], 1, [$3])
428            fi
429         fi
430 ])
431
432 AC_DEFUN(
433 [AST_CHECK_OPENH323_BUILD], [
434         if test "${HAS_OPENH323:-unset}" != "unset"; then
435                 AC_MSG_CHECKING(OpenH323 build option)
436                 OPENH323_SUFFIX=
437                 files=`ls -l ${OPENH323_LIBDIR}/libh323_${PWLIB_PLATFORM}_*.so*`
438                 libfile=
439                 if test -n "$files"; then
440                         for f in $files; do
441                                 if test -f $f -a ! -L $f; then
442                                         libfile=`basename $f`
443                                         break;
444                                 fi
445                         done
446                 fi
447                 if test "${libfile:-unset}" != "unset"; then
448                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/libh323_${PWLIB_PLATFORM}_\(@<:@^.@:>@*\)\..*/\1/'"`
449                 fi
450                 case "${OPENH323_SUFFIX}" in
451                         n)
452                                 OPENH323_BUILD="notrace";;
453                         r)
454                                 OPENH323_BUILD="opt";;
455                         d)
456                                 OPENH323_BUILD="debug";;
457                         *)
458                                 OPENH323_BUILD="notrace";;
459                 esac
460                 AC_MSG_RESULT(${OPENH323_BUILD})
461
462                 AC_SUBST([OPENH323_SUFFIX])
463                 AC_SUBST([OPENH323_BUILD])
464         fi
465 ])
466
467
468 # AST_FUNC_FORK
469 # -------------
470 AN_FUNCTION([fork],  [AST_FUNC_FORK])
471 AN_FUNCTION([vfork], [AST_FUNC_FORK])
472 AC_DEFUN([AST_FUNC_FORK],
473 [AC_REQUIRE([AC_TYPE_PID_T])dnl
474 AC_CHECK_HEADERS(vfork.h)
475 AC_CHECK_FUNCS(fork vfork)
476 if test "x$ac_cv_func_fork" = xyes; then
477   _AST_FUNC_FORK
478 else
479   ac_cv_func_fork_works=$ac_cv_func_fork
480 fi
481 if test "x$ac_cv_func_fork_works" = xcross; then
482   case $host in
483     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* )
484       # Override, as these systems have only a dummy fork() stub
485       ac_cv_func_fork_works=no
486       ;;
487     *)
488       ac_cv_func_fork_works=yes
489       ;;
490   esac
491   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
492 fi
493 ac_cv_func_vfork_works=$ac_cv_func_vfork
494 if test "x$ac_cv_func_vfork" = xyes; then
495   _AC_FUNC_VFORK
496 fi;
497 if test "x$ac_cv_func_fork_works" = xcross; then
498   ac_cv_func_vfork_works=$ac_cv_func_vfork
499   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
500 fi
501
502 if test "x$ac_cv_func_vfork_works" = xyes; then
503   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
504 else
505   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
506 fi
507 if test "x$ac_cv_func_fork_works" = xyes; then
508   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
509 fi
510 ])# AST_FUNC_FORK
511
512
513 # _AST_FUNC_FORK
514 # -------------
515 AC_DEFUN([_AST_FUNC_FORK],
516   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
517     [AC_RUN_IFELSE(
518       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
519         [
520           /* By Ruediger Kuhlmann. */
521           return fork () < 0;
522         ])],
523       [ac_cv_func_fork_works=yes],
524       [ac_cv_func_fork_works=no],
525       [ac_cv_func_fork_works=cross])])]
526 )# _AST_FUNC_FORK