Index: Makefile.am
===================================================================
--- Makefile.am	(revision 8326)
+++ Makefile.am	(working copy)
@@ -130,8 +130,15 @@
 libs/libteletone/src/libteletone.h\
 src/include/switch_odbc.h
 
+if !USE_SYSTEM_APR
 CORE_CFLAGS     = `$(switch_srcdir)/libs/apr/apr-1-config --cflags --cppflags --includes`
 CORE_CFLAGS    += `$(switch_srcdir)/libs/apr-util/apu-1-config --includes`
+endif
+
+if USE_SYSTEM_APR
+CORE_CFLAGS     = $(APR_CFLAGS) $(APR_UTIL_CFLAGS)
+endif
+
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/stfu
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/sqlite
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/pcre
@@ -139,7 +146,14 @@
 CORE_CFLAGS    += -I$(switch_srcdir)/libs/srtp/crypto/include
 CORE_CFLAGS    += $(RESAMPLE_CFLAGS)
 
+if !USE_SYSTEM_APR
 CORE_LIBS      = libs/apr-util/libaprutil-1.la libs/apr/libapr-1.la
+endif
+
+if USE_SYSTEM_APR
+CORE_LIBS      = $(APR_UTIL_LIBS) $(APR_LIBS)
+endif
+
 CORE_LIBS     += libs/sqlite/libsqlite3.la libs/pcre/libpcre.la
 CORE_LIBS     += libs/srtp/libsrtp.la $(RESAMPLE_LIB)
 
@@ -160,22 +174,27 @@
 nodist_freeswitch_SOURCES = src/include/switch_version.h 
 freeswitch_CFLAGS = $(AM_CFLAGS) $(CORE_CFLAGS)
 freeswitch_LDFLAGS = $(AM_LDFLAGS) -rpath $(libdir)
-freeswitch_LDADD = libfreeswitch.la libs/apr/libapr-1.la
-if ADD_LIBEDIT
-freeswitch_CFLAGS    += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
-freeswitch_LDADD      += libs/libedit/src/.libs/libedit.a
+freeswitch_LDADD = libfreeswitch.la
+
+if !USE_SYSTEM_APR
+freeswitch_LDADD += libs/apr/libapr-1.la
 endif
 
+if USE_SYSTEM_APR
+freeswitch_LDADD += $(APR_LIBS)
+endif
 
 if ADD_LIBEDIT
-CORE_CFLAGS    += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
-CORE_LIBS      += libs/libedit/src/.libs/libedit.a
+CORE_CFLAGS       += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
+CORE_LIBS         += libs/libedit/src/.libs/libedit.a
+freeswitch_CFLAGS += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
+freeswitch_LDADD  += libs/libedit/src/.libs/libedit.a
 endif
 
 if ADD_ODBC
-CORE_CFLAGS    += -DSWITCH_HAVE_ODBC
+CORE_CFLAGS              += -DSWITCH_HAVE_ODBC
 libfreeswitch_la_SOURCES += src/switch_odbc.c
-libfreeswitch_la_LDFLAGS     += -Wl,-lodbc
+libfreeswitch_la_LDFLAGS += -Wl,-lodbc
 endif
 
 bin_SCRIPTS = scripts/gentls_cert scripts/fsxs
Index: configure.in
===================================================================
--- configure.in	(revision 8326)
+++ configure.in	(working copy)
@@ -31,11 +31,13 @@
 AC_SUBST(switch_builddir)
 
 # Where to install the modules
-AC_ARG_WITH(modinstdir, [   --with-modinstdir (default=$prefix/mod)], modinstdir=$withval, modinstdir="${prefix}/mod")
+AC_ARG_WITH([modinstdir], [AS_HELP_STRING([--with-modinstdir=DIR],[(default=$prefix/mod)])], [modinstdir="$withval"], [modinstdir="${prefix}/mod"])
+if test "$modinstdir" = "yes" -o "$modinstdir" = "no"; then
+	AC_MSG_ERROR([wrong value for --with-modinstdir])
+fi
+AC_SUBST([modinstdir])
+AC_DEFINE_UNQUOTED([SWITCH_MOD_DIR], ["${modinstdir}"], [where to install the modules to])
 
-AC_SUBST(modinstdir)
-AC_DEFINE_UNQUOTED([SWITCH_MOD_DIR],"${modinstdir}",[where to install the modules to])
-
 #Set default language
 AC_LANG_C
 # Checks for programs.
@@ -143,18 +145,19 @@
 fi
 
 #  Enable debugging
-AC_ARG_ENABLE(debug,
-[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"])
+AC_ARG_ENABLE([debug],
+	[AC_HELP_STRING([--enable-debug], [build with debug information])],
+	[enable_debug="$enableval"],
+	[enable_debug="yes"])
 
 if test "${enable_debug}" = "yes"; then
-        AC_DEFINE([DEBUG],[],[Enable extra debugging.])
-        AX_CFLAGS_WARN_ALL_ANSI
+	AC_DEFINE([DEBUG],[],[Enable extra debugging.])
+	AX_CFLAGS_WARN_ALL_ANSI
 
 	if test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
-	    APR_ADDTO(SWITCH_AM_CFLAGS, -g -ggdb)
-	    export DEBUG_CFLAGS="-g -ggdb"
+		APR_ADDTO(SWITCH_AM_CFLAGS, -g -ggdb)
+		export DEBUG_CFLAGS="-g -ggdb"
 	fi
-
 fi
 
 
@@ -406,11 +409,15 @@
 LIBCURL_CHECK_CONFIG([yes], [7.13.0], [LIBCURL_DEPS=''], [LIBCURL_DEPS='${switch_srcdir}/libs/curl/lib/libcurl.la';LIBCURL='${switch_srcdir}/libs/curl/lib/libcurl.la';LIBCURL_CPPFLAGS='-I${switch_srcdir}/libs/curl/include'])
 AC_SUBST(LIBCURL_DEPS)
 
-AC_ARG_ENABLE(core-odbc-support,     
-	[  --enable-core-odbc-support         Compile with ODBC Support],,[enable_core_odbc_support="no"])
+AC_ARG_ENABLE([core-odbc-support],
+	[AS_HELP_STRING([--enable-core-odbc-support], [Compile with ODBC Support])],
+	[enable_core_odbc_support="$enableval"],
+	[enable_core_odbc_support="no"])
 
-AC_ARG_ENABLE(core-libedit-support,     
-	[  --disable-core-libedit-support         Compile without libedit Support],,[enable_core_libedit_support="yes"])
+AC_ARG_ENABLE([core-libedit-support],
+	[AS_HELP_STRING([--disable-core-libedit-support], [Compile without libedit Support])],
+	[enable_core_libedit_support="$enableval"],
+	[enable_core_libedit_support="yes"])
 
 if test "$enable_core_libedit_support" = "yes" ; then
     AC_CHECK_LIB(ncurses, tgetent,,
@@ -418,18 +425,297 @@
           [AC_MSG_ERROR([libtermcap, libcurses or libncurses are required!])] )] )
 fi
 
-AX_CHECK_JAVA
-
 AM_CONDITIONAL([ADD_ODBC],[test "x$enable_core_odbc_support" != "xno"])
 AM_CONDITIONAL([ADD_LIBEDIT],[test "x$enable_core_libedit_support" != "xno"])
 AM_CONDITIONAL([HAVE_MYSQL],[test "$found_mysql" = "yes"])
 
+newline='
+'
+
+#######################################################
+# Core dependencies
 #
+
+#
+# apr libs
+#
+AC_ARG_WITH(
+	[system-apr],
+	[AS_HELP_STRING([--with-system-apr], [Use system APR instead of bundled version (experts only!])],
+	[with_system_apr="$withval"],
+	[with_system_apr="no"]
+)
+
+AC_ARG_WITH(
+	[apr-config],
+	[AS_HELP_STRING([--with-apr-config@<:@=PATH@:>@], [Location of apr-config])],
+	[with_apr_config="$withval"],
+	[with_apr_config="no"]
+)
+
+AC_ARG_WITH(
+	[apu-config],
+	[AS_HELP_STRING([--with-apu-config@<:@=PATH@:>@], [Location of apu-config])],
+	[with_apr_util_config="$withval"],
+	[with_apr_util_config="no"]
+)
+
+if test "$with_system_apr" != "no"
+then
+	save_CFLAGS="$CFLAGS"
+	save_LIBS="$LIBS"
+
+	AC_MSG_RESULT([${newline}* Checking for APR])
+
+	# apr checks here
+	if test "$with_apr_config" != "yes" -a "$with_apr_config" != "no"; then
+		AC_MSG_CHECKING([for apr-config])
+		if test ! -x "$with_apr_config" ; then
+			AC_MSG_ERROR([Specified apr-config does not exist or is not executable: $with_apr_config])
+		fi
+		AC_MSG_RESULT([$with_apr_config])
+		AC_SUBST([APR_CONFIG], ["$with_apr_config"])
+	else
+		AC_PATH_PROGS([APR_CONFIG], ["apr-1-config" "apr-config-1" "apr-config"], [AC_MSG_ERROR([apr-config not found, try using --with-apr-config])], ["$PATH:/usr/bin:/usr/local/bin"])
+	fi
+
+	AC_MSG_CHECKING([apr version])
+	APR_VERSION="`$APR_CONFIG --version`"
+	AC_MSG_RESULT([$APR_VERSION])
+
+	ver_major="`echo $APR_VERSION | cut -d'.' -f1`"
+	ver_minor="`echo $APR_VERSION | cut -d'.' -f2`"
+	ver_patch="`echo $APR_VERSION | cut -d'.' -f3`"
+
+	if test $ver_major -ne 1 -o $ver_minor -ne 2 -o $ver_patch -lt 10 ; then
+		AC_MSG_ERROR([Need >=apr-1.2.10])
+	fi
+
+	APR_CFLAGS="`$APR_CONFIG --cflags --cppflags --includes`"
+	APR_LIBS="`$APR_CONFIG --link-libtool --libs`"
+
+	# check apr-util
+	if test "$with_apr_util_config" != "yes" -a "$with_apr_util_config" != "no"; then
+		AC_MSG_CHECKING([for apr-util-config])
+		if test ! -x "$with_apr_util_config" ; then
+			AC_MSG_ERROR([Specified apu-config does not exist or is not executable: $with_apr_util_config])
+		fi
+		AC_MSG_RESULT([$with_apr_util_config])
+		AC_SUBST([APR_UTIL_CONFIG], ["$with_apr_util_config"])
+	else
+		AC_PATH_PROGS([APR_UTIL_CONFIG], ["apu-1-config" "apu-config-1" "apu-config"], [AC_MSG_ERROR([apu-config not found, try using --with-apu-config])], ["$PATH:/usr/bin:/usr/local/bin"])
+	fi
+
+	AC_MSG_CHECKING([apr-util version])
+	APR_UTIL_VERSION="`$APR_UTIL_CONFIG --version`"
+	AC_MSG_RESULT([$APR_UTIL_VERSION])
+
+	ver_major="`echo $APR_UTIL_VERSION | cut -d'.' -f1`"
+	ver_minor="`echo $APR_UTIL_VERSION | cut -d'.' -f2`"
+	ver_patch="`echo $APR_UTIL_VERSION | cut -d'.' -f3`"
+
+	if test $ver_major -ne 1 -o $ver_minor -ne 2 -o $ver_patch -lt 10 ; then
+		AC_MSG_ERROR([Need >=apr-util-1.2.10])
+	fi
+
+	APR_UTIL_CFLAGS="`$APR_UTIL_CONFIG --includes`"
+	APR_UTIL_LIBS="`$APR_UTIL_CONFIG --link-libtool --libs`"
+
+	#
+	# check for important apr functions
+	# (e.g. initialization, threading etc.)
+	#
+	LIBS="`$APR_CONFIG --link-ld --libs`"
+	CFLAGS="$APR_CFLAGS"
+	AC_MSG_RESULT([checking for required functions...])
+	AC_CHECK_FUNCS([apr_initialize apr_pool_create_ex apr_thread_create],
+		[], [AC_MSG_ERROR([Required function missing in apr!])]
+	)
+	AC_CHECK_FUNCS([apr_file_open apr_dir_open apr_dso_load apr_socket_create],
+		[], [AC_MSG_ERROR([Required function missing in apr!])]
+	)
+
+	#
+	# check for important apr-util functions
+	#
+	LIBS="`$APR_UTIL_CONFIG --link-ld --libs` $LIBS"
+	CFLAGS="$APR_UTIL_CFLAGS $CFLAGS"
+	AC_CHECK_FUNCS([apr_uuid_get apr_queue_create],
+		[], [AC_MSG_ERROR([Required function missing in apr-util!])]
+	)
+
+	AC_SUBST([APR_LIBS],   [$APR_LIBS])
+	AC_SUBST([APR_CFLAGS], [$APR_CFLAGS])
+
+	AC_SUBST([APR_UTIL_LIBS],   [$APR_UTIL_LIBS])
+	AC_SUBST([APR_UTIL_CFLAGS], [$APR_UTIL_CFLAGS])
+
+	CFLAGS="$save_CFLAGS"
+	LIBS="$save_LIBS"
+fi
+
+AM_CONDITIONAL([USE_SYSTEM_APR], [test "$with_system_apr" != "no"])
+
+
+#
+# curl
+#
+AC_ARG_WITH(
+	[system-curl],
+	[AS_HELP_STRING([--with-system-curl], [Use system Curl instead of bundled version (experts only!])],
+	[with_system_curl="$withval"],
+	[with_system_curl="no"]
+)
+
+if test "$with_system_curl" != "no"
+then
+	AC_MSG_RESULT([${newline}* Checking for Curl])
+
+	# checks here
+fi
+
+AM_CONDITIONAL([USE_SYSTEM_CURL], [test "$with_system_curl" != "no"])
+
+
+#
+# libsndfile
+#
+AC_ARG_WITH(
+	[system-sndfile],
+	[AS_HELP_STRING([--with-system-sndfile], [Use system libsndfile instead of bundled version (experts only!])],
+	[with_system_sndfile="$withval"],
+	[with_system_sndfile="no"]
+)
+
+if test "$with_system_sndfile" != "no"
+then
+	AC_MSG_RESULT([${newline}* Checking for sndfile])
+
+	# checks here
+fi
+
+AM_CONDITIONAL([USE_SYSTEM_SNDFILE], [test "$with_system_sndfile" != "no"])
+
+
+#
+# speex
+#
+AC_ARG_WITH(
+	[system-speex],
+	[AS_HELP_STRING([--with-system-speex], [Use system Speex instead of bundled version (experts only!])],
+	[with_system_speex="$withval"],
+	[with_system_speex="no"]
+)
+
+if test "$with_system_speex" != "no"
+then
+	AC_MSG_RESULT([${newline}* Checking for Speex])
+
+	# checks here
+fi
+
+AM_CONDITIONAL([USE_SYSTEM_SPEEX], [test "$with_system_speex" != "no"])
+
+#######################################################
+# Module dependencies
+#
+
+#
+# convenience function for printing warning/error messages
+#
+# AX_MSG_IFTRY([VAR], [MESSAGE], [ALTERNATIVE-ERROR-MESSAGE])
+#
+AC_DEFUN([AX_MSG_IFTRY], [
+	if test "$1" = "try" ; then
+		AC_MSG_WARN([$2])
+	else
+		AC_MSG_ERROR([m4_ifval([$3], [$3], [$2])])
+	fi
+])
+
+#
+# Java for mod_java
+#
+AC_MSG_RESULT([${newline}* Java])
+
+AX_CHECK_JAVA
+
+#
+# Perl checks for mod_perl
+#
+HAVE_PERL="no"
+
+AC_ARG_WITH(
+	[perl],
+	[AS_HELP_STRING([--with-perl@<:@=PATH@:>@], [Path to the perl binary (default: try)])],
+	[with_perl="$withval"],
+	[with_perl="try"]
+)
+
+AC_MSG_RESULT([${newline}* Perl (with threads support)])
+
+if test "$with_perl" != "no"
+then
+	save_CFLAGS="$CFLAGS"
+	save_LIBS="$LIBS"
+
+	if test "$with_perl" != "yes" -a "$with_perl" != "try" ; then
+		AC_MSG_CHECKING([for perl])
+		if test ! -x "$with_perl" ; then
+			AC_MSG_ERROR([Specified perl does not exist or is not executable: $with_perl])
+		fi
+		AC_MSG_RESULT([$with_perl])
+		AC_SUBST([PERL], ["$with_perl"])
+	else
+		AC_PATH_PROG([PERL], ["perl"], ["no"], ["$PATH:/usr/bin:/usr/local/bin"])
+	fi
+
+	if test "$PERL" != "no"
+	then
+		PERL_LIBS="`$PERL -MConfig -e 'print $$Config{libs}'`"
+		PERL_LIBS="$PERL_LIBS `$PERL -MExtUtils::Embed -e ldopts`"
+
+		PERL_CFLAGS="`$PERL -MExtUtils::Embed -e ccopts` -DEMBED_PERL -DMULTIPLICITY"
+
+		# check for threads support
+		AC_MSG_CHECKING([for thread support in perl])
+		perl_has_threads="`$PERL -V | grep -q "usemultiplicity=def" 2>/dev/null && echo "yes" || echo "no"`"
+		AC_MSG_RESULT([$perl_has_threads])
+
+		LIBS="$PERL_LIBS"
+		CFLAGS="$PERL_CFLAGS"
+		AC_CHECK_FUNC([Perl_Tstack_base_ptr], [perl_tstack_base_ptr="yes"], [perl_tstack_base_ptr="no"])
+
+		if test "$perl_has_threads" = "no" -o "$perl_tstack_base_ptr" = "no"; then
+			AX_MSG_IFTRY([$with_perl], [perl found but unusable (no threads support)]) 
+		else
+			HAVE_PERL="yes"
+			AC_SUBST([PERL_CFLAGS], [$PERL_CFLAGS])
+			AC_SUBST([PERL_LIBS], [$PERL_LIBS])
+		fi
+	else
+		AX_MSG_IFTRY([$with_perl],
+			 [perl not found or unusable, modules requiring perl will fail!],
+			 [perl not found or unusable (no threads support)]
+		)
+	fi
+
+	CFLAGS="$save_CFLAGS"
+	LIBS="$save_LIBS"
+else
+	AC_MSG_NOTICE([perl support disabled by user])
+fi
+
+AC_SUBST([HAVE_PERL], [$HAVE_PERL])
+
+#
 # Python checks for mod_python
 #
+HAVE_PYTHON="no"
+
 AC_ARG_WITH(
 	[python],
-	[AS_HELP_STRING([--with-python], [Use system provided version of python (default: try)])],
+	[AS_HELP_STRING([--with-python@<:@=PATH@:>@], [Use system provided version of python (default: try)])],
 	[with_python="$withval"],
 	[with_python="try"]
 )
@@ -441,9 +727,13 @@
 	[with_python_config="no"]
 )
 
+AC_MSG_RESULT([${newline}* Python (with threads support)])
 
 if test "$with_python" != "no"
 then
+	save_CFLAGS="$CFLAGS"
+	save_LIBS="$LIBS"
+
 	if test "$with_python" != "yes" -a "$with_python" != "try" ; then
 		AC_MSG_CHECKING([for python])
 		if test ! -x "$with_python" ; then
@@ -497,47 +787,151 @@
 			PYTHON_LDFLAGS="`$PYTHON_CONFIG --ldflags`"
 
 			# check whether system libpython is usable and has threads support
-			save_LIBS="$LIBS"
 			LIBS="$PYTHON_LDFLAGS"
 			AC_CHECK_FUNC([PyThread_init_thread], [python_has_threads="yes"], [python_has_threads="no"])
-			LIBS="$save_LIBS"
 
 			if test "$python_has_threads" = "no" ; then
-				if test "$with_python" = "try" ; then
-					AC_MSG_ERROR([Your python lacks threads support, can not build mod_python])
-				fi
-
-				AC_MSG_WARN([Your python lacks threads support, can not build mod_python])
+				AX_MSG_IFTRY([$with_python], [Your python lacks threads support, can not build mod_python])
 			else
 				AC_MSG_NOTICE([Your python seems OK, do not forget to enable mod_python in modules.conf])
 				AC_SUBST([PYTHON_CFLAGS], [$PYTHON_CFLAGS])
 				AC_SUBST([PYTHON_LDFLAGS], [$PYTHON_LDFLAGS])
+				HAVE_PYTHON="yes"
 			fi
 		else
-			if test "$with_python" != "try" ; then
-				AC_MSG_ERROR([python-config could not be found, use --with-python-config to specify the location])
-			fi
-
-			AC_MSG_WARN([python-config could not be found, mod_python will not build, use --with-python-config to specify the location])
+			AX_MSG_IFTRY([$with_python],
+				[python-config could not be found, use --with-python-config to specify the location]
+			)
 		fi
 	else
-		if test "$with_python" != "try" ; then
-			AC_MSG_ERROR([Could not find python, use --with-python to specify the location])
+		AX_MSG_IFTRY([$with_python],
+			[Could not find python, mod_python will not build, use --with-python to specify the location],
+			[Could not find python, use --with-python to specify the location]
+		)
+	fi
+
+	CFLAGS="$save_CFLAGS"
+	LIBS="$save_LIBS"
+else
+	AC_MSG_NOTICE([python support disabled by user])
+fi
+
+AC_SUBST([HAVE_PYTHON], [$HAVE_PYTHON])
+
+
+#
+# ldap checks for mod_xml_ldap
+#
+HAVE_LDAP="no"
+
+# general ldap support (openldap only right now)
+AC_ARG_WITH(
+	[ldap],
+	[AS_HELP_STRING([--with-ldap], [LDAP support for modules (default: try)])],
+	[with_ldap="$withval"],
+	[with_ldap="try"]
+)
+
+# path to libs
+AC_ARG_WITH(
+	[ldap-lib-dir],
+	[AS_HELP_STRING([--with-ldap-lib-dir=DIR], [Location of the ldap client libraries])],
+	[with_ldap_lib_dir="$withval"],
+	[with_ldap_lib_dir="no"]
+)
+
+# path to includes
+AC_ARG_WITH(
+	[ldap-inc-dir],
+	[AS_HELP_STRING([--with-ldap-inc-dir=DIR], [Location of the ldap client includes])],
+	[with_ldap_inc_dir="$withval"],
+	[with_ldap_inc_dir="no"]
+)
+
+AC_MSG_RESULT([${newline}* LDAP libraries])
+
+
+if test "$with_ldap" != "no"
+then
+	save_CFLAGS="$CFLAGS"
+	save_LIBS="$LIBS"
+
+	LDAP_CFLAGS=""
+	LDAP_LIBS=""
+
+	if test -d "$with_ldap_inc_dir" ; then
+		LDAP_CFLAGS="-I$with_ldap_inc_dir"
+	fi
+	if test -d "$with_ldap_lib_dir" ; then 
+		LDAP_LIBS="-L$with_ldap_lib_dir"
+	fi
+
+	# check headers
+	CFLAGS="$CFLAGS $LDAP_CFLAGS"
+	AC_CHECK_HEADER([lber.h], [have_lber_h=yes], [have_lber_h=no])
+	AC_CHECK_HEADER([ldap.h], [have_ldap_h=yes], [have_ldap_h=no])
+
+	if test "$have_lber_h" = "no" -o "$have_ldap_h" = "no"
+	then
+		AX_MSG_IFTRY([$with_ldap], [LDAP client libraries not found or unusable])
+	else
+
+		# check libs
+		LIBS="$LDAP_LIBS"
+		AC_CHECK_LIB([lber], [ber_init], [have_lber=yes
+						  LDAP_LIBS="$LDAP_LIBS -llber"], [have_lber=no])
+
+		# first check w/o, second with -lpthread
+		AC_CHECK_LIB([ldap_r], [ldap_init],
+				[have_ldap_r=yes
+				 LDAP_LIBS="$LDAP_LIBS -lldap_r"],
+				[LIBS="$LDAP_LIBS -lldap_r -lpthread"
+				 unset ac_cv_lib_ldap_r_ldap_init
+				 AC_CHECK_LIB([ldap_r], [ldap_init],
+						[have_ldap=yes
+						 LDAP_LIBS="$LDAP_LIBS -lldap_r -lpthread"],
+						[have_ldap=no]
+				)]
+		)
+
+		if test "$have_lber" = "no" -o "$have_ldap_r" = "no"
+		then
+			AX_MSG_IFTRY([$with_ldap],
+				[LDAP client libraries not found or unusable]
+			)
+		else
+			AC_MSG_NOTICE([LDAP client libraries found])
+			#AC_DEFINE([HAVE_LDAP], [1], [LDAP client libraries available])
+
+			AC_SUBST([LDAP_CFLAGS], [$LDAP_CFLAGS])
+			AC_SUBST([LDAP_LIBS], [$LDAP_LIBS])
+			HAVE_LDAP="yes"
 		fi
+	fi
 
-		AC_MSG_WARN([Could not find python, mod_python will not build, use --with-python to specify the location])
-	fi
+	CFLAGS="$save_CFLAGS"
+	LIBS="$save_LIBS"
 else
-	AC_MSG_WARN([python support disabled, building mod_python will fail!])
+	AC_MSG_NOTICE([ldap support disabled by user])
 fi
 
+AC_SUBST([HAVE_LDAP], [$HAVE_LDAP])
+
+
+#
+# Done, insert spacer
+#
+AC_MSG_RESULT([])
+
 AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/mod/Makefile
                 src/mod/endpoints/mod_sofia/Makefile
                 src/mod/event_handlers/mod_radius_cdr/Makefile
                 src/mod/languages/mod_java/Makefile
+                src/mod/languages/mod_perl/Makefile
                 src/mod/languages/mod_python/Makefile
+                src/mod/xml_int/mod_xml_ldap/Makefile
                 src/include/switch_am_config.h
                 build/getsounds.sh
                 build/getlib.sh
@@ -588,21 +982,100 @@
     AC_CONFIG_SUBDIRS(libs/libedit)
 fi
 AC_CONFIG_SUBDIRS(libs/pcre)
-AC_CONFIG_SUBDIRS(libs/apr)
-AC_CONFIG_SUBDIRS(libs/apr-util)
+if test "$with_system_apr" = "no" ; then
+	AC_CONFIG_SUBDIRS(libs/apr)
+	AC_CONFIG_SUBDIRS(libs/apr-util)
+fi
 AC_CONFIG_SUBDIRS(libs/voipcodecs)
 AC_CONFIG_SUBDIRS(libs/codec/ilbc)
-AC_CONFIG_SUBDIRS(libs/curl)
+if test "$with_system_curl" = "no" ; then
+	AC_CONFIG_SUBDIRS(libs/curl)
+fi
 AC_CONFIG_SUBDIRS(libs/iksemel)
 AC_CONFIG_SUBDIRS(libs/js/nsprpub)
 AC_CONFIG_SUBDIRS(libs/js)
 AC_CONFIG_SUBDIRS(libs/libdingaling)
-AC_CONFIG_SUBDIRS(libs/libsndfile)
+if test "$with_system_sndfile" ; then
+	AC_CONFIG_SUBDIRS(libs/libsndfile)
+fi
 AC_CONFIG_SUBDIRS(libs/sofia-sip)
-AC_CONFIG_SUBDIRS(libs/speex)
+if test "$with_system_speex" ; then
+	AC_CONFIG_SUBDIRS(libs/speex)
+fi
 AC_CONFIG_SUBDIRS(libs/xmlrpc-c)
 AC_CONFIG_SUBDIRS(libs/portaudio)
 AC_CONFIG_SUBDIRS(libs/openmrcp)
 AC_CONFIG_SUBDIRS(libs/openzap)
 
 AC_OUTPUT
+
+#
+# Print a nice summary of core options
+#
+AC_MSG_RESULT([
+------====== FreeSWITCH configuration summary ======------
+
+    prefix:.................. $prefix
+    modules directory:....... $modinstdir
+
+    optimized build:......... $enable_optimizer
+    debug build:............. $enable_debug
+    crash protection:........ -not available-
+
+    core odbc support:....... $enable_core_odbc_support
+    core libedit support:.... $enable_core_libedit_support
+    embedded resampler:...... $enable_resample
+])
+
+#
+# core dependencies
+#
+
+#
+# AX_FOR_SETVAL([VAR... ], [VALUE-TO-CHECK], [IF-VALUE], [ELSE-VALUE])
+#
+AC_DEFUN([AX_FOR_SETVAL], [{
+	for x in $1"" ; do
+		if eval "test \"\$$x\" = \"$2\"" ; then
+			eval $x=\"m4_flatten([$3])\"
+		elif test -n "m4_flatten([$4])" ; then
+			eval $x=\"m4_flatten([$4])\"
+		fi
+	done
+}])
+
+
+AX_FOR_SETVAL(
+	[with_system_apr with_system_curl with_system_speex with_system_sndfile],
+	[no], [bundled], [system provided]
+)
+
+
+AC_MSG_RESULT([
+    Core dependencies:
+
+    Apache Portable Runtime:... $with_system_apr
+    CURL:...................... $with_system_curl
+    speex:..................... $with_system_speex
+    sndfile:................... $with_system_sndfile
+])
+
+#
+# optional external components used by modules
+#
+
+# special handling for bundled lib
+if test "$HAVE_LDAP" = "no"; then
+	HAVE_LDAP="no (using bundled)"
+fi
+
+AC_MSG_RESULT([
+    Optional dependencies used by modules:
+
+    Python w/ threads support:... $HAVE_PYTHON
+    Perl w/ threads support:..... $HAVE_PERL
+    LDAP Client libraries:....... $HAVE_LDAP
+
+
+------==============================================------
+])
Index: build/config/ax_check_java.m4
===================================================================
--- build/config/ax_check_java.m4	(revision 8326)
+++ build/config/ax_check_java.m4	(working copy)
@@ -9,7 +9,7 @@
 AC_DEFUN([AX_CHECK_JAVA],
 [
 AC_ARG_WITH([java],
-            AC_HELP_STRING([  --with-java=PFX], [prefix where 'java' is installed.]),
+            AC_HELP_STRING([--with-java=DIR], [prefix where 'java' is installed.]),
             [with_java_prefix=$withval], 
 	    [with_java_prefix=${JAVA_INSTALL_PATH:-/usr/java/j2sdk1.4.1_01}])
 have_java='no'
Index: src/mod/languages/mod_python/Makefile.in
===================================================================
--- src/mod/languages/mod_python/Makefile.in	(revision 8326)
+++ src/mod/languages/mod_python/Makefile.in	(working copy)
@@ -3,6 +3,10 @@
 
 # and define these variables to impact your build
 
+HAVE_PYTHON=@HAVE_PYTHON@
+
+ifeq ($(HAVE_PYTHON),yes)
+
 LOCAL_CFLAGS = @PYTHON_CFLAGS@
 LOCAL_LDFLAGS= @PYTHON_LDFLAGS@ -lstdc++
 LOCAL_OBJS=freeswitch_python.o mod_python_wrap.o
@@ -27,3 +31,7 @@
 	mkdir -m755 -p $(DESTDIR)$(PYTHON_SITE_DIR)
 	cp -f freeswitch.py $(DESTDIR)$(PYTHON_SITE_DIR)
 
+else
+all install:
+	@echo "$(MODNAME) - No Python with threads support found, disabled"
+endif
Index: src/mod/languages/mod_perl/Makefile.in
===================================================================
--- /dev/null	2008-04-08 15:04:37.368007714 +0000
+++ src/mod/languages/mod_perl/Makefile.in	2008-05-07 16:38:55.000000000 +0000
@@ -0,0 +1,43 @@
+BASE=../../../..
+
+HAVE_PERL=@HAVE_PERL@
+
+ifeq ($(HAVE_PERL),yes)
+PERL        =@PERL@
+PERL_LIBS   =@PERL_LIBS@
+PERL_CFLAGS =@PERL_CFLAGS@
+
+LOCAL_CFLAGS =$(PERL_CFLAGS) -w 
+LOCAL_LDFLAGS=$(PERL_LIBS)
+LOCAL_OBJS=freeswitch_perl.o mod_perl_wrap.o perlxsi.o
+
+VERBOSE=1
+
+include $(BASE)/build/modmake.rules
+
+swigclean: clean
+	rm -f mod_perl_wrap.* freeswitch.so freeswitch.pm
+
+mod_perl_wrap.cpp:
+	swig -static -shadow -perl5 -c++ -DMULTIPLICITY -I../../../../src/include -o mod_perl_wrap.cpp freeswitch.i
+	echo "#include \"mod_perl_extra.c\"" >> mod_perl_wrap.cpp
+	patch -s -p0 -i hack.diff
+
+
+freeswitch.$(DYNAMIC_LIB_EXTEN): $(LOCAL_OBJS) $(LOCAL_LIBADD)
+	$(LINK) $(SOLINK) -o freeswitch.$(DYNAMIC_LIB_EXTEN)  $(LOCAL_OBJS) $(LOCAL_LIBADD) $(LDFLAGS)
+
+local_all: freeswitch.$(DYNAMIC_LIB_EXTEN)
+
+local_clean:
+	rm -fr *~ freeswitch.$(DYNAMIC_LIB_EXTEN)
+
+depend_install:
+	mkdir -p $(DESTDIR)$(PREFIX)/perl
+	$(LTINSTALL) freeswitch.$(DYNAMIC_LIB_EXTEN) freeswitch.pm $(DESTDIR)$(PREFIX)/perl
+	if [ ! -f $(DESTDIR)$(PREFIX)/perl/freeswitch.pm ] ; then $(LTINSTALL) freeswitch.pm $(DESTDIR)$(PREFIX)/perl ; fi
+
+else
+all install:
+	@echo "$(MODNAME) - No perl with threads support found, disabled"
+endif
Index: src/mod/xml_int/mod_xml_ldap/Makefile.in
===================================================================
--- /dev/null	2008-04-08 15:04:37.368007714 +0000
+++ src/mod/xml_int/mod_xml_ldap/Makefile.in	2008-05-07 11:51:17.000000000 +0000
@@ -0,0 +1,38 @@
+switch_srcdir=../../../..
+
+HAVE_LDAP=@HAVE_LDAP@
+
+ifeq ($(HAVE_LDAP),no)
+# Use bundled openldap libs
+LDAP=openldap-2.3.19
+LDAP_DIR=$(switch_srcdir)/libs/$(LDAP)
+
+LDAPLA=$(LDAP_DIR)/libraries/libldap_r/libldap_r.la
+LBERLA=$(LDAP_DIR)/libraries/liblber/liblber.la
+
+LDAP_CFLAGS=-I$(LDAP_DIR)/include
+LDAP_LIBS=$(LDAPLA) $(LBERLA)
+
+DEFAULT_ARGS= --prefix=$(PREFIX) --disable-shared --with-pic --disable-slapd
+DEFAULT_ARGS+= --disable-slurpd --disable-relay --disable-bdb --disable-hdb
+else
+# Use system-provided openldap libs
+LDAP_CFLAGS=@LDAP_CFLAGS@
+LDAP_LIBS=@LDAP_LIBS@
+endif
+
+LOCAL_CFLAGS=$(LDAP_CFLAGS) -DWITH_OPENLDAP -DLDAP_DEPRECATED
+LOCAL_LIBADD=$(LDAP_LIBS)
+
+include $(switch_srcdir)/build/modmake.rules
+
+ifeq ($(HAVE_LDAP),no)
+$(LDAP_DIR):
+	$(GETLIB) $(LDAP).tgz
+	cd $(LDAP_DIR) && CFLAGS="`echo $(CFLAGS) | sed -e 's:-std=c99::'`" ./configure $(DEFAULT_ARGS)
+
+$(LDAPLA) $(LBERLA): $(LDAP_DIR)
+	cd $(LDAP_DIR) && $(MAKE)
+	$(TOUCH_TARGET)
+endif
+
