--- configure.ac
+++ configure.ac
@@ -225,19 +225,31 @@ AM_CONDITIONAL(USE_GNUTLS, test x$enable_ssl = xGnuTLS)
 dnl +-------------------------------------------------------------------+
 dnl | Checking for libasyncns                                           |
 dnl +-------------------------------------------------------------------+
-AC_ARG_WITH(asyncns, [  --with-asyncns=yes/no  define whether to use libasyncns, default=no],
-            ac_asyncns=$withval,
-            ac_asyncns=no
-            )
+AC_ARG_WITH(asyncns,
+	AS_HELP_STRING([--with-asyncns],
+		[define whether to use libasyncns, @<:@default=no@:>@ (internal/system/no)]),
+	ac_asyncns=$withval,
+	ac_asyncns=no)
 
 enable_asyncns=no
+have_asyncns_system=no
 if test x$ac_asyncns != xno; then
 	enable_asyncns=yes
 	AC_DEFINE(HAVE_ASYNCNS, 1, [Whether to use libasyncns])
+
+	if test x$ac_asyncns = xsystem; then
+		PKG_CHECK_MODULES(ASYNCNS, [libasyncns >= 0.3],
+			[have_asyncns_system=yes],
+			[have_asyncns_system=no])
+	fi
 else
 	echo "Not using asynchronous dns lookups"
 fi
 
+AC_SUBST(ASYNCNS_CFLAGS)
+AC_SUBST(ASYNCNS_LIBS)
+AM_CONDITIONAL(USE_SYSTEM_ASYNCNS, test x$have_asyncns_system = xyes)
+
 dnl +-------------------------------------------------------------------+
 dnl | Checking for Linux TCP/IP stack                                   |
 dnl +-------------------------------------------------------------------+
--- loudmouth/Makefile.am.orig	2009-04-13 10:39:37.000000000 +0200
+++ loudmouth/Makefile.am	2009-04-13 10:41:41.000000000 +0200
@@ -10,6 +10,7 @@
 	-I$(top_srcdir)                     \
 	$(LOUDMOUTH_CFLAGS)                 \
 	$(LIBIDN_CFLAGS)                    \
+	$(ASYNCNS_CFLAGS)                   \
 	-DLM_COMPILATION                    \
 	-DRUNTIME_ENDIAN                    \
 	$(NULL)
@@ -32,6 +33,13 @@
 	lm-ssl-openssl.c
 endif
 
+if ! USE_SYSTEM_ASYNCNS
+asyncns_sources = \
+	asyncns.c     \
+	asyncns.h
+endif
+
+
 libloudmouth_1_la_SOURCES =             \
 	lm-connection.c                     \
 	lm-debug.c                          \
@@ -55,8 +63,7 @@
 	lm-parser.c                         \
 	lm-parser.h                         \
 										\
-	asyncns.c                           \
-	asyncns.h                           \
+	$(asyncns_sources)                  \
 	lm-resolver.c                       \
 	lm-resolver.h                       \
 	lm-asyncns-resolver.c               \
@@ -110,6 +117,7 @@
 libloudmouth_1_la_LIBADD =              \
 	$(LOUDMOUTH_LIBS)                   \
 	$(LIBIDN_LIBS)                      \
+	$(ASYNCNS_LIBS)                     \
 	-lresolv
 
 libloudmouth_1_la_LDFLAGS =                                 \
