If there's a default, turn it on, even when the option isn't specified.
[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 # AST_OPTION_ONLY([option name], [option variable], [option description], [default value])
40 AC_DEFUN([AST_OPTION_ONLY],
41 [
42 AC_ARG_WITH([$1], AC_HELP_STRING([--with-$1=PATH], [use $3 in PATH]),
43         [
44         case ${withval} in
45         n|no)
46                 unset $2
47                 ;;
48         *)
49                 if test "x${$2}" = "x"; then
50                         m4_ifval($4, [$2="$4"], [:])
51                 else
52                         $2="${withval}"
53                 fi
54                 ;;
55         esac
56         ],
57         [m4_ifval($4, [$2="$4"])])
58 AC_SUBST($2)
59 ])
60
61 # AST_EXT_LIB_SETUP_DEPENDENT([package symbol name], [package friendly name], [master package symbol name], [master package option name])
62
63 AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
64 [
65 $1_DESCRIP="$2"
66 m4_ifval([$4], [$1_OPTION=$4])
67 m4_ifval([$3], [
68 for i in ${ac_mandatory_list}; do
69    if test "x$3" = "x$i"; then
70       ac_mandatory_list="${ac_mandatory_list} $1"
71       break
72    fi
73 done
74 ])
75 PBX_$1=0
76 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
77 AC_SUBST([$1_LIB])
78 AC_SUBST([$1_INCLUDE])
79 AC_SUBST([$1_DIR])
80 AC_SUBST([PBX_$1])
81 ])
82
83 # Check for existence of a given package ($1), either looking up a function
84 # in a library, or, if no function is supplied, only check for the
85 # existence of the header files.
86
87 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
88 #        [extra libs], [extra cflags], [version])
89 AC_DEFUN([AST_EXT_LIB_CHECK],
90 [
91 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
92    pbxlibdir=""
93    # if --with-$1=DIR has been specified, use it.
94    if test "x${$1_DIR}" != "x"; then
95       if test -d ${$1_DIR}/lib; then
96          pbxlibdir="-L${$1_DIR}/lib"
97       else
98          pbxlibdir="-L${$1_DIR}"
99       fi
100    fi
101    pbxfuncname="$3"
102    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
103       AST_$1_FOUND=yes
104    else
105       ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
106       CFLAGS="${CFLAGS} $6"
107       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
108       CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
109    fi
110
111    # now check for the header.
112    if test "${AST_$1_FOUND}" = "yes"; then
113       $1_LIB="${pbxlibdir} -l$2 $5"
114       # if --with-$1=DIR has been specified, use it.
115       if test "x${$1_DIR}" != "x"; then
116          $1_INCLUDE="-I${$1_DIR}/include"
117       fi
118       $1_INCLUDE="${$1_INCLUDE} $6"
119       if test "x$4" = "x" ; then        # no header, assume found
120          $1_HEADER_FOUND="1"
121       else                              # check for the header
122          ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
123          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
124          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
125          CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
126       fi
127       if test "x${$1_HEADER_FOUND}" = "x0" ; then
128          $1_LIB=""
129          $1_INCLUDE=""
130       else
131          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
132             $1_LIB=""
133          fi
134          PBX_$1=1
135          cat >>confdefs.h <<_ACEOF
136 [@%:@define] HAVE_$1 1
137 _ACEOF
138          m4_ifval([$7], [
139          cat >>confdefs.h <<_ACEOF
140 [@%:@define] HAVE_$1_VERSION $7
141 _ACEOF
142             ])
143       fi
144    fi
145 fi
146 m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
147 ])