On Thu, 1 Feb 2001, Ken Williams wrote:

> I kind of feel like we should blindly use $ENV{APACHE} if it's there,
> because I just made up the variable for this purpose, and if the user
> sets it, we shouldn't argue.  It would be mysterious if you set APACHE
> to something, and then Makefile.PL defaults to use something else
> without telling you why.

Ok, now it does respect this, but only the first time through.  If you
stick with your choice and it turns out to not have mod_perl it'll poke
through the filesystem a bit to try to find something.  Seems like the
best of all worlds to me.

> What *would* be nice, though, is to check the user-typed response for
> the presence of mod_perl, and give an appropriate error message if it's
> missing.

Added this.

>   sub _has_mod_perl {
>       my ($self, $httpd) = @_;
>
>       return 1 if `$httpd -l` =~ /mod_perl\.c/;

Added this too


--- /usr/src/misc/mod_perl-1.25/lib/Apache/test.pm      Fri Dec 22 00:17:51 2000
+++ ./test.pm   Thu Feb  1 00:47:54 2001
@@ -108,27 +108,32 @@

     my %conf;

-    my $httpd = $ENV{'APACHE'} || which('apache') || which('httpd') || 
'/usr/lib/httpd/httpd';
+    my $httpd = $pkg->_find_mod_perl_httpd(1);

-    $httpd = _ask("\n", $httpd, 1, '!');
-    if ($httpd eq '!') {
-       print "Skipping.\n";
-       return;
-    }
+    my $found;
+    do
+    {
+       $httpd = _ask("\n", $httpd, 1, '!');
+       if ($httpd eq '!') {
+           print "Skipping.\n";
+           return;
+       }
+
+       if ($pkg->_httpd_has_mod_perl($httpd)) {
+           $found = 1;
+       } else {
+           warn("$httpd does not appear to have been compiled with\n",
+                "mod_perl as a static or dynamic module\n");
+           $httpd = $pkg->_find_mod_perl_httpd(0);
+       }
+    } until ($found);
     system "$Config{lns} $httpd t/httpd";

     # Default: search for dynamic dependencies if mod_so is present, don't bother 
otherwise.
     my $default = (`t/httpd -l` =~ /mod_so\.c/ ? 'y' : 'n');
     if (lc _ask("Search existing config file for dynamic module dependencies?", 
$default) eq 'y') {
-       my %compiled;
-       for (`t/httpd -V`) {
-           if (/([\w]+)="(.*)"/) {
-               $compiled{$1} = $2;
-           }
-       }
-       $compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
-           unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
-
+       my %compiled = $pkg->_get_compilation_params('t/httpd');
+
        my $file = _ask("  Config file", $compiled{SERVER_CONFIG_FILE}, 1);
        $conf{modules} = $pkg->_read_existing_conf($file);
     }
@@ -145,6 +150,21 @@
     return %conf;
 }

+sub _get_compilation_params {
+    my ($self, $httpd) = @_;
+
+    my %compiled;
+    for (`$httpd -V`) {
+       if (/([\w]+)="(.*)"/) {
+           $compiled{$1} = $2;
+       }
+    }
+    $compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
+       unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
+
+    return %compiled;
+}
+
 sub _read_existing_conf {
     # Returns some "(Add|Load)Module" config lines, generated from the
     # existing config file and a few must-have modules.
@@ -176,7 +196,7 @@
     }

     # Directories where apache DSOs live.
-    my @module_dirs = map {m,(/\S*/),} @modules;
+    my @module_dirs = map {m,(/\S*)/,} @modules;

     # Finally compute the directives to load modules that need to be loaded.
  MODULE:
@@ -204,12 +224,42 @@
     return {map {lc($_) => 1} map /(\S+)\.c/, @l};
 }

-# Find an executable in the PATH.
-sub which {
-    foreach (map { "$_/$_[0]" } split /:/, $ENV{PATH}) {
-       next unless m,^/,;
-       return $_ if -x;
+sub _find_mod_perl_httpd {
+    my ($self, $respect_env) = @_;
+
+    return $ENV{'APACHE'} if $ENV{'APACHE'} && $respect_env;
+
+    foreach ( '/usr/local/apache/bin/httpd',
+             '/usr/local/apache_mp/bin/httpd',
+             '/opt/apache/bin/httpd',
+             $self->_which('httpd'),
+             $self->_which('apache'),
+           ) {
+       return $_ if -x $_ && $self->_httpd_has_mod_perl($_);
     }
+}
+
+sub _httpd_has_mod_perl {
+    my ($self, $httpd) = @_;
+
+    return 1 if `$httpd -l` =~ /mod_perl\.c/;
+
+    my %compiled = $self->_get_compilation_params($httpd);
+
+    if ($compiled{SERVER_CONFIG_FILE}) {
+       local *SERVER_CONF;
+       open SERVER_CONF, $compiled{SERVER_CONFIG_FILE} or die "Couldn't open 
+$compiled{SERVER_CONFIG_FILE}: $!";
+       my @lines = grep {!m/^\s*\#/} <SERVER_CONF>;
+       close SERVER_CONF;
+
+       return 1 if grep { /mod_perl/ } grep /^\s*(Add|Load)Module/, @lines;
+    }
+
+    return 0;
+}
+
+sub _which {
+    return grep {-x $_} map { "$_/$_[1]" } split /:/, $ENV{PATH};
 }

 sub test {


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to