#! /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@
diff -urNad trunk~/support/apxs.in trunk/support/apxs.in
--- trunk~/support/apxs.in	2010-07-16 20:24:58.337788441 +0200
+++ trunk/support/apxs.in	2010-07-16 20:25:13.333807240 +0200
@@ -190,7 +190,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");
 
@@ -293,6 +293,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);
 
@@ -481,7 +482,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
@@ -517,7 +518,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"));
@@ -528,17 +530,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);
         }
@@ -614,15 +616,15 @@
                 $content =~ s|^(.*\n)#?\s*$lmd[^\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");
             }
@@ -646,8 +648,8 @@
 ##
 
 builddir=.
-top_srcdir=%PREFIX%
-top_builddir=%PREFIX%
+top_srcdir=%DATADIR%
+top_builddir=%DATADIR%
 include %INSTALLBUILDDIR%/special.mk
 
 #   the used tools
