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)
7 # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
9 AC_DEFUN([AST_EXT_LIB_SETUP],
14 AC_ARG_WITH([$3], AS_HELP_STRING([--with-$3=PATH],[use $2 files in PATH$4]),
19 # -1 is a magic value used by menuselect to know that the package
20 # was disabled, other than 'not found'
24 ac_mandatory_list="${ac_mandatory_list} $1"
28 ac_mandatory_list="${ac_mandatory_list} $1"
32 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
34 AC_SUBST([$1_INCLUDE])
39 # AST_OPTION_ONLY([option name], [option variable], [option description], [default value])
40 AC_DEFUN([AST_OPTION_ONLY],
42 AC_ARG_WITH([$1], AS_HELP_STRING([--with-$1=PATH], [use $3 in PATH]),
49 if test "x${withval}" = "x"; then
50 m4_ifval($4, [$2="$4"], [:])
57 [m4_ifval($4, [$2="$4"], [:])])
61 # Setup required dependent package
62 # AST_EXT_LIB_SETUP_DEPENDENT([dependent package symbol name], [dependent package friendly name], [master package symbol name], [master package name])
64 AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
67 m4_ifval([$4], [$1_OPTION=$4])
69 for i in ${ac_mandatory_list}; do
70 if test "x$3" = "x$i"; then
71 ac_mandatory_list="${ac_mandatory_list} $1"
78 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
80 AC_SUBST([$1_INCLUDE])
85 # Setup optional dependent package
86 # AST_EXT_LIB_SETUP_OPTIONAL([optional package symbol name], [optional package friendly name], [master package symbol name], [master package name])
88 AC_DEFUN([AST_EXT_LIB_SETUP_OPTIONAL],
91 m4_ifval([$4], [$1_OPTION=$4])
92 m4_ifval([$3], [$1_DIR=${$3_DIR}
95 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if $3 has the $2 feature.])
97 AC_SUBST([$1_INCLUDE])
102 # Check for existence of a given package ($1), either looking up a function
103 # in a library, or, if no function is supplied, only check for the
104 # existence of the header files.
106 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
107 # [extra libs], [extra cflags], [version])
108 AC_DEFUN([AST_EXT_LIB_CHECK],
110 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
112 # if --with-$1=DIR has been specified, use it.
113 if test "x${$1_DIR}" != "x"; then
114 if test -d ${$1_DIR}/lib; then
115 pbxlibdir="-L${$1_DIR}/lib"
117 pbxlibdir="-L${$1_DIR}"
121 ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
122 CFLAGS="${CFLAGS} $6"
123 AC_CHECK_LIB([$2], [$3], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
124 CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
126 # empty lib, assume only headers
130 # now check for the header.
131 if test "${AST_$1_FOUND}" = "yes"; then
132 $1_LIB="${pbxlibdir} -l$2 $5"
133 # if --with-$1=DIR has been specified, use it.
134 if test "x${$1_DIR}" != "x"; then
135 $1_INCLUDE="-I${$1_DIR}/include"
137 $1_INCLUDE="${$1_INCLUDE} $6"
139 # check for the header
140 ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
141 CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
142 AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
143 CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
145 # no header, assume found
148 if test "x${$1_HEADER_FOUND}" = "x0" ; then
153 # only checking headers -> no library
157 cat >>confdefs.h <<_ACEOF
158 [@%:@define] HAVE_$1 1
161 cat >>confdefs.h <<_ACEOF
162 [@%:@define] HAVE_$1_VERSION $7
168 m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
171 # Check if the previously discovered library can be dynamically linked.
173 # AST_EXT_LIB_CHECK_SHARED([package], [library], [function], [header],
174 # [extra libs], [extra cflags], [action-if-true], [action-if-false])
175 AC_DEFUN([AST_EXT_LIB_CHECK_SHARED],
177 if test "x${PBX_$1}" = "x1"; then
178 ast_ext_lib_check_shared_saved_libs="${LIBS}"
179 ast_ext_lib_check_shared_saved_ldflags="${LDFLAGS}"
180 ast_ext_lib_check_shared_saved_cflags="${CFLAGS}"
181 LIBS="${LIBS} ${$1_LIB} $5"
182 LDFLAGS="${LDFLAGS} -shared -fPIC"
183 CFLAGS="${CFLAGS} ${$1_INCLUDE} $6"
184 AC_MSG_CHECKING(for the ability of -l$2 to be linked in a shared object)
201 CFLAGS="${ast_ext_lib_check_shared_saved_cflags}"
202 LDFLAGS="${ast_ext_lib_check_shared_saved_ldflags}"
203 LIBS="${ast_ext_lib_check_shared_saved_libs}"