It's been a long awaited feature, to bring back something similar to the old
mod_perl option to have mod_perl statically linked to httpd. Here is my attempt
at it.

The original way I attempted this was to hook into the new httpd build system,
but, one issue about that is that it would require autoconf/automake/aclocal.

So, instead, this patch tries to make things work by poking at httpd ever so
slightly.

In a nutshell :

$> cd ~
$> tar zxvf httpd-2.0.x.tar.gz
$> cd ~/httpd-2.0.x && ./configure [...]
$> cd ~/mod_perl
$mod_perl> perl Makefile.PL MP_USE_STATIC=1 MP_AP_PREFIX=~/httpd-2.0.x
generating...src/modules/perl/modperl_xsinit.c
mod_perl static library will be built as mod_perl.a
Patching : ~/httpd-2.0.x/build/config_vars.mk
Patching : ~/httpd-2.0.x/modules.c
$mod_perl> make
$mod_perl> cd ~/httpd-2.0.x
$httpd-2.0.x> make
$httpd-2.0.x> ./httpd -l
Compiled in modules:
  core.c
  [...]
  mod_perl.c
$httpd-2.0.x> cd ~/mod_perl
$mod_perl> ./t/TEST -httpd ~/httpd-2.0.x/httpd
$mod_perl> make install
$mod_perl> cd ~/httpd.2.0.x && make install


Statically linking mod_perl should help people on platforms with defective dso
support, for instance.

There is currently one bug with mod_perl compiled statically. It tries to add
the MODPERL2 server define at hook-registry phase, but for statically linked
modules, that hook-registry phase is called before ap_server_config_defines is
created.

The following httpd patch fixes it, and I think it should be submitted to
[EMAIL PROTECTED] for inclusion, as what mod_perl is doing is the only way I could find
of adding defines, and it just doesn't work when statically linked. The
pre-config hook doesn't work, because it's being run a bit too late for this:

Index: server/main.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/main.c,v
retrieving revision 1.140.2.8
diff -u -I$Id -r1.140.2.8 main.c
--- server/main.c       30 Mar 2004 20:53:06 -0000      1.140.2.8
+++ server/main.c       27 Apr 2004 22:33:20 -0000
@@ -393,14 +393,13 @@
     }
 #endif

-    ap_setup_prelinked_modules(process);
-
     apr_pool_create(&pcommands, pglobal);
     apr_pool_tag(pcommands, "pcommands");
     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
     ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));

+    ap_setup_prelinked_modules(process);
     ap_run_rewrite_args(process);

     /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM


And now, the actual static build patch follows; I am aware that it's not
verydefensive and possibly doesn't work on some platforms (win32 anyone?), but I
think it's a step in the good direction. Comments welcome.

Index: Makefile.PL
===================================================================
RCS file: /home/cvs/modperl-2.0/Makefile.PL,v
retrieving revision 1.137
diff -u -I$Id -r1.137 Makefile.PL
--- Makefile.PL 4 Mar 2004 03:36:18 -0000       1.137
+++ Makefile.PL 27 Apr 2004 22:47:37 -0000
@@ -261,6 +261,11 @@
         warning "You'll need to add the following to httpd.conf:",
                 " LoadModule perl_module modules/$build->{MODPERL_LIB_DSO}\n";
     }
+
+    #XXX: Not sure this is the best place
+    if ($build->is_static) {
+        $build->patch_httpd_for_static;
+    }

     if ($build->{MP_INST_APACHE2}) {
         warning "Apache Perl modules will be installed relative to Apache2/";
Index: lib/Apache/Build.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/Build.pm,v
retrieving revision 1.162
diff -u -I$Id -r1.162 Build.pm
--- lib/Apache/Build.pm 27 Apr 2004 17:26:28 -0000      1.162
+++ lib/Apache/Build.pm 27 Apr 2004 22:47:37 -0000
@@ -87,6 +87,46 @@
     return '';
 }

+sub patch_httpd_for_static {
+    my $self = shift;
+
+    #AP_LIBS+=
+    my $ldopts = $self->ldopts;
+
+    #XXX: figure the name for all platforms
+    my $lib = catfile($self->{cwd}, qw(src modules perl mod_perl.a));
+
+    my $config_vars = catfile($self->dir, qw(build config_vars.mk));
+
+    warning "Patching : $config_vars";
+    {
+    local @ARGV = $config_vars;
+    local $^I = ".bak";
+    while (<>) {
+        s/^AP_LIBS\s*=(.*)/AP_LIBS=$1 $ldopts/;
+        s/^BUILTIN_LIBS\s*=(.*)/BUILTIN_LIBS=$1 $lib/;
+        print;
+        }
+    unlink $config_vars . $^I;
+    }
+
+    my $modules = catfile($self->dir, qw(modules.c));
+
+    warning "Patching : $modules";
+
+    my $fh;
+    open($fh, "<$modules");
+    local $/ = undef;
+    my $modules_data = <$fh>;
+    $modules_data =~
+      s/(extern module core_module;)/$1\nextern module perl_module;/;
+    $modules_data =~ s/(\s*)NULL/$1&perl_module,$1NULL/g;
+    close($fh);
+    open($fh, ">$modules");
+    print $fh $modules_data;
+    close($fh);
+}
+
 sub httpd_is_source_tree {
     my $self = shift;

@@ -796,6 +836,7 @@
 #--- attribute access ---

 sub is_dynamic { shift->{MP_USE_DSO} }
+sub is_static { shift->{MP_USE_STATIC} }

 sub default_dir {
     my $build = shift->build_config;

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to