Merged revisions 279502 via svnmerge from
[asterisk/asterisk.git] / autoconf / ast_ext_lib.m4
index 3d9d039..28a5521 100644 (file)
@@ -30,13 +30,34 @@ AC_DEFUN([AST_EXT_LIB_SETUP],
        esac
     ])
     AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
-    AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])
     AC_SUBST([$1_LIB])
     AC_SUBST([$1_INCLUDE])
     AC_SUBST([$1_DIR])
     AC_SUBST([PBX_$1])
 ])
 
+# AST_OPTION_ONLY([option name], [option variable], [option description], [default value])
+AC_DEFUN([AST_OPTION_ONLY],
+[
+AC_ARG_WITH([$1], AC_HELP_STRING([--with-$1=PATH], [use $3 in PATH]),
+       [
+       case ${withval} in
+       n|no)
+               unset $2
+               ;;
+       *)
+               if test "x${withval}" = "x"; then
+                       m4_ifval($4, [$2="$4"], [:])
+               else
+                       $2="${withval}"
+               fi
+               ;;
+       esac
+       ],
+       [m4_ifval($4, [$2="$4"])])
+AC_SUBST($2)
+])
+
 # AST_EXT_LIB_SETUP_DEPENDENT([package symbol name], [package friendly name], [master package symbol name], [master package option name])
 
 AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
@@ -81,7 +102,10 @@ if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
       AST_$1_FOUND=yes
    else
-      AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} $6"
+      AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
    fi
 
    # now check for the header.
@@ -95,10 +119,10 @@ if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
       if test "x$4" = "x" ; then       # no header, assume found
          $1_HEADER_FOUND="1"
       else                             # check for the header
-         saved_cppflags="${CPPFLAGS}"
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
-         CPPFLAGS="${saved_cppflags}"
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
       fi
       if test "x${$1_HEADER_FOUND}" = "x0" ; then
          $1_LIB=""
@@ -110,9 +134,14 @@ if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
          PBX_$1=1
          cat >>confdefs.h <<_ACEOF
 [@%:@define] HAVE_$1 1
+_ACEOF
+         m4_ifval([$7], [
+         cat >>confdefs.h <<_ACEOF
 [@%:@define] HAVE_$1_VERSION $7
 _ACEOF
+            ])
       fi
    fi
 fi
+m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
 ])