Merged revisions 151240 via svnmerge from
[asterisk/asterisk.git] / autoconf / ast_ext_lib.m4
1 # Helper function to setup variables for a package.
2 # $1 -> the package name. Used in configure.ac and also as a prefix
3 #       for the variables ($1_DIR, $1_INCLUDE, $1_LIB) in makeopts
4 # $3 -> option name, used in --with-$3 or --without-$3 when calling configure.
5 # $2 and $4 are just text describing the package (short and long form)
6
7 # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
8
9 AC_DEFUN([AST_EXT_LIB_SETUP],
10 [
11     $1_DESCRIP="$2"
12     $1_OPTION="$3"
13     AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),
14     [
15         case ${withval} in
16         n|no)
17         USE_$1=no
18         ;;
19         y|ye|yes)
20         ac_mandatory_list="${ac_mandatory_list} $1"
21         ;;
22         *)
23         $1_DIR="${withval}"
24         ac_mandatory_list="${ac_mandatory_list} $1"
25         ;;
26         esac
27     ])
28     PBX_$1=0
29     AC_SUBST([$1_LIB])
30     AC_SUBST([$1_INCLUDE])
31     AC_SUBST([$1_DIR])
32     AC_SUBST([PBX_$1])
33 ])
34
35 # Check for existence of a given package ($1), either looking up a function
36 # in a library, or, if no function is supplied, only check for the
37 # existence of the header files.
38
39 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
40 #        [extra libs], [extra cflags], [version])
41 AC_DEFUN([AST_EXT_LIB_CHECK],
42 [
43 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
44    pbxlibdir=""
45    # if --with-$1=DIR has been specified, use it.
46    if test "x${$1_DIR}" != "x"; then
47       if test -d ${$1_DIR}/lib; then
48          pbxlibdir="-L${$1_DIR}/lib"
49       else
50          pbxlibdir="-L${$1_DIR}"
51       fi
52    fi
53    pbxfuncname="$3"
54    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
55       AST_$1_FOUND=yes
56    else
57       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
58    fi
59
60    # now check for the header.
61    if test "${AST_$1_FOUND}" = "yes"; then
62       $1_LIB="${pbxlibdir} -l$2 $5"
63       # if --with-$1=DIR has been specified, use it.
64       if test "x${$1_DIR}" != "x"; then
65          $1_INCLUDE="-I${$1_DIR}/include"
66       fi
67       $1_INCLUDE="${$1_INCLUDE} $6"
68       if test "x$4" = "x" ; then        # no header, assume found
69          $1_HEADER_FOUND="1"
70       else                              # check for the header
71          saved_cppflags="${CPPFLAGS}"
72          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
73          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
74          CPPFLAGS="${saved_cppflags}"
75       fi
76       if test "x${$1_HEADER_FOUND}" = "x0" ; then
77          $1_LIB=""
78          $1_INCLUDE=""
79       else
80          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
81             $1_LIB=""
82          fi
83          PBX_$1=1
84          # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
85          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
86          AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the ${$1_DESCRIP} library version])
87       fi
88    fi
89 fi
90 ])