diff -r 972de6ab7b60 Config
--- a/Config	Sun Jul 18 19:00:03 2010 -0400
+++ b/Config	Tue Jul 20 22:21:02 2010 -0400
@@ -18,6 +18,7 @@
 
 # some bits edited by baafie on March 17 2004, every change marked.
 
+PKG_CONFIG=pkg-config
 
 RUN_CONFIGURE () {
 ARG=" "
@@ -670,16 +671,32 @@
                 if [ -d "/usr/share/unreal-curl" ]; then
                         CURLDIR="/usr/share/unreal-curl"
                 fi
+		# See if pkg-config is the way to go
+		if $PKG_CONFIG --exists libcurl; then
+		    CURLDIR="yes"
+		fi
 
                 GOTASYNC=0
                 if [ "x$CURLDIR" != "x" ]; then
                   # Check if it's of any use: a curl without async dns (cares) hangs the entire ircd..
                   # normally this is done in ./configure but now we're forced to do it also here..
-                  GOTASYNC="`$CURLDIR/bin/curl-config --features|grep AsynchDNS|wc -l`"
-                  if [ "$GOTASYNC" != "1" ]; then
-                          PREVCURLDIR="$CURLDIR"
-                          CURLDIR=""
-                  fi
+		    if [ "x$CURLDIR" = "xyes" ]; then
+			# pkg-config
+			CURL_FEATURES="`$PKG_CONFIG --variable supported_features libcurl`"
+		    else
+			# curl-config
+			CURL_FEATURES="`$CURLDIR/bin/curl-config --features`"
+		    fi
+		    # get rid of double-quotes (from pkg-config --variable supported_features's output)
+		    CURL_FEATURES="`eval echo $CURL_FEATURES`"
+		    for curl_feature in $CURL_FEATURES; do
+			[ $curl_feature = "AsynchDNS" ] && GOTASYNC=1
+		    done
+                    if [ "$GOTASYNC" != "1" ]; then
+			echo "I be called!"
+                        PREVCURLDIR="$CURLDIR"
+                        CURLDIR=""
+                    fi
                 fi
                 
                 # Second, use the local curl if it exists (overrides above)
@@ -728,10 +745,11 @@
                         fi
                 fi
                 
-                # Need to output it here, as the HOME check from above may cause this to be no longer relevant.
+                # Show warning after the HOME check (above) as that check may render this warning irrelevant.
                 if [ "x$CURLDIR" = "x" -a "$GOTASYNC" != "1" ]; then
                 	echo "Curl library was found in $PREVCURLDIR, but it does not support Asynchronous DNS (not compiled with c-ares)"
-                	echo "so it's of no use to us."
+                	echo "so it's of no use to us. ( pssst... to use this copy of libcURL regardless, answer \`\`no'' below"
+			echo " -- but only do so if you want your IRCd to freeze temporarily during REHASHes)."
                 fi
                 	
         fi
@@ -770,7 +788,8 @@
           while [ -z "$TEST" ] ; do
                   TEST="$CURLDIR"
                   echo ""
-                  echo "Specify the directory you installed libcurl to"
+                  echo "Specify the directory you installed libcurl to."
+		  echo "If you want to use pkg-config(1), enter \`\`yes''."
                   echo $n "[$TEST] -> $c"
                   read cc
                   if [ -z "$cc" ] ; then
diff -r 972de6ab7b60 autoconf/m4/unreal.m4
--- a/autoconf/m4/unreal.m4	Sun Jul 18 19:00:03 2010 -0400
+++ b/autoconf/m4/unreal.m4	Tue Jul 20 22:21:02 2010 -0400
@@ -44,50 +44,69 @@
 	[enable_curl=$enableval],
 	[enable_curl=no])
 
+	CURL_FOUND="no"
 	AS_IF([test "x$enable_curl" != "xno"],
 	[
-		dnl sane, default directory for Operating System-managed libcURL
-		dnl (when --enable-libcurl is passed without any arguments). On
-		dnl systems with stuff in /usr/local, /usr/local/bin should already
-		dnl be in PATH. On sane systems, this will invoke the curl-config
-		dnl installed by the package manager.
-		CURLCONFIG="curl-config"
-		AS_IF([test "x$enable_curl" != "xyes"],
-			[CURLCONFIG="$enable_curl/bin/curl-config"])
+		dnl First try pkg-config. But only if the user has not specified
+		dnl a path to the --enable-libcurl switch. If the user _wants_
+		dnl pkg-config to be used, he should just do --enable-libcurl=yes
+		dnl and set PKG_CONFIG_PATH appropriately.
+		AS_IF([test "x$enable_curl" = "xyes"],
+			[
+			PKG_CHECK_MODULES([CURL], [libcurl], [CURL_FOUND="yes"], [:])
+			dnl check features
+			CURL_ASYNCH=""
+			CURL_FEATURES="`$PKG_CONFIG --variable supported_features libcurl`"
+			CURL_FEATURES="`eval echo $CURL_FEATURES`"
+			])
 
-		AC_MSG_CHECKING([$CURLCONFIG])
-		AS_IF([$CURLCONFIG --version 2>/dev/null >/dev/null],
-			[AC_MSG_RESULT([yes])],
-			[AC_MSG_RESULT([no])
-				AC_MSG_FAILURE([Could not find curl-config, try editing --enable-libcurl])])
+		dnl The alternate, scary, curl-config-style curl discovery.
+		dnl if --enable-libcurl=/some/path, then this is cleaner than manually
+		dnl extending PKG_CONFIG_PATH=/some/path/lib*/pkgconfig. --binki
+		AS_IF([test "x$CURL_FOUND" = "xno"],
+			[
+			dnl sane, default directory for Operating System-managed libcURL
+			dnl (when --enable-libcurl is passed without any arguments). On
+			dnl systems with stuff in /usr/local, /usr/local/bin should already
+			dnl be in PATH. On sane systems, this will invoke the curl-config
+			dnl installed by the package manager. --binki
+			CURLCONFIG="curl-config"
+			AS_IF([test "x$enable_curl" != "xyes"],
+				[CURLCONFIG="$enable_curl/bin/curl-config"])
 
-		CURLCFLAG="`$CURLCONFIG --cflags`"
-		CURLLIBS="`$CURLCONFIG --libs`"
-		
-		CURLUSESCARES="`echo $CURLLIBS|grep c-ares|wc -l`"
-		AS_IF([test "$CURLUSESCARES" = "0"],
-			[AC_MSG_WARN([cURL is compiled without c-ares support. Your IRCd will possibly stall when REHASHing!])])
+			AC_MSG_CHECKING([$CURLCONFIG])
+			AS_IF([$CURLCONFIG --version 2>/dev/null >/dev/null],
+				[AC_MSG_RESULT([yes])],
+				[AC_MSG_RESULT([no])
+					AC_MSG_FAILURE([Could not find curl-config, try editing --enable-libcurl])])
 
-		dnl sanity warnings
-		AS_IF([test -z "${CURLLIBS}"],
-			[AC_MSG_WARN([CURLLIBS is empty, that probably means that I could not find $enable_curl/bin/curl-config])])
+			CURL_CFLAGS="`$CURLCONFIG --cflags`"
+			CURL_LIBS="`$CURLCONFIG --libs`"
 
-		dnl Ok this is ugly, basically we need to strip the version of c-ares that curl uses
-		dnl because we want to use our own version (which is hopefully fully binary
-		dnl compatible with the curl one as well).
-		dnl Therefore we need to strip the cares libs in a weird way...
-		dnl If anyone can come up with something better and still portable (no awk!?)
-		dnl then let us know. -- Syzop
-		dnl
-		dnl It is dangerous to mix and match cURL with potentially ABI-incompatible versions of
-		dnl c-ares, just use --with-system-cares.
-		dnl Thus, make sure to use --with-system-cares when using system-cURL. If the user
-		dnl wants bundled c-ares + system libcURL, then we should filter out c-ares
-		dnl flags. _Only_ in that case should we mess with the flags. -- ohnobinki
+			CURL_FEATURES="`$CURLCONFIG --features`"
+			CURL_FEATURES="`eval echo $CURLCONFIG --features`"
 
-		AS_IF([test "x$with_system_cares" = "xno" && test "x$HOME/curl" != "x$enable_curl" && test "x/usr/share/unreal-curl" != "x$enable_curl" && test "$CURLUSESCARES" != "0" ],
-		[
-			AC_MSG_ERROR([[
+			dnl sanity warnings
+			AS_IF([test -z "${CURL_LIBS}"],
+				[AC_MSG_WARN([CURL_LIBS is empty, that probably means that I could not find $enable_curl/bin/curl-config])])
+			CURL_FOUND="yes"
+
+			dnl Ok this is ugly, basically we need to strip the version of c-ares that curl uses
+			dnl because we want to use our own version (which is hopefully fully binary
+			dnl compatible with the curl one as well).
+			dnl Therefore we need to strip the cares libs in a weird way...
+			dnl If anyone can come up with something better and still portable (no awk!?)
+			dnl then let us know. -- Syzop
+			dnl
+			dnl It is dangerous to mix and match cURL with potentially ABI-incompatible versions of
+			dnl c-ares, just use --with-system-cares.
+			dnl Thus, make sure to use --with-system-cares when using system-cURL. If the user
+			dnl wants bundled c-ares + system libcURL, then we should filter out c-ares
+			dnl flags. _Only_ in that case should we mess with the flags. -- ohnobinki
+
+			AS_IF([test "x$with_system_cares" = "xno" && test "x$HOME/curl" != "x$enable_curl" && test "x/usr/share/unreal-curl" != "x$enable_curl" && test "$CURLUSESCARES" != "0" ],
+			[
+				AC_MSG_ERROR([[
 
   You have decided to build unrealIRCd with libcURL (remote includes) support.
   However, you have disabled system-installed c-ares support (--with-system-cares).
@@ -100,34 +119,48 @@
   Or UnrealIRCd might even crash.
 
   Please build UnrealIRCd with --with-system-cares when enabling --enable-libcurl
-]])
-		])
+					]])
+			])
 
-		AS_IF([test "x`echo $CURLLIBS |grep ares`" != x && test "x$with_system_cares" = "xno"],
-		[
-			dnl Attempt one: Linux sed
-			XCURLLIBS="`echo "$CURLLIBS"|sed -r 's/(@<:@^ @:>@+ @<:@^ @:>@+ )(@<:@^ @:>@+ @<:@^ @:>@+ )(.+)/\1\3/g' 2>/dev/null`"
-			AS_IF([test "x$XCURLLIBS" = "x"],
+			AS_IF([test "x`echo $CURL_LIBS |grep ares`" != x && test "x$with_system_cares" = "xno"],
 			[
-				dnl Attempt two: FreeBSD (and others?) sed
-				XCURLLIBS="`echo "$CURLLIBS"|sed -E 's/(@<:@^ @:>@+ @<:@^ @:>@+ )(@<:@^ @:>@+ @<:@^ @:>@+ )(.+)/\1\3/g' 2>/dev/null`"
-				AS_IF([test x"$XCURLLIBS" = x],
+				dnl Attempt one: Linux sed
+				XCURL_LIBS="`echo "$CURL_LIBS"|sed -r 's/(@<:@^ @:>@+ @<:@^ @:>@+ )(@<:@^ @:>@+ @<:@^ @:>@+ )(.+)/\1\3/g' 2>/dev/null`"
+				AS_IF([test "x$XCURL_LIBS" = "x"],
 				[
-					AC_MSG_ERROR([sed appears to be broken. It is needed for a remote includes compile hack.])
+					dnl Attempt two: FreeBSD (and others?) sed
+					XCURL_LIBS="`echo "$CURL_LIBS"|sed -E 's/(@<:@^ @:>@+ @<:@^ @:>@+ )(@<:@^ @:>@+ @<:@^ @:>@+ )(.+)/\1\3/g' 2>/dev/null`"
+					AS_IF([test x"$XCURL_LIBS" = x],
+					[
+						AC_MSG_ERROR([sed appears to be broken. It is needed for a remote includes compile hack.])
+					])
 				])
+				CURL_LIBS="$XCURL_LIBS"
+
+				IRCDLIBS_CURL_CARES="$CARES_LIBS"
+				CFLAGS_CURL_CARES="$CARES_CFLAGS"
 			])
-			CURLLIBS="$XCURLLIBS"
-
-			IRCDLIBS_CURL_CARES="$CARES_LIBS"
-			CFLAGS_CURL_CARES="$CARES_CFLAGS"
 		])
 		
+
+		dnl Sanity check: using a synchronous libcurl will mean stalling
+		dnl on rehash.
+		CURL_ASYNC="no"
+		for curl_feature in $CURL_FEATURES; do
+			AS_IF([test "$curl_feature" = "AsynchDNS" ],
+				[CURL_ASYNCH="yes"])
+		done
+		AS_IF([test "$CURL_ASYNC" = "no"],
+			[AC_MSG_WARN([cURL is compiled without c-ares support. Your IRCd will possibly stall when REHASHing!])])
+
+
 		dnl Make sure that linking against cURL works rather than letting the user
 		dnl find out after compiling most of his program. ~ohnobinki
-		IRCDLIBS="$IRCDLIBS $CURLLIBS"
-		CFLAGS="$CFLAGS $CURLCFLAG -DUSE_LIBCURL"
+		IRCDLIBS="$IRCDLIBS $CURL_LIBS"
+		CFLAGS="$CFLAGS $CURL_CFLAGS"
+		AC_DEFINE([USE_LIBCURL], [], [Define if you have libcurl installed to get remote includes and MOTD support])
 
-		AC_MSG_CHECKING([curl_easy_init() in $CURLLIBS])
+		AC_MSG_CHECKING([curl_easy_init() in $CURL_LIBS])
 		LIBS_SAVEDA="$LIBS"
 		CFLAGS_SAVEDA="$CFLAGS"
 
