@@ -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_basename2xstype {
25+ my ($self , $ext ) = @_ ;
26+ for my $xs_ext (keys %XS_ext2src ) {
27+ return $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 _sprintf562) ;
1533
@@ -1371,10 +1389,11 @@ sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc)
13711389 next if -l $name ; # We do not support symlinks at all
13721390 next if $self -> {NORECURS };
13731391 $dir {$name } = $name if (-f File::Spec-> catfile($name ," Makefile.PL" ));
1374- } elsif ($name =~ / \. xs\z / ){
1375- my ($c ); ($c = $name ) =~ s /\. xs\z / .c/ ;
1376- $xs {$name } = $c ;
1377- $c {$c } = 1;
1392+ } elsif ($name =~ $XS_extRE ){
1393+ my $xs_ext = $1 ;
1394+ (my $src = $name ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1395+ $xs {$name } = $src ;
1396+ $c {$src } = 1;
13781397 } elsif ($name =~ / \. c(pp|xx|c)?\z /i ){ # .c .C .cpp .cxx .cc
13791398 $c {$name } = 1
13801399 unless $name =~ m / perlmain\. c/ ; # See MAP_TARGET
@@ -1619,11 +1638,13 @@ sub init_PM {
16191638 $inst = $self -> libscan($inst );
16201639 print " libscan($path ) => '$inst '\n " if ($Verbose >= 2);
16211640 return unless $inst ;
1622- if ($self -> {XSMULTI } and $inst =~ / \. xs\z / ) {
1623- my ($base ); ($base = $path ) =~ s /\. xs\z // ;
1624- $self -> {XS }{$path } = " $base .c" ;
1625- push @{$self -> {C }}, " $base .c" ;
1626- push @{$self -> {O_FILES }}, " $base$self ->{OBJ_EXT}" ;
1641+ if ($self -> {XSMULTI } and $inst =~ $XS_extRE ) {
1642+ my $xs_ext = $1 ;
1643+ (my $src = $path ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1644+ (my $obj = $path ) =~ s /\. $xs_ext\z / $self ->{OBJ_EXT}/ ;
1645+ $self -> {XS }{$path } = $src ;
1646+ push @{$self -> {C }}, $src ;
1647+ push @{$self -> {O_FILES }}, $obj ;
16271648 } else {
16281649 $self -> {PM }{$path } = $inst ;
16291650 }
@@ -3888,28 +3909,18 @@ Defines the suffix rules to compile XS files to C.
38883909
38893910sub xs_c {
38903911 my ($self ) = shift ;
3891- return ' ' unless $self -> needs_linking();
3892- '
3893- .xs.c:
3894- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
3895- $(MV) $*.xsc $*.c
3896- ' ;
3897- }
3898-
3899- =item xs_cpp (o)
3900-
3901- Defines the suffix rules to compile XS files to C++.
3902-
3903- =cut
3912+ return ' ' unless $self -> needs_linking;
3913+ my @m ;
3914+ for my $xs_ext (keys %XS_ext2src ) {
3915+ # 1 2
3916+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext };
39043917
3905- sub xs_cpp {
3906- my ($self ) = shift ;
3907- return ' ' unless $self -> needs_linking();
3908- '
3909- .xs.cpp:
3910- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3911- $(MV) $*.xsc $*.cpp
3912- ' ;
3918+ .%1$s.%2$s:
3919+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.%1$s > $*.xsc
3920+ $(MV) $*.xsc $*.%2$s
3921+ EOF
3922+ }
3923+ join ' ' , @m ;
39133924}
39143925
39153926=item xs_o (o)
@@ -3923,39 +3934,47 @@ have an individual C<$(VERSION)>.
39233934
39243935sub xs_o {
39253936 my ($self ) = @_ ;
3926- return ' ' unless $self -> needs_linking() ;
3937+ return ' ' unless $self -> needs_linking;
39273938 my $minus_o = $self -> xs_obj_opt(' $*$(OBJ_EXT)' );
3928- my $frag = ' ' ;
3939+ my @m ;
39293940 # dmake makes noise about ambiguous rule
3930- $frag .= sprintf <<'EOF' , $minus_o unless $self -> is_make_type(' dmake' );
3931- .xs$(OBJ_EXT) :
3932- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3933- $(MV) $*.xsc $*.c
3934- $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c %s
3941+ my @xs_keys = $self -> is_make_type(' dmake' ) ? () : keys %XS_ext2src ;
3942+ for my $xs_ext (@xs_keys ) {
3943+ # 1 2 3
3944+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext }, $minus_o ;
3945+
3946+ .%1$s$(OBJ_EXT) :
3947+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.%1$s > $*.xsc
3948+ $(MV) $*.xsc $*.%2$s
3949+ $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.%2$s %3$s
39353950EOF
3951+ }
39363952 if ($self -> {XSMULTI }) {
3937- for my $ext ($self -> _xs_list_basenames) {
3938- my $pmfile = " $ext .pm" ;
3939- croak " $ext .xs has no matching $pmfile : $! " unless -f $pmfile ;
3940- my $version = $self -> parse_version($pmfile );
3941- my $cccmd = $self -> {CONST_CCCMD };
3942- $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3943- $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3944- $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3945- $self -> _xsbuild_replace_macro($cccmd , ' xs' , $ext , ' INC' );
3953+ for my $ext ($self -> _xs_list_basenames) {
3954+ my $pmfile = " $ext .pm" ;
3955+ my $xstype = $self -> _xs_basename2xstype($ext );
3956+ my $xs = " $ext .$xstype " ;
3957+ croak " $xs has no matching $pmfile : $! " unless -f $pmfile ;
3958+ my $version = $self -> parse_version($pmfile );
3959+ my $cccmd = $self -> {CONST_CCCMD };
3960+ $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3961+ $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3962+ $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3963+ my $src = $self -> {XS }{$xs };
3964+ $self -> _xsbuild_replace_macro($cccmd , $xstype , $ext , ' INC' );
39463965 my $define = ' $(DEFINE)' ;
3947- $self -> _xsbuild_replace_macro($define , ' xs ' , $ext , ' DEFINE' );
3948- # 1 2 3 4
3949- $frag .= _sprintf562 <<'EOF' , $ext , $cccmd , $minus_o , $define ;
3950-
3951- %1$s$(OBJ_EXT): %1$s.xs
3952- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3953- $(MV) $*.xsc $*.c
3954- %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4 $s $*.c %3 $s
3966+ $self -> _xsbuild_replace_macro($define , $xstype , $ext , ' DEFINE' );
3967+ # 1 2 3 4 5 6
3968+ push @m , _sprintf562 <<'EOF' , $ext , $cccmd , $xs , $src , $minus_o , $define ;
3969+
3970+ %1$s$(OBJ_EXT) : %3$s
3971+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) %3$s > $*.xsc
3972+ $(MV) $*.xsc %4$s
3973+ %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %6 $s %4$s %5 $s
39553974EOF
3956- }
3975+ }
39573976 }
3958- $frag ;
3977+ join ' ' , @m ;
39593978}
39603979
39613980# param gets modified
0 commit comments