dougm       00/04/30 11:36:52

  Modified:    .        Makefile.PL
               lib/Apache Build.pm
               lib/ModPerl Code.pm MM.pm
  Log:
  "discover" xs modules.  since there is no list hardwired
  any module can be unpacked in the mod_perl-2.xx directory
  and built static
  
  this stunt also make it possible to leave .xs files where
  they are, unlike 1.xx where *.xs live in src/modules/perl
  and are copied to subdir/ if DYNAMIC=1
  
  Revision  Changes    Path
  1.19      +21 -4     modperl-2.0/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Makefile.PL,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Makefile.PL       2000/04/30 03:31:16     1.18
  +++ Makefile.PL       2000/04/30 18:36:50     1.19
  @@ -32,6 +32,8 @@
       },
   );
   
  +post_configure();
  +
   sub configure {
       system_sanity_check();
       set_modperl_version();
  @@ -48,14 +50,27 @@
   
       printf "Configuring Apache/%s mod_perl/%s Perl/v%vd\n",
         $httpd_version, $VERSION, $^V;
  -
  -    $code->generate;
   
  -    $build->write_src_makefile;
  +    for (@{ clean_files() }) {
  +        unlink;
  +    }
   
  +    #ModPerl::MM will use Apache::BuildConfig in subdir/Makefile.PL's
       $build->save;
  +}
  +
  +sub post_configure {
  +
  +    #didn't exist until configure()
  +    require Apache::BuildConfig;
  +    #now have any data subdir/Makefile.PL's save, e.g. XS
  +    $build = Apache::BuildConfig->new;
  +
  +    $build->write_src_makefile;
       $build->save_ldopts;
   
  +    $code->generate($build);
  +
       printf "Will build mod_perl %s as %s\n",
         $build->is_dynamic ? "shared" : "static",
           $build->{"MODPERL_LIB"};
  @@ -63,6 +78,8 @@
       if ($build->{MP_INST_APACHE2}) {
           print "Will install Apache Perl modules into Apache2/\n";
       }
  +
  +    $build->save;
   }
   
   sub echo_cmd {
  @@ -190,7 +207,7 @@
       my $self = shift;
       #up one from the Apache2/ subdir
       #so it can be found for 'use Apache2 ()'
  -    $self->{PM}->{'lib/Apache2.pm'} =~ s:^\$\(INST_LIB\):blib/lib:;
  +    $self->{PM}->{'lib/Apache2.pm'} = "blib/lib/Apache2.pm";
       '';
   }
   
  
  
  
  1.16      +93 -26    modperl-2.0/lib/Apache/Build.pm
  
  Index: Build.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/Apache/Build.pm,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Build.pm  2000/04/30 03:31:17     1.15
  +++ Build.pm  2000/04/30 18:36:51     1.16
  @@ -315,6 +315,12 @@
       $self->{$key} ||= ($override || $default_files{$name});
   }
   
  +sub file_path {
  +    my($self, $file) = @_;
  +    return $file if $file =~ m:^/:;
  +    join '/', $self->{cwd}, $file;
  +}
  +
   sub freeze {
       require Data::Dumper;
       local $Data::Dumper::Terse = 1;
  @@ -339,6 +345,8 @@
       my($self, $file) = @_;
   
       $file ||= $self->default_file('build_config');
  +    $file = $self->file_path($file);
  +
       (my $obj = $self->freeze) =~ s/^/    /;
       open my $fh, '>', $file or die "open $file: $!";
   
  @@ -573,9 +581,70 @@
       "$attr = $self->{$attr}\n\n";
   }
   
  +sub xsubpp {
  +    my $self = shift;
  +    my $xsubpp = join ' ', '$(MODPERL_PERLPATH)',
  +      '$(MODPERL_PRIVLIBEXP)/ExtUtils/xsubpp',
  +        '-typemap', '$(MODPERL_PRIVLIBEXP)/ExtUtils/typemap';
  +    $xsubpp;
  +}
  +
  +sub make_xs {
  +    my($self, $fh) = @_;
  +
  +    print $fh $self->canon_make_attr(xsubpp => $self->xsubpp);
  +
  +    return [] unless $self->{XS};
  +
  +    my @files;
  +    my @xs_targ;
  +
  +    while (my($name, $xs) = each %{ $self->{XS} }) {
  +        #Foo/Bar.xs => Bar.c
  +        (my $c = $xs) =~ s:.*/(\w+)\.xs$:$1.c:;
  +        push @files, $c;
  +
  +        $xs = "../../../$xs"; #XXX
  +
  +        push @xs_targ, <<EOF;
  +$c: $xs
  +\t\$(MODPERL_XSUBPP) $xs > \$*.xsc && \$(MODPERL_MV) \$*.xsc \$@
  +
  +EOF
  +    }
  +
  +    my %o = (xs_o_files => 'o', xs_o_pic_files => 'lo');
  +
  +    for my $ext (qw(xs_o_files xs_o_pic_files)) {
  +        print $fh $self->canon_make_attr($ext, map {
  +            (my $file = $_) =~ s/c$/$o{$ext}/; $file;
  +        } @files);
  +    }
  +
  +    print $fh $self->canon_make_attr(xs_clean_files => @files);
  +
  +    \@xs_targ;
  +}
  +
   my @perl_config_pm =
  -  qw(cc ld ar rm ranlib lib_ext dlext cccdlflags lddlflags optimize);
  +  qw(cc ld ar rm ranlib lib_ext dlext cccdlflags lddlflags optimize
  +     perlpath privlibexp);
  +
  +sub make_tools {
  +    my($self, $fh) = @_;
   
  +    #XXX win32
  +
  +    for (@perl_config_pm) {
  +        print $fh $self->canon_make_attr($_, $self->perl_config($_));
  +    }
  +
  +    print $fh $self->canon_make_attr('RM_F' => #XXX
  +                                     $self->{MODPERL_RM} . ' -f');
  +
  +    print $fh $self->canon_make_attr(MV => 'mv');
  +}
  +
   sub write_src_makefile {
       my $self = shift;
       my $code = ModPerl::Code->new;
  @@ -585,12 +654,7 @@
   
       open my $fh, '>', $mf or die "open $mf: $!";
   
  -    for (@perl_config_pm) {
  -        print $fh $self->canon_make_attr($_, $self->perl_config($_));
  -    }
  -
  -    print $fh $self->canon_make_attr('RM_F' => #XXX
  -                                     $self->{MODPERL_RM} . ' -f');
  +    $self->make_tools($fh);
   
       print $fh $self->canon_make_attr('libname', $self->{MP_LIBNAME});
   
  @@ -600,11 +664,8 @@
       print $fh $self->canon_make_attr('lib_static',
                          "$self->{MP_LIBNAME}$self->{MODPERL_LIB_EXT}");
   
  -    print $fh $self->canon_make_attr('xsubpp',
  -                                     join '/', 
  -                                     $self->perl_config('privlibexp'),
  -                                    'xsubpp');
   
  +
       print $fh $self->canon_make_attr('libperl',
                                        join '/',
                                        $self->perl_config('archlibexp'),
  @@ -623,25 +684,30 @@
                                        $self->{MODPERL_LIB_SHARED} :
                                        $self->{MODPERL_LIB_STATIC});
   
  +    my $xs_targ = $self->make_xs($fh);
  +
       print $fh <<'EOF';
  +MODPERL_CCFLAGS = $(MODPERL_INC) $(MODPERL_CCOPTS) $(MODPERL_OPTIMIZE)
   
  -all: lib
  +MODPERL_CCFLAGS_SHLIB = $(MODPERL_CCFLAGS) $(MODPERL_CCCDLFLAGS)
   
  -lib: $(MODPERL_LIB)
  +MODPERL_OBJS = $(MODPERL_O_FILES) $(MODPERL_XS_O_FILES)
   
  -MODPERL_CCFLAGS = $(MODPERL_INC) $(MODPERL_CCOPTS) $(MODPERL_OPTIMIZE)
  +MODPERL_PIC_OBJS = $(MODPERL_O_PIC_FILES) $(MODPERL_XS_O_PIC_FILES)
   
  -MODPERL_CCFLAGS_SHLIB = $(MODPERL_CCFLAGS) $(MODPERL_CCCDLFLAGS)
  +all: lib
  +
  +lib: $(MODPERL_LIB)
   
  -$(MODPERL_LIBNAME)$(MODPERL_LIB_EXT): $(MODPERL_O_FILES)
  +$(MODPERL_LIBNAME)$(MODPERL_LIB_EXT): $(MODPERL_OBJS)
        $(MODPERL_RM_F) $@
  -     $(MODPERL_AR) crv $@ $(MODPERL_O_FILES)
  +     $(MODPERL_AR) crv $@ $(MODPERL_OBJS)
        $(MODPERL_RANLIB) $@
   
  -$(MODPERL_LIBNAME).$(MODPERL_DLEXT): $(MODPERL_O_PIC_FILES)
  +$(MODPERL_LIBNAME).$(MODPERL_DLEXT): $(MODPERL_PIC_OBJS)
        $(MODPERL_RM_F) $@
        $(MODPERL_LD) $(MODPERL_LDDLFLAGS) -o $@ \
  -     $(MODPERL_O_PIC_FILES) $(MODPERL_LDOPTS)
  +     $(MODPERL_PIC_OBJS) $(MODPERL_LDOPTS)
        $(MODPERL_RANLIB) $@
   
   .SUFFIXES: .xs .c .o .lo
  @@ -665,16 +731,17 @@
        $(MODPERL_CC) $(MP_CCFLAGS_SHLIB) -c $*.c && mv $*.o $*.lo
   
   clean:
  -     $(MODPERL_RM_F) *.a *.so
  -     $(MODPERL_RM_F) $(MODPERL_O_FILES)
  -     $(MODPERL_RM_F) $(MODPERL_O_FILES)
  -     $(MODPERL_RM_F) $(MODPERL_O_PIC_FILES)
  -     $(MODPERL_RM_F) $(MODPERL_CLEAN_FILES)
  +     $(MODPERL_RM_F) *.a *.so *.xsc *.o *.lo \
  +     $(MODPERL_CLEAN_FILES) \
  +     $(MODPERL_XS_CLEAN_FILES)
   
  -$(MODPERL_O_FILES): $(MODPERL_H_FILES) Makefile
  -$(MODPERL_O_PIC_FILES): $(MODPERL_H_FILES) Makefile
  +$(MODPERL_OBJS): $(MODPERL_H_FILES) Makefile
  +$(MODPERL_PIC_OBJS): $(MODPERL_H_FILES) Makefile
   $(MODPERL_LIB): $(MODPERL_LIBPERL)
  +
   EOF
  +
  +    print $fh @$xs_targ;
   
       close $fh;
   }
  
  
  
  1.24      +4 -2      modperl-2.0/lib/ModPerl/Code.pm
  
  Index: Code.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/ModPerl/Code.pm,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Code.pm   2000/04/30 03:31:17     1.23
  +++ Code.pm   2000/04/30 18:36:51     1.24
  @@ -448,7 +448,7 @@
   }
   
   sub generate {
  -    my $self = shift;
  +    my($self, $build) = @_;
   
       for my $s (values %sources) {
           for (qw(h c)) {
  @@ -474,7 +474,9 @@
       my $xsinit = "$self->{path}/modperl_xsinit.c";
       warn "generating...$xsinit\n";
   
  -    ExtUtils::Embed::xsinit($xsinit);
  +    #create bootstrap method for static xs modules
  +    my $static_xs = [keys %{ $build->{XS} }];
  +    ExtUtils::Embed::xsinit($xsinit, 1, $static_xs);
   
       warn "generating...", $self->generate_apache2_pm, "\n";
   }
  
  
  
  1.2       +38 -9     modperl-2.0/lib/ModPerl/MM.pm
  
  Index: MM.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/ModPerl/MM.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MM.pm     2000/04/30 03:28:36     1.1
  +++ MM.pm     2000/04/30 18:36:52     1.2
  @@ -16,14 +16,19 @@
       $$string =~ s/($targ\s+::)/$1 $add /;
   }
   
  +sub build_config {
  +    my $key = shift;
  +    require Apache::BuildConfig;
  +    my $build = Apache::BuildConfig->new;
  +    return $build unless $key;
  +    $build->{$key};
  +}
  +
   #strip the Apache2/ subdir so things are install where they should be
   sub install {
       my $hash = shift;
   
  -    require Apache::BuildConfig;
  -    my $build = Apache::BuildConfig->new;
  -
  -    if ($build->{MP_INST_APACHE2}) {
  +    if (build_config('MP_INST_APACHE2')) {
           while (my($k,$v) = each %$hash) {
               delete $hash->{$k};
               $k =~ s:/Apache2$::;
  @@ -51,13 +56,12 @@
       ExtUtils::MakeMaker::WriteMakefile(@_);
   }
   
  -package ModPerl::MM::MY;
  +my %always_dynamic = map { $_, 1 } qw(Apache::Leak);
   
  -sub constants {
  +sub ModPerl::MM::MY::constants {
       my $self = shift;
   
  -    require Apache::BuildConfig;
  -    my $build = Apache::BuildConfig->new;
  +    my $build = build_config();
   
       #install everything relative to the Apache2/ subdir
       if ($build->{MP_INST_APACHE2}) {
  @@ -65,14 +69,39 @@
           $self->{INST_LIB} .= '/Apache2';
       }
   
  +    #"discover" xs modules.  since there is no list hardwired
  +    #any module can be unpacked in the mod_perl-2.xx directory
  +    #and built static
  +
  +    #this stunt also make it possible to leave .xs files where
  +    #they are, unlike 1.xx where *.xs live in src/modules/perl
  +    #and are copied to subdir/ if DYNAMIC=1
  +
  +    unless ($build->{MP_DYNAMIC}) {
  +        #skip .xs -> .so if we are linking static
  +        my $name = $self->{NAME};
  +        unless ($always_dynamic{$name}) {
  +            if (my($xs) = keys %{ $self->{XS} }) {
  +                $self->{HAS_LINK_CODE} = 0;
  +                print "$name will be linked static\n";
  +                #propagate static xs module to src/modules/perl/Makefile
  +                $build->{XS}->{$name} = join '/',
  +                  $self->{BASEEXT}, $xs;
  +                $build->save;
  +            }
  +        }
  +    }
  +
       $self->MM::constants;
   }
   
  -sub libscan {
  +sub ModPerl::MM::MY::libscan {
       my($self, $path) = @_;
  +
       return '' if $path =~ m/\.(pl|cvsignore)$/;
       return '' if $path =~ m:\bCVS/:;
       return '' if $path =~ m/~$/;
  +
       $path;
   }
   
  
  
  

Reply via email to