@@ -9,6 +9,24 @@ use ExtUtils::MakeMaker::Config;
99use File::Basename qw( basename dirname) ;
1010
1111our %Config_Override ;
12+ our %XS_ext2src = qw(
13+ xs c
14+ ) ;
15+ my $xspat = join ' |' , keys %XS_ext2src ;
16+ our $XS_extRE = qr /\. ($xspat )\z / ;
17+
18+ sub _xs_list_basenames {
19+ my ($self ) = @_ ;
20+ map { (my $b = $_ ) =~ s / $XS_extRE// ; $b } sort keys %{ $self -> {XS } };
21+ }
22+
23+ sub _xs_basename2xstype {
24+ my ($self , $ext ) = @_ ;
25+ for my $xs_ext (keys %XS_ext2src ) {
26+ return $xs_ext if exists $self -> {XS }{" $ext .$xs_ext " };
27+ }
28+ Carp::confess " PANIC: shouldn't get here" ;
29+ }
1230
1331use ExtUtils::MakeMaker qw( $Verbose neatvalue _sprintf562) ;
1432
@@ -1383,10 +1401,11 @@ sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc)
13831401 next if -l $name ; # We do not support symlinks at all
13841402 next if $self -> {NORECURS };
13851403 $dir {$name } = $name if (-f $self -> catfile($name ," Makefile.PL" ));
1386- } elsif ($name =~ / \. xs\z / ){
1387- my ($c ); ($c = $name ) =~ s /\. xs\z / .c/ ;
1388- $xs {$name } = $c ;
1389- $c {$c } = 1;
1404+ } elsif ($name =~ $XS_extRE ){
1405+ my $xs_ext = $1 ;
1406+ (my $src = $name ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1407+ $xs {$name } = $src ;
1408+ $c {$src } = 1;
13901409 } elsif ($name =~ / \. c(pp|xx|c)?\z /i ){ # .c .C .cpp .cxx .cc
13911410 $c {$name } = 1
13921411 unless $name =~ m / perlmain\. c/ ; # See MAP_TARGET
@@ -1631,11 +1650,13 @@ sub init_PM {
16311650 $inst = $self -> libscan($inst );
16321651 print " libscan($path ) => '$inst '\n " if ($Verbose >= 2);
16331652 return unless $inst ;
1634- if ($self -> {XSMULTI } and $inst =~ / \. xs\z / ) {
1635- my ($base ); ($base = $path ) =~ s /\. xs\z // ;
1636- $self -> {XS }{$path } = " $base .c" ;
1637- push @{$self -> {C }}, " $base .c" ;
1638- push @{$self -> {O_FILES }}, " $base$self ->{OBJ_EXT}" ;
1653+ if ($self -> {XSMULTI } and $inst =~ $XS_extRE ) {
1654+ my $xs_ext = $1 ;
1655+ (my $src = $path ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1656+ (my $obj = $path ) =~ s /\. $xs_ext\z / $self ->{OBJ_EXT}/ ;
1657+ $self -> {XS }{$path } = $src ;
1658+ push @{$self -> {C }}, $src ;
1659+ push @{$self -> {O_FILES }}, $obj ;
16391660 } else {
16401661 $self -> {PM }{$path } = $inst ;
16411662 }
@@ -3883,28 +3904,18 @@ Defines the suffix rules to compile XS files to C.
38833904
38843905sub xs_c {
38853906 my ($self ) = shift ;
3886- return ' ' unless $self -> needs_linking();
3887- '
3888- .xs.c:
3889- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
3890- $(MV) $*.xsc $*.c
3891- ' ;
3892- }
3893-
3894- =item xs_cpp (o)
3895-
3896- Defines the suffix rules to compile XS files to C++.
3897-
3898- =cut
3907+ return ' ' unless $self -> needs_linking;
3908+ my @m ;
3909+ for my $xs_ext (keys %XS_ext2src ) {
3910+ # 1 2
3911+ push @m , _sprintf562 <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext };
38993912
3900- sub xs_cpp {
3901- my ($self ) = shift ;
3902- return ' ' unless $self -> needs_linking();
3903- '
3904- .xs.cpp:
3905- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3906- $(MV) $*.xsc $*.cpp
3907- ' ;
3913+ .%1$s.%2$s:
3914+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.%1$s > $*.xsc
3915+ $(MV) $*.xsc $*.%2$s
3916+ EOF
3917+ }
3918+ join ' ' , @m ;
39083919}
39093920
39103921=item xs_o (o)
@@ -3918,39 +3929,47 @@ have an individual C<$(VERSION)>.
39183929
39193930sub xs_o {
39203931 my ($self ) = @_ ;
3921- return ' ' unless $self -> needs_linking() ;
3932+ return ' ' unless $self -> needs_linking;
39223933 my $m_o = $self -> {XSMULTI } ? $self -> xs_obj_opt(' $*$(OBJ_EXT)' ) : ' ' ;
3923- my $frag = ' ' ;
3934+ my @m ;
39243935 # dmake makes noise about ambiguous rule
3925- $frag .= sprintf <<'EOF' , $m_o unless $self -> is_make_type(' dmake' );
3926- .xs$(OBJ_EXT) :
3927- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3928- $(MV) $*.xsc $*.c
3929- $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c %s
3936+ my @xs_keys = $self -> is_make_type(' dmake' ) ? () : keys %XS_ext2src ;
3937+ for my $xs_ext (@xs_keys ) {
3938+ # 1 2 3
3939+ push @m , _sprintf562 <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext }, $m_o ;
3940+
3941+ .%1$s$(OBJ_EXT) :
3942+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.%1$s > $*.xsc
3943+ $(MV) $*.xsc $*.%2$s
3944+ $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.%2$s %3$s
39303945EOF
3946+ }
39313947 if ($self -> {XSMULTI }) {
3932- for my $ext ($self -> _xs_list_basenames) {
3933- my $pmfile = " $ext .pm" ;
3934- croak " $ext .xs has no matching $pmfile : $! " unless -f $pmfile ;
3935- my $version = $self -> parse_version($pmfile );
3936- my $cccmd = $self -> {CONST_CCCMD };
3937- $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3938- $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3939- $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3940- $self -> _xsbuild_replace_macro($cccmd , ' xs' , $ext , ' INC' );
3948+ for my $ext ($self -> _xs_list_basenames) {
3949+ my $pmfile = " $ext .pm" ;
3950+ my $xstype = $self -> _xs_basename2xstype($ext );
3951+ my $xs = " $ext .$xstype " ;
3952+ croak " $xs has no matching $pmfile : $! " unless -f $pmfile ;
3953+ my $version = $self -> parse_version($pmfile );
3954+ my $cccmd = $self -> {CONST_CCCMD };
3955+ $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3956+ $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3957+ $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3958+ my $src = $self -> {XS }{$xs };
3959+ $self -> _xsbuild_replace_macro($cccmd , $xstype , $ext , ' INC' );
39413960 my $define = ' $(DEFINE)' ;
3942- $self -> _xsbuild_replace_macro($define , ' xs ' , $ext , ' DEFINE' );
3943- # 1 2 3 4
3944- $frag .= _sprintf562 <<'EOF' , $ext , $cccmd , $m_o , $define ;
3945-
3946- %1$s$(OBJ_EXT): %1$s.xs
3947- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3948- $(MV) $*.xsc $*.c
3949- %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4 $s $*.c %3 $s
3961+ $self -> _xsbuild_replace_macro($define , $xstype , $ext , ' DEFINE' );
3962+ # 1 2 3 4 5 6
3963+ push @m , _sprintf562 <<'EOF' , $ext , $cccmd , $xs , $src , $m_o , $define ;
3964+
3965+ %1$s$(OBJ_EXT) : %3$s
3966+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) %3$s > $*.xsc
3967+ $(MV) $*.xsc %4$s
3968+ %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %6 $s %4$s %5 $s
39503969EOF
3951- }
3970+ }
39523971 }
3953- $frag ;
3972+ join ' ' , @m ;
39543973}
39553974
39563975# param gets modified
0 commit comments