File Coverage

lib/ExtUtils/Mkbootstrap.pm
Criterion Covered Total %
statement 47 48 97.9
branch 17 20 85.0
condition 5 6 83.3
subroutine 6 6 100.0
pod 0 1 0.0
total 75 81 92.5


line stmt bran cond sub pod time code
1              
2             use strict;
3 2     2   38338 use warnings;
  2         8  
  2         50  
4 2     2   9  
  2         3  
  2         149  
5             our $VERSION = '7.64';
6             $VERSION =~ tr/_//d;
7              
8             require Exporter;
9             our @ISA = ('Exporter');
10             our @EXPORT = ('&Mkbootstrap');
11              
12             use Config;
13 2     2   11  
  2         2  
  2         309  
14             our $Verbose = 0;
15              
16              
17             my($baseext, @bsloadlibs)=@_;
18             @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
19 7     7 0 6716  
20 7         16 print " bsloadlibs=@bsloadlibs\n" if $Verbose;
21              
22 7 100       32 # We need DynaLoader here because we and/or the *_BS file may
23             # call dl_findfile(). We don't say `use' here because when
24             # first building perl extensions the DynaLoader will not have
25             # been built when MakeMaker gets first used.
26             require DynaLoader;
27              
28 7         56 rename "$baseext.bs", "$baseext.bso"
29             if -s "$baseext.bs";
30 7 100       154  
31             if (-f "${baseext}_BS"){
32             $_ = "${baseext}_BS";
33 7 100       79 no strict 'vars';
34 1         4 local($osname, $dlsrc) = (); # avoid warnings
35             ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
36 2     2   12 $bscode = "";
  2         3  
  2         241  
37 1         3 unshift @INC, ".";
38 1         10 require $_;
39 1         3 shift @INC;
40 1         3  
41 1         161 if ($Config{'dlsrc'} =~ /^dl_dld/){
42 1         11 no strict 'vars';
43             push(@dl_resolve_using, dl_findfile('-lc'));
44              
45 7 50       72 my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
46             my($method) = '';
47 2     2   17 if (@all || (defined $DynaLoader::bscode && length $DynaLoader::bscode)){
  2         4  
  2         582  
48 0         0 open my $bs, ">", "$baseext.bs"
49             or die "Unable to open $baseext.bs: $!";
50             print "Writing $baseext.bs\n";
51 7         25 print " containing: @all" if $Verbose;
52 7         13 print $bs "# $baseext DynaLoader bootstrap file for $^O architecture.\n";
53 7 100 66     31 print $bs "# Do not edit this file, changes will be lost.\n";
      100        
54 3 50       145 print $bs "# This file was automatically generated by the\n";
55             print $bs "# Mkbootstrap routine in ExtUtils::Mkbootstrap (v$VERSION).\n";
56 3         19 if (@all) {
57 3 100       25 print $bs "\@DynaLoader::dl_resolve_using = ";
58 3         22 # If @all contains names in the form -lxxx or -Lxxx then it's asking for
59 3         5 # runtime library location so we automatically add a call to dl_findfile()
60 3         24 if (" @all" =~ m/ -[lLR]/){
61 3         7 print $bs " dl_findfile(qw(\n @all\n ));\n";
62 3 50       6 } else {
63 3         6 print $bs " qw(@all);\n";
64             }
65             }
66 3 100       12 # write extra code if *_BS says so
67 1         4 print $bs $DynaLoader::bscode if $DynaLoader::bscode;
68             print $bs "\n1;\n";
69 2         5 close $bs;
70             }
71             }
72              
73 3 100       7 1;
74 3         4  
75 3         227  
76             =head1 NAME
77              
78             ExtUtils::Mkbootstrap - make a bootstrap file for use by DynaLoader
79              
80             =head1 SYNOPSIS
81              
82             Mkbootstrap
83              
84             =head1 DESCRIPTION
85              
86             Mkbootstrap typically gets called from an extension Makefile.
87              
88             There is no C<*.bs> file supplied with the extension. Instead, there may
89             be a C<*_BS> file which has code for the special cases, like posix for
90             berkeley db on the NeXT.
91              
92             This file will get parsed, and produce a maybe empty
93             C<@DynaLoader::dl_resolve_using> array for the current architecture.
94             That will be extended by $BSLOADLIBS, which was computed by
95             ExtUtils::Liblist::ext(). If this array still is empty, we do nothing,
96             else we write a .bs file with an C<@DynaLoader::dl_resolve_using>
97             array.
98              
99             The C<*_BS> file can put some code into the generated C<*.bs> file by
100             placing it in C<$bscode>. This is a handy 'escape' mechanism that may
101             prove useful in complex situations.
102              
103             If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
104             Mkbootstrap will automatically add a dl_findfile() call to the
105             generated C<*.bs> file.
106              
107             =cut