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