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