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