906948
diff --git a/support/apxs.in b/support/apxs.in
906948
index b2705fa..c331631 100644
906948
--- a/support/apxs.in
906948
+++ b/support/apxs.in
906948
@@ -35,7 +35,18 @@ if ($ddi >= 0) {
906948
 
906948
 my %config_vars = ();
906948
 
906948
-my $installbuilddir = "@exp_installbuilddir@";
906948
+# Awful hack to make apxs libdir-agnostic:
906948
+my $pkg_config = "/usr/bin/pkg-config";
906948
+if (! -x "$pkg_config") {
906948
+    error("$pkg_config not found!");
906948
+    exit(1);
906948
+}
906948
+
906948
+my $libdir = `pkg-config --variable=libdir apr-1`;
906948
+chomp $libdir;
906948
+
906948
+my $installbuilddir = $libdir . "/httpd/build";
906948
+
906948
 get_config_vars($destdir . "$installbuilddir/config_vars.mk",\%config_vars);
906948
 
906948
 # read the configuration variables once
906948
@@ -285,7 +296,7 @@ if ($opt_g) {
906948
     $data =~ s|%NAME%|$name|sg;
906948
     $data =~ s|%TARGET%|$CFG_TARGET|sg;
906948
     $data =~ s|%PREFIX%|$prefix|sg;
906948
-    $data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
906948
+    $data =~ s|%LIBDIR%|$libdir|sg;
906948
 
906948
     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
906948
 
906948
@@ -463,11 +474,11 @@ if ($opt_c) {
906948
     my $ldflags = "$CFG_LDFLAGS";
906948
     if ($opt_p == 1) {
906948
         
906948
-        my $apr_libs=`$apr_config --cflags --ldflags --link-libtool --libs`;
906948
+        my $apr_libs=`$apr_config --cflags --ldflags --link-libtool`;
906948
         chomp($apr_libs);
906948
         my $apu_libs="";
906948
         if ($apr_major_version < 2) {
906948
-            $apu_libs=`$apu_config --ldflags --link-libtool --libs`;
906948
+            $apu_libs=`$apu_config --ldflags --link-libtool`;
906948
             chomp($apu_libs);
906948
         }
906948
         
906948
@@ -682,8 +693,8 @@ __DATA__
906948
 
906948
 builddir=.
906948
 top_srcdir=%PREFIX%
906948
-top_builddir=%PREFIX%
906948
-include %INSTALLBUILDDIR%/special.mk
906948
+top_builddir=%LIBDIR%/httpd
906948
+include %LIBDIR%/httpd/build/special.mk
906948
 
906948
 #   the used tools
906948
 APACHECTL=apachectl