@@ -10,6 +10,24 @@ use File::Basename qw(basename dirname);
1010use DirHandle;
1111
1212our %Config_Override ;
13+ our %XS_ext2src = qw(
14+ xs c
15+ ) ;
16+ my $xspat = join ' |' , keys %XS_ext2src ;
17+ our $XS_extRE = qr /\. ($xspat )\z / ;
18+
19+ sub _xs_list_basenames {
20+ my ($self ) = @_ ;
21+ map { (my $b = $_ ) =~ s / $XS_extRE// ; $b } sort keys %{ $self -> {XS } };
22+ }
23+
24+ sub _xs_basename2xs {
25+ my ($self , $ext ) = @_ ;
26+ for my $xs_ext (keys %XS_ext2src ) {
27+ return " $ext .$xs_ext " if exists $self -> {XS }{" $ext .$xs_ext " };
28+ }
29+ Carp::confess " PANIC: shouldn't get here" ;
30+ }
1331
1432use ExtUtils::MakeMaker qw( $Verbose neatvalue) ;
1533
@@ -1373,10 +1391,11 @@ sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc)
13731391 next if -l $name ; # We do not support symlinks at all
13741392 next if $self -> {NORECURS };
13751393 $dir {$name } = $name if (-f File::Spec-> catfile($name ," Makefile.PL" ));
1376- } elsif ($name =~ / \. xs\z / ){
1377- my ($c ); ($c = $name ) =~ s /\. xs\z / .c/ ;
1378- $xs {$name } = $c ;
1379- $c {$c } = 1;
1394+ } elsif ($name =~ $XS_extRE ){
1395+ my $xs_ext = $1 ;
1396+ my ($src ); ($src = $name ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1397+ $xs {$name } = $src ;
1398+ $c {$src } = 1;
13801399 } elsif ($name =~ / \. c(pp|xx|c)?\z /i ){ # .c .C .cpp .cxx .cc
13811400 $c {$name } = 1
13821401 unless $name =~ m / perlmain\. c/ ; # See MAP_TARGET
@@ -1621,11 +1640,13 @@ sub init_PM {
16211640 $inst = $self -> libscan($inst );
16221641 print " libscan($path ) => '$inst '\n " if ($Verbose >= 2);
16231642 return unless $inst ;
1624- if ($self -> {XSMULTI } and $inst =~ / \. xs\z / ) {
1625- my ($base ); ($base = $path ) =~ s /\. xs\z // ;
1626- $self -> {XS }{$path } = " $base .c" ;
1627- push @{$self -> {C }}, " $base .c" ;
1628- push @{$self -> {O_FILES }}, " $base$self ->{OBJ_EXT}" ;
1643+ if ($self -> {XSMULTI } and $inst =~ $XS_extRE ) {
1644+ my $xs_ext = $1 ;
1645+ my ($src ); ($src = $path ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1646+ my ($obj ); ($obj = $path ) =~ s /\. $xs_ext\z / $self ->{OBJ_EXT}/ ;
1647+ $self -> {XS }{$path } = $src ;
1648+ push @{$self -> {C }}, $src ;
1649+ push @{$self -> {O_FILES }}, $obj ;
16291650 } else {
16301651 $self -> {PM }{$path } = $inst ;
16311652 }
@@ -3867,28 +3888,18 @@ Defines the suffix rules to compile XS files to C.
38673888
38683889sub xs_c {
38693890 my ($self ) = shift ;
3870- return ' ' unless $self -> needs_linking();
3871- '
3872- .xs.c:
3873- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
3874- $(MV) $*.xsc $*.c
3875- ' ;
3876- }
3877-
3878- =item xs_cpp (o)
3879-
3880- Defines the suffix rules to compile XS files to C++.
3881-
3882- =cut
3891+ return ' ' unless $self -> needs_linking;
3892+ my @m ;
3893+ for my $xs_ext (keys %XS_ext2src ) {
3894+ # 1 2
3895+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext };
38833896
3884- sub xs_cpp {
3885- my ($self ) = shift ;
3886- return ' ' unless $self -> needs_linking();
3887- '
3888- .xs.cpp:
3889- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3890- $(MV) $*.xsc $*.cpp
3891- ' ;
3897+ .%1$s.%2$s:
3898+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.%1$s > $*.xsc
3899+ $(MV) $*.xsc $*.%2$s
3900+ EOF
3901+ }
3902+ join ' ' , @m ;
38923903}
38933904
38943905=item xs_o (o)
@@ -3902,14 +3913,19 @@ have an individual C<$(VERSION)>.
39023913
39033914sub xs_o {
39043915 my ($self ) = @_ ;
3905- return ' ' unless $self -> needs_linking() ;
3916+ return ' ' unless $self -> needs_linking;
39063917 my $minus_o = $self -> xs_obj_opt(' $*$(OBJ_EXT)' );
3907- my $frag = sprintf <<'EOF' , $minus_o ;
3908- .xs$(OBJ_EXT) :
3909- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3910- $(MV) $*.xsc $*.c
3911- $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c %s
3918+ my @m ;
3919+ for my $xs_ext (keys %XS_ext2src ) {
3920+ # 1 2 3
3921+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext }, $minus_o ;
3922+
3923+ .%1$s$(OBJ_EXT) :
3924+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.%1$s > $*.xsc
3925+ $(MV) $*.xsc $*.%2$s
3926+ $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.%2$s %3$s
39123927EOF
3928+ }
39133929 if ($self -> {XSMULTI }) {
39143930 for my $ext ($self -> _xs_list_basenames) {
39153931 my $pmfile = " $ext .pm" ;
@@ -3919,17 +3935,19 @@ EOF
39193935 $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
39203936 $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
39213937 $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3922- # 1 2 3
3923- $frag .= sprintf <<'EOF' , $ext , $cccmd , $minus_o ;
3924-
3925- %1$s$(OBJ_EXT): %1$s.xs
3926- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3927- $(MV) $*.xsc $*.c
3928- %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c %3$s
3938+ my $xs = $self -> _xs_basename2xs($ext );
3939+ my $src = $self -> {XS }{$xs };
3940+ # 1 2 3 4 5
3941+ push @m , sprintf <<'EOF' , $ext , $cccmd , $xs , $src , $minus_o ;
3942+
3943+ %1$s$(OBJ_EXT) : %3$s
3944+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) %3$s > $*.xsc
3945+ $(MV) $*.xsc %4$s
3946+ %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) %4$s %5$s
39293947EOF
39303948 }
39313949 }
3932- $frag ;
3950+ join ' ' , @m ;
39333951}
39343952
39353953
0 commit comments