when --without-<foo> is passed to the configure script, explicitly inform menuselect...
[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     AC_SUBST([$1_LIB])
33     AC_SUBST([$1_INCLUDE])
34     AC_SUBST([$1_DIR])
35     AC_SUBST([PBX_$1])
36 ])
37
38 # Check for existence of a given package ($1), either looking up a function
39 # in a library, or, if no function is supplied, only check for the
40 # existence of the header files.
41
42 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
43 #        [extra libs], [extra cflags], [version])
44 AC_DEFUN([AST_EXT_LIB_CHECK],
45 [
46 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
47    pbxlibdir=""
48    # if --with-$1=DIR has been specified, use it.
49    if test "x${$1_DIR}" != "x"; then
50       if test -d ${$1_DIR}/lib; then
51          pbxlibdir="-L${$1_DIR}/lib"
52       else
53          pbxlibdir="-L${$1_DIR}"
54       fi
55    fi
56    pbxfuncname="$3"
57    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
58       AST_$1_FOUND=yes
59    else
60       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
61    fi
62
63    # now check for the header.
64    if test "${AST_$1_FOUND}" = "yes"; then
65       $1_LIB="${pbxlibdir} -l$2 $5"
66       # if --with-$1=DIR has been specified, use it.
67       if test "x${$1_DIR}" != "x"; then
68          $1_INCLUDE="-I${$1_DIR}/include"
69       fi
70       $1_INCLUDE="${$1_INCLUDE} $6"
71       if test "x$4" = "x" ; then        # no header, assume found
72          $1_HEADER_FOUND="1"
73       else                              # check for the header
74          saved_cppflags="${CPPFLAGS}"
75          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
76          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
77          CPPFLAGS="${saved_cppflags}"
78       fi
79       if test "x${$1_HEADER_FOUND}" = "x0" ; then
80          $1_LIB=""
81          $1_INCLUDE=""
82       else
83          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
84             $1_LIB=""
85          fi
86          PBX_$1=1
87          # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
88          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
89          AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$7], [Define to indicate the ${$1_DESCRIP} library version])
90       fi
91    fi
92 fi
93 ])