@@ -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
@@ -1372,10 +1390,11 @@ sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc)
13721390 next if -l $name ; # We do not support symlinks at all
13731391 next if $self -> {NORECURS };
13741392 $dir {$name } = $name if (-f File::Spec-> catfile($name ," Makefile.PL" ));
1375- } elsif ($name =~ / \. xs\z / ){
1376- my ($c ); ($c = $name ) =~ s /\. xs\z / .c/ ;
1377- $xs {$name } = $c ;
1378- $c {$c } = 1;
1393+ } elsif ($name =~ $XS_extRE ){
1394+ my $xs_ext = $1 ;
1395+ (my $src = $name ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1396+ $xs {$name } = $src ;
1397+ $c {$src } = 1;
13791398 } elsif ($name =~ / \. c(pp|xx|c)?\z /i ){ # .c .C .cpp .cxx .cc
13801399 $c {$name } = 1
13811400 unless $name =~ m / perlmain\. c/ ; # See MAP_TARGET
@@ -1620,11 +1639,13 @@ sub init_PM {
16201639 $inst = $self -> libscan($inst );
16211640 print " libscan($path ) => '$inst '\n " if ($Verbose >= 2);
16221641 return unless $inst ;
1623- if ($self -> {XSMULTI } and $inst =~ / \. xs\z / ) {
1624- my ($base ); ($base = $path ) =~ s /\. xs\z // ;
1625- $self -> {XS }{$path } = " $base .c" ;
1626- push @{$self -> {C }}, " $base .c" ;
1627- push @{$self -> {O_FILES }}, " $base$self ->{OBJ_EXT}" ;
1642+ if ($self -> {XSMULTI } and $inst =~ $XS_extRE ) {
1643+ my $xs_ext = $1 ;
1644+ (my $src = $path ) =~ s /\. $xs_ext\z / .$XS_ext2src {$xs_ext }/ ;
1645+ (my $obj = $path ) =~ s /\. $xs_ext\z / $self ->{OBJ_EXT}/ ;
1646+ $self -> {XS }{$path } = $src ;
1647+ push @{$self -> {C }}, $src ;
1648+ push @{$self -> {O_FILES }}, $obj ;
16281649 } else {
16291650 $self -> {PM }{$path } = $inst ;
16301651 }
@@ -3887,28 +3908,18 @@ Defines the suffix rules to compile XS files to C.
38873908
38883909sub xs_c {
38893910 my ($self ) = shift ;
3890- return ' ' unless $self -> needs_linking();
3891- '
3892- .xs.c:
3893- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
3894- $(MV) $*.xsc $*.c
3895- ' ;
3896- }
3897-
3898- =item xs_cpp (o)
3899-
3900- Defines the suffix rules to compile XS files to C++.
3901-
3902- =cut
3911+ return ' ' unless $self -> needs_linking;
3912+ my @m ;
3913+ for my $xs_ext (keys %XS_ext2src ) {
3914+ # 1 2
3915+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext };
39033916
3904- sub xs_cpp {
3905- my ($self ) = shift ;
3906- return ' ' unless $self -> needs_linking();
3907- '
3908- .xs.cpp:
3909- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3910- $(MV) $*.xsc $*.cpp
3911- ' ;
3917+ .%1$s.%2$s:
3918+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.%1$s > $*.xsc
3919+ $(MV) $*.xsc $*.%2$s
3920+ EOF
3921+ }
3922+ join ' ' , @m ;
39123923}
39133924
39143925=item xs_o (o)
@@ -3922,39 +3933,47 @@ have an individual C<$(VERSION)>.
39223933
39233934sub xs_o {
39243935 my ($self ) = @_ ;
3925- return ' ' unless $self -> needs_linking() ;
3936+ return ' ' unless $self -> needs_linking;
39263937 my $minus_o = $self -> xs_obj_opt(' $*$(OBJ_EXT)' );
3927- my $frag = ' ' ;
3938+ my @m ;
39283939 # dmake makes noise about ambiguous rule
3929- $frag .= sprintf <<'EOF' , $minus_o unless $self -> is_make_type(' dmake' );
3930- .xs$(OBJ_EXT) :
3931- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3932- $(MV) $*.xsc $*.c
3933- $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c %s
3940+ my @xs_keys = $self -> is_make_type(' dmake' ) ? () : keys %XS_ext2src ;
3941+ for my $xs_ext (@xs_keys ) {
3942+ # 1 2 3
3943+ push @m , sprintf <<'EOF' , $xs_ext , $XS_ext2src {$xs_ext }, $minus_o ;
3944+
3945+ .%1$s$(OBJ_EXT) :
3946+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.%1$s > $*.xsc
3947+ $(MV) $*.xsc $*.%2$s
3948+ $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.%2$s %3$s
39343949EOF
3950+ }
39353951 if ($self -> {XSMULTI }) {
3936- for my $ext ($self -> _xs_list_basenames) {
3937- my $pmfile = " $ext .pm" ;
3938- croak " $ext .xs has no matching $pmfile : $! " unless -f $pmfile ;
3939- my $version = $self -> parse_version($pmfile );
3940- my $cccmd = $self -> {CONST_CCCMD };
3941- $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3942- $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3943- $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3944- $self -> _xsbuild_replace_macro($cccmd , ' xs' , $ext , ' INC' );
3952+ for my $ext ($self -> _xs_list_basenames) {
3953+ my $pmfile = " $ext .pm" ;
3954+ my $xstype = $self -> _xs_basename2xstype($ext );
3955+ my $xs = " $ext .$xstype " ;
3956+ croak " $xs has no matching $pmfile : $! " unless -f $pmfile ;
3957+ my $version = $self -> parse_version($pmfile );
3958+ my $cccmd = $self -> {CONST_CCCMD };
3959+ $cccmd =~ s / ^\s *CCCMD\s *=\s *// ;
3960+ $cccmd =~ s /\$\( DEFINE_VERSION\) / -DVERSION=\\ "$version \\ "/ ;
3961+ $cccmd =~ s /\$\( XS_DEFINE_VERSION\) / -DXS_VERSION=\\ "$version \\ "/ ;
3962+ my $src = $self -> {XS }{$xs };
3963+ $self -> _xsbuild_replace_macro($cccmd , $xstype , $ext , ' INC' );
39453964 my $define = ' $(DEFINE)' ;
3946- $self -> _xsbuild_replace_macro($define , ' xs ' , $ext , ' DEFINE' );
3947- # 1 2 3 4
3948- $frag .= _sprintf562 <<'EOF' , $ext , $cccmd , $minus_o , $define ;
3949-
3950- %1$s$(OBJ_EXT): %1$s.xs
3951- $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
3952- $(MV) $*.xsc $*.c
3953- %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4 $s $*.c %3 $s
3965+ $self -> _xsbuild_replace_macro($define , $xstype , $ext , ' DEFINE' );
3966+ # 1 2 3 4 5 6
3967+ push @m , _sprintf562 <<'EOF' , $ext , $cccmd , $xs , $src , $minus_o , $define ;
3968+
3969+ %1$s$(OBJ_EXT) : %3$s
3970+ $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) %3$s > $*.xsc
3971+ $(MV) $*.xsc %4$s
3972+ %2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %6 $s %4$s %5 $s
39543973EOF
3955- }
3974+ }
39563975 }
3957- $frag ;
3976+ join ' ' , @m ;
39583977}
39593978
39603979# param gets modified
0 commit comments