#! /bin/sh /usr/share/dpatch/dpatch-run
## 031_apxs2_sucks_more by Adam Conrad <adconrad@0c3.net>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Make apxs2 use httpd.conf, instead of apache2.conf, plus other random fixes.

@DPATCH@
--- a/support/apxs.in
+++ b/support/apxs.in
@@ -189,7 +189,7 @@
 my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
 $httpd = eval qq("$httpd");
 $httpd = eval qq("$httpd");
-my $envvars = get_vars("sbindir") . "/envvars";
+my $envvars = "$CFG_SYSCONFDIR" . "/envvars";
 $envvars = eval qq("$envvars");
 $envvars = eval qq("$envvars");
 
@@ -292,6 +292,7 @@
     $data =~ s|%TARGET%|$CFG_TARGET|sg;
     $data =~ s|%PREFIX%|$prefix|sg;
     $data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
+    $data =~ s|%DATADIR%|$datadir|sg;
 
     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
 
@@ -480,7 +481,7 @@
         if ($opt_i) {
 	    push(@cmds, "$installbuilddir/instdso.sh SH_LIBTOOL='" .
                  "$libtool' $f $CFG_LIBEXECDIR");
-	    push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
+	    push(@cmds, "chmod 644 $CFG_LIBEXECDIR/$t");
         }
 
         #   determine module symbolname and filename
@@ -516,7 +517,8 @@
             $filename = "mod_${name}.c";
         }
         my $dir = $CFG_LIBEXECDIR;
-        $dir =~ s|^$CFG_PREFIX/?||;
+        # Debian doesn't have a CFG_PREFIX, so this stuffs up:
+	# $dir =~ s|^$CFG_PREFIX/?||;
         $dir =~ s|(.)$|$1/|;
 	$t =~ s|\.la$|.so|;
         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
@@ -527,17 +529,17 @@
 
     #   activate module via LoadModule/AddModule directive
     if ($opt_a or $opt_A) {
-        if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
-            error("Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found");
+        if (not -f "$CFG_SYSCONFDIR/httpd.conf") {
+            error("Config file $CFG_SYSCONFDIR/httpd.conf not found");
             exit(1);
         }
 
-        open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
+        open(FP, "<$CFG_SYSCONFDIR/httpd.conf") || die;
         my $content = join('', <FP>);
         close(FP);
 
         if ($content !~ m|\n#?\s*LoadModule\s+|) {
-            error("Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.");
+            error("Activation failed for custom $CFG_SYSCONFDIR/httpd.conf file.");
             error("At least one `LoadModule' directive already has to exist.");
             exit(1);
         }
@@ -616,15 +618,15 @@
                 $content =~ s|^(.*\n)#?\s*$lmd_re[^\n]*\n|$1$c$lmd\n|s;
             }
             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
-            notice("[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]");
+            notice("[$what module `$1' in $CFG_SYSCONFDIR/httpd.conf]");
         }
         if (@lmd) {
-            if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
+            if (open(FP, ">$CFG_SYSCONFDIR/httpd.conf.new")) {
                 print FP $content;
                 close(FP);
-                system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
-                       "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
-                       "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
+                system("cp $CFG_SYSCONFDIR/httpd.conf $CFG_SYSCONFDIR/httpd.conf.bak && " .
+                       "cp $CFG_SYSCONFDIR/httpd.conf.new $CFG_SYSCONFDIR/httpd.conf && " .
+                       "rm $CFG_SYSCONFDIR/httpd.conf.new");
             } else {
                 notice("unable to open configuration file");
             }
@@ -648,8 +650,8 @@
 ##
 
 builddir=.
-top_srcdir=%PREFIX%
-top_builddir=%PREFIX%
+top_srcdir=%DATADIR%
+top_builddir=%DATADIR%
 include %INSTALLBUILDDIR%/special.mk
 
 #   the used tools
