Merged revisions 214357 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     PBX_$1=0
14     AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH$4]),
15     [
16         case ${withval} in
17         n|no)
18         USE_$1=no
19         # -1 is a magic value used by menuselect to know that the package
20         # was disabled, other than 'not found'
21         PBX_$1=-1
22         ;;
23         y|ye|yes)
24         ac_mandatory_list="${ac_mandatory_list} $1"
25         ;;
26         *)
27         $1_DIR="${withval}"
28         ac_mandatory_list="${ac_mandatory_list} $1"
29         ;;
30         esac
31     ])
32     AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
33     AC_SUBST([$1_LIB])
34     AC_SUBST([$1_INCLUDE])
35     AC_SUBST([$1_DIR])
36     AC_SUBST([PBX_$1])
37 ])
38
39 # Check for existence of a given package ($1), either looking up a function
40 # in a library, or, if no function is supplied, only check for the
41 # existence of the header files.
42
43 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
44 #        [extra libs], [extra cflags], [version])
45 AC_DEFUN([AST_EXT_LIB_CHECK],
46 [
47 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
48    pbxlibdir=""
49    # if --with-$1=DIR has been specified, use it.
50    if test "x${$1_DIR}" != "x"; then
51       if test -d ${$1_DIR}/lib; then
52          pbxlibdir="-L${$1_DIR}/lib"
53       else
54          pbxlibdir="-L${$1_DIR}"
55       fi
56    fi
57    pbxfuncname="$3"
58    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
59       AST_$1_FOUND=yes
60    else
61       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
62    fi
63
64    # now check for the header.
65    if test "${AST_$1_FOUND}" = "yes"; then
66       $1_LIB="${pbxlibdir} -l$2 $5"
67       # if --with-$1=DIR has been specified, use it.
68       if test "x${$1_DIR}" != "x"; then
69          $1_INCLUDE="-I${$1_DIR}/include"
70       fi
71       $1_INCLUDE="${$1_INCLUDE} $6"
72       if test "x$4" = "x" ; then        # no header, assume found
73          $1_HEADER_FOUND="1"
74       else                              # check for the header
75          saved_cppflags="${CPPFLAGS}"
76          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
77          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
78          CPPFLAGS="${saved_cppflags}"
79       fi
80       if test "x${$1_HEADER_FOUND}" = "x0" ; then
81          $1_LIB=""
82          $1_INCLUDE=""
83       else
84          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
85             $1_LIB=""
86          fi
87          PBX_$1=1
88          if test "x${$1_OPTION}" = "x"; then
89             dnl Ensure that we have an autoheader, when AST_EXT_LIB_SETUP was
90             dnl not called.  Note that we cannot use shell substitution in the
91             dnl description, because the shell is never invoked when rendering
92             dnl the autoheader.  Only m4 substitutions will expand correctly.
93             AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define to 1 to indicate $1 functionality.])
94             AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the $1 library version])
95          else
96             cat >>confdefs.h <<_ACEOF
97 [@%:@define] HAVE_$1 1
98 [@%:@define] HAVE_$1_VERSION $7
99 _ACEOF
100          fi
101       fi
102    fi
103 fi
104 ])