--- apr-config.in.orig	Thu Aug  3 04:05:27 2006
+++ apr-config.in	Tue Feb 12 02:24:17 2008
@@ -30,6 +30,27 @@
 installbuilddir="@installbuilddir@"
 includedir="@includedir@"
 
+# Determine the root directory of the Apache installation using the directory
+# in which this script resides. Use this directory as the base for all the paths
+cur_dir=`pwd`
+install_root=`dirname $0`
+cd $install_root
+install_root=`pwd`
+new_install_root=`echo $install_root | sed -e "s!@bindir@!!"`
+if test "$install_root" != "$new_install_root"; then
+    install_root="$new_install_root"
+else
+    install_root=""
+fi
+cd $cur_dir
+prefix="${install_root}@prefix@"
+exec_prefix="@exec_prefix@"
+bindir="@bindir@"
+libdir="@libdir@"
+datadir="${install_root}@datadir@"
+installbuilddir="${install_root}@installbuilddir@"
+includedir="@includedir@"
+
 CC="@CC@"
 CPP="@CPP@"
 SHELL="@SHELL@"
@@ -199,7 +199,11 @@
     --link-ld)
     if test "$location" = "installed"; then
         ### avoid using -L if libdir is a "standard" location like /usr/lib
-        flags="$flags -L$libdir -l${APR_LIBNAME}"
+        if test -n "$install_root"; then
+            flags="$flags -L$libdir -l${APR_LIBNAME}"
+        else
+            flags="$flags -L$libdir -R$libdir -l${APR_LIBNAME}"
+        fi
     elif test "$location" = "crosscompile"; then
         flags="$flags -L$APR_TARGET_DIR/$libdir -l${APR_LIBNAME}"
     else